-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from inertia186/improved-search-hits
Improved search hits
- Loading branch information
Showing
6 changed files
with
145 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Jekyll | ||
module KeywordifyFilter | ||
SEP = /[^a-z0-9_]+/i | ||
STOP_WORDS = %w(i me my myself we our ours ourselves you your yours yourself | ||
yourselves he him his himself she her hers herself it its itself they them | ||
their theirs themselves what which who whom this that these those am is | ||
are was were be been being have has had having do does did doing a an the | ||
and but if or because as until while of at by for with about against | ||
between into through during before after above below to from up down in | ||
out on off over under again further then once here there when where why | ||
how all any both each few more most other some such no nor not only own | ||
same so than too very s t can will just don should now) | ||
|
||
def keywordify(object, mode = 'subtract', extra_keywords = nil) | ||
output = [] | ||
|
||
case object | ||
when Hash | ||
object.each do |k, v| | ||
output += keywordify(k).split(SEP) | ||
output += keywordify(v).split(SEP) | ||
end | ||
when Array | ||
object.each do |k, v| | ||
output += keywordify(v).split(SEP) | ||
end | ||
when NilClass | ||
# no-op | ||
else | ||
output += object.inspect.split(SEP) | ||
end | ||
|
||
output = output.map(&:strip).map(&:downcase) | ||
extra_keywords = extra_keywords.to_s.split(SEP).map(&:strip).map(&:downcase) | ||
|
||
case mode | ||
when 'subtract' then output -= extra_keywords | ||
when 'add' then output += extra_keywords | ||
else; raise "Unknown mode: #{mode}" | ||
end | ||
|
||
(output - STOP_WORDS).uniq.compact.join(' ').strip | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_filter(Jekyll::KeywordifyFilter) | ||
|
||
# USAGE: | ||
# {{object | keywordify}} | ||
# {{object | keywordify 'subtract', 'some words to subtract'}} | ||
# {{object | keywordify 'add', 'additional words to add'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters