Skip to content

Commit 9746038

Browse files
authored
Merge pull request #4 from neilboyd/add-query-to-middleware
add query to middleware
2 parents f9bc704 + 380b101 commit 9746038

11 files changed

+18
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ If the `search.json` contains this data
167167

168168
A function that will be called whenever a match in the template is found.
169169

170-
It gets passed the current property name, property value, and the template.
170+
It gets passed the current property name, property value, the template, and the search query.
171171

172172
If the function returns a non-undefined value, it gets replaced in the template.
173173

@@ -178,7 +178,7 @@ Example:
178178
```js
179179
SimpleJekyllSearch({
180180
...
181-
templateMiddleware: function(prop, value, template) {
181+
templateMiddleware: function(prop, value, template, query) {
182182
if (prop === 'bar') {
183183
return value.replace(/^\//, '')
184184
}

WIKI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ If the `search.json` contains this data
5757

5858
A function that will be called whenever a match in the template is found.
5959

60-
It gets passed the current property name, property value, and the template.
60+
It gets passed the current property name, property value, the template, and the search query.
6161

6262
If the function returns a non-undefined value, it gets replaced in the template.
6363

@@ -68,7 +68,7 @@ Example:
6868
```js
6969
SimpleJekyllSearch({
7070
...
71-
templateMiddleware: function(prop, value, template) {
71+
templateMiddleware: function(prop, value, template, query) {
7272
if (prop === 'bar') {
7373
return value.replace(/^\//, '')
7474
}

dest/simple-jekyll-search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function setOptions (_options) {
2727

2828
function compile (data) {
2929
return options.template.replace(options.pattern, function (match, prop) {
30-
const value = options.middleware(prop, data[prop], options.template)
30+
const value = options.middleware(prop, data[prop], options.template, data.query)
3131
if (typeof value !== 'undefined') {
3232
return value
3333
}
@@ -90,7 +90,7 @@ function LiteralSearchStrategy () {
9090
}
9191
if (crit.startsWith('"') && crit.endsWith('"')) {
9292
exact = true
93-
crit = crit.substring(1, crit.length - 2)
93+
crit = crit.substring(1, crit.length - 1)
9494
}
9595
crit = crit.toLowerCase()
9696
crit = exact ? [crit] : crit.split(' ')
@@ -192,7 +192,7 @@ function findMatches (data, crit, strategy, opt) {
192192

193193
function findMatchesInObject (obj, crit, strategy, opt) {
194194
for (const key in obj) {
195-
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
195+
if (key !== 'query' && !isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
196196
return obj
197197
}
198198
}

dest/simple-jekyll-search.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/js/simple-jekyll-search.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function setOptions (_options) {
2727

2828
function compile (data) {
2929
return options.template.replace(options.pattern, function (match, prop) {
30-
const value = options.middleware(prop, data[prop], options.template)
30+
const value = options.middleware(prop, data[prop], options.template, data.query)
3131
if (typeof value !== 'undefined') {
3232
return value
3333
}
@@ -90,7 +90,7 @@ function LiteralSearchStrategy () {
9090
}
9191
if (crit.startsWith('"') && crit.endsWith('"')) {
9292
exact = true
93-
crit = crit.substring(1, crit.length - 2)
93+
crit = crit.substring(1, crit.length - 1)
9494
}
9595
crit = crit.toLowerCase()
9696
crit = exact ? [crit] : crit.split(' ')
@@ -192,7 +192,7 @@ function findMatches (data, crit, strategy, opt) {
192192

193193
function findMatchesInObject (obj, crit, strategy, opt) {
194194
for (const key in obj) {
195-
if (!isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
195+
if (key !== 'query' && !isExcluded(obj[key], opt.exclude) && strategy.matches(obj[key], crit)) {
196196
return obj
197197
}
198198
}

0 commit comments

Comments
 (0)