madness 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b8bd26b9b5e653feb97ff0a0b5cc2859729cfd5014d7a2fbeaaf3c7a5de7381
4
- data.tar.gz: 13c24f4c4af034814918d9cd7543adb770ab62e13d819eb0d4d006b99629a64a
3
+ metadata.gz: c755fffb873e0721cf789a8f3ea205bdcb03379c1338cb40482899940d6d0f99
4
+ data.tar.gz: f87ec8c17f1b38a69b028ededcf0a140b9ff59724d937fca10b79f19d5953929
5
5
  SHA512:
6
- metadata.gz: e346d93cc0b23989fcfcb66f1d3f65325420fe3999c3a0d37b9afee2d2954e14c51b5e7f77aaa6b990bda3d9cd7b0cb7057ab6b85ae046481aab56e475c2833a
7
- data.tar.gz: ed1e9e6b986c450596d3853d7f45b3ecbd2da2bbca3032155f069434c5ea0542c18df02d90c8333402f76204e9e4f350d2ebf0a95524fe49d56a6f2453da9c44
6
+ metadata.gz: 022c102699a039bd18e4e6209f4ba88afb2fbe6f5e0aeb0ff9d4175f56cb101ff5e1feed4091dd038179b3ca5617d3319c11bf8c4048b28dcbd375d764567e1e
7
+ data.tar.gz: 2be131708f7e75f97bb47064972ef4a9beb957ea96c49873056fb0429dd2c6db4ed0b592b43f1a22e4124d10ff5da1b73b010252939ef8bf29e1b679f1d514dd
@@ -1,8 +1,12 @@
1
1
  module Madness
2
2
  module StringRefinements
3
3
  refine String do
4
+ def remove(regex)
5
+ gsub regex, ''
6
+ end
7
+
4
8
  def to_slug
5
- downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
9
+ downcase.strip.gsub(' ', '-').remove(/[^\w-]/)
6
10
  end
7
11
 
8
12
  # This is here so we can have one place that defines how to convert
@@ -12,7 +16,7 @@ module Madness
12
16
  # just removes any numbers followed by a dot at the beginning of the
13
17
  # string, in order to allow "The Invisible Sorting Hand".
14
18
  def to_label
15
- gsub(/^\d+\.\s+/, '').gsub(/\.md$/, '')
19
+ remove(/^\d+\.\s+/).remove(/\.md$/)
16
20
  end
17
21
  end
18
22
  end
@@ -21,7 +21,8 @@ module Madness
21
21
  index = Index.new path: index_dir, create: true
22
22
 
23
23
  Dir["#{@path}/**/*.md"].each do |file|
24
- index << { file: file, content: searchable_content(file) }
24
+ record = { file: file, content: searchable_content(file) }
25
+ index << record unless skip_index? file
25
26
  end
26
27
 
27
28
  index.optimize()
@@ -40,7 +41,7 @@ module Madness
40
41
 
41
42
  results << {
42
43
  score: score,
43
- file: filename,
44
+ file: file_url(filename),
44
45
  label: file_label(filename),
45
46
  highlights: highlights
46
47
  }
@@ -61,17 +62,37 @@ module Madness
61
62
 
62
63
  private
63
64
 
65
+ # We are going to avoid indexing of README.md when there is also an
66
+ # index.md in the same directory, to keep behavior consistent with the
67
+ # display logic
68
+ def skip_index?(file)
69
+ if file.end_with? 'README.md'
70
+ dir = File.dirname file
71
+ File.exist? "#{dir}/index.md"
72
+ else
73
+ false
74
+ end
75
+ end
76
+
64
77
  # This is poor-mans markdown strip.
65
78
  # Convert to HTML, strip tags and return plain text suitable to act as
66
79
  # the content for the search index.
67
80
  def searchable_content(file)
68
81
  content = File.read file
69
82
  content = CommonMarker.render_html content
70
- content.gsub(/<\/?[^>]*>/, "").gsub("\n", " ")
83
+ content.remove(/<\/?[^>]*>/).gsub("\n", " ")
71
84
  end
72
85
 
73
86
  def file_label(filename)
74
- filename.split('/').map { |i| i.to_label }.join(' / ')
87
+ filename
88
+ .remove(/\/(index|README)$/)
89
+ .split('/')
90
+ .map { |i| i.to_label }
91
+ .join(' / ')
92
+ end
93
+
94
+ def file_url(filename)
95
+ filename.remove(/\/(index|README)$/)
75
96
  end
76
97
  end
77
98
  end
@@ -1,3 +1,3 @@
1
1
  module Madness
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: madness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-10 00:00:00.000000000 Z
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay