Skip to content

Commit

Permalink
add match to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
neilboyd committed Dec 23, 2024
1 parent 1c61b7a commit d108ae3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ after `1.9.0` were actually the same as `1.9.0` because the build step was not e
I then made the following changes:
- add [dev container](https://code.visualstudio.com/docs/devcontainers/containers) configuration
- exact search using quotes instead of trailing space
- add query parameter to middleware
- add `query` and `match` parameters to middleware
- split search criteria on words instead of space
- add package version to header

Expand Down Expand Up @@ -189,7 +189,7 @@ Example:
```js
SimpleJekyllSearch({
...
templateMiddleware: function(prop, value, template, query) {
templateMiddleware: function(prop, value, template, query, match) {
if (prop === 'bar') {
return value.replace(/^\//, '')
}
Expand Down
2 changes: 1 addition & 1 deletion WIKI.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Example:
```js
SimpleJekyllSearch({
...
templateMiddleware: function(prop, value, template, query) {
templateMiddleware: function(prop, value, template, query, match) {
if (prop === 'bar') {
return value.replace(/^\//, '')
}
Expand Down
69 changes: 69 additions & 0 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
GEM
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
colorator (1.1.0)
concurrent-ruby (1.3.4)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
ffi (1.17.0-x86_64-linux-gnu)
forwardable-extended (2.6.0)
google-protobuf (3.25.5-x86_64-linux)
http_parser.rb (0.8.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jekyll (4.3.4)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 1.0)
jekyll-sass-converter (>= 2.0, < 4.0)
jekyll-watch (~> 2.0)
kramdown (~> 2.3, >= 2.3.1)
kramdown-parser-gfm (~> 1.0)
liquid (~> 4.0)
mercenary (>= 0.3.6, < 0.5)
pathutil (~> 0.9)
rouge (>= 3.0, < 5.0)
safe_yaml (~> 1.0)
terminal-table (>= 1.8, < 4.0)
webrick (~> 1.7)
jekyll-sass-converter (3.0.0)
sass-embedded (~> 1.54)
jekyll-watch (2.2.1)
listen (~> 3.0)
kramdown (2.5.1)
rexml (>= 3.3.9)
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.4)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (6.0.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rexml (3.3.9)
rouge (4.5.1)
safe_yaml (1.0.5)
sass-embedded (1.62.1-x86_64-linux-gnu)
google-protobuf (~> 3.21)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.6.0)
webrick (1.9.1)

PLATFORMS
x86_64-linux-gnu

DEPENDENCIES
jekyll

BUNDLED WITH
2.5.23
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-jekyll-search",
"version": "1.13.0",
"version": "1.14.0",
"description": "Simple Jekyll site search using javascript and json",
"main": "dest/simple-jekyll-search.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const year = new Date().getFullYear()
const stampTop =
`/*!
* Simple-Jekyll-Search ${version}
* Copyright 2015-${year}, Christian Fei
* Copyright 2015-${year}, Christian Fei, Neil Boyd
* Licensed under the MIT License.
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Templater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ test('renders the template with the provided data and query', t => {
t.deepEqual(templater.compile({ url: 'http://google.com', query: 'bar' }), '<a href="http://google.com?query=bar">url</a>')
})

test('renders the template with the match', t => {
t.deepEqual(templater.compile({ foo: 'bar' }), 'bar')

templater.setOptions({
template: '<b>{match}</b>'
})

t.deepEqual(templater.compile({ match: 'bar' }), '<b>bar"></b>')
})

test('replaces not found properties with the original pattern', t => {
const template = '{foo}'
templater.setOptions({
Expand Down

0 comments on commit d108ae3

Please sign in to comment.