From 2b62cf5f15666292132bcaba7b8fc9f37eb3b2a7 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 2 Aug 2024 05:16:20 +0000 Subject: [PATCH 01/18] setup for dev containers --- .devcontainer/devcontainer.json | 22 ++++++++++++++++++++++ .github/dependabot.yml | 12 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/dependabot.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..964d46f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/jekyll +{ + "name": "Jekyll", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "jekyll --version" + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly From 78b64ef6a448f8a57f5cf0eee6c149689e53ef19 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 2 Aug 2024 06:01:53 +0000 Subject: [PATCH 02/18] editor config --- .editorconfig | 19 +++++++++++++++++++ .prettierrc | 3 +++ .vscode/extensions.json | 6 ++++++ 3 files changed, 28 insertions(+) create mode 100644 .editorconfig create mode 100644 .prettierrc create mode 100644 .vscode/extensions.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2b740bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +# Unix-style newlines with a newline ending every file +end_of_line = lf +insert_final_newline = true + +[*.{js,css,scss}] +quote_type = single + +[*.{yml,yaml}] +quote_type = double + +[*.md] +trim_trailing_whitespace = false diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..dceda2d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "semi": false +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..df3bcb5 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode", + "ms-vscode-remote.remote-containers" + ] +} \ No newline at end of file From e4b446156de00d0ae9911728486ecda135008968 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 2 Aug 2024 06:05:22 +0000 Subject: [PATCH 03/18] split on words --- src/SearchStrategies/LiteralSearchStrategy.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/SearchStrategies/LiteralSearchStrategy.js b/src/SearchStrategies/LiteralSearchStrategy.js index 0bcb4b9..8aa07ef 100644 --- a/src/SearchStrategies/LiteralSearchStrategy.js +++ b/src/SearchStrategies/LiteralSearchStrategy.js @@ -2,7 +2,9 @@ module.exports = new LiteralSearchStrategy() -function LiteralSearchStrategy () { +const segmenter = new Intl.Segmenter([], { granularity: 'word' }); + +function LiteralSearchStrategy() { this.matches = function (str, crit) { if (!str) return false str = str.trim().toLowerCase() @@ -16,8 +18,16 @@ function LiteralSearchStrategy () { crit = crit.substring(1, crit.length - 1) } crit = crit.toLowerCase() - crit = exact ? [crit] : crit.split(' ') + let critArray = [crit] + if (!exact) { + const segmentedText = segmenter.segment(crit); + critArray = [...segmentedText].filter(s => s.isWordLike).map(s => s.segment); + } - return crit.filter(word => str.indexOf(word) >= 0).length === crit.length + return ( + critArray + .filter((word) => str.indexOf(word) >= 0) + .length === critArray.length + ) } } From 41eb48dc030648412e53431c6b6ef35939f63819 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Wed, 7 Aug 2024 04:19:40 +0000 Subject: [PATCH 04/18] remove publsh step from workflow --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d425a5c..63b2aae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,9 +21,9 @@ jobs: # with: # record: false # # cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }} - - name: publish - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" - npm publish + # - name: publish + # env: + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # run: | + # npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" + # npm publish From 2d72e4c309fda9fdaff78ca29bc12f5859ef057c Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Wed, 7 Aug 2024 05:03:42 +0000 Subject: [PATCH 05/18] install npm --- .devcontainer/devcontainer.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 964d46f..e465240 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,10 +3,14 @@ { "name": "Jekyll", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye" + "image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye", // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, + "features": { + "ghcr.io/devcontainers-contrib/features/node-asdf:0": { + "version": "latest" + } + } // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], From bc164c2c6250b4c225903c107e822fa03c51fba4 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Wed, 7 Aug 2024 05:15:38 +0000 Subject: [PATCH 06/18] npm run dist --- dest/simple-jekyll-search.js | 14 ++++++++++++-- dest/simple-jekyll-search.min.js | 2 +- example/js/simple-jekyll-search.js | 14 ++++++++++++-- example/js/simple-jekyll-search.min.js | 2 +- src/SearchStrategies/LiteralSearchStrategy.js | 8 ++++---- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/dest/simple-jekyll-search.js b/dest/simple-jekyll-search.js index 364163b..468c17e 100644 --- a/dest/simple-jekyll-search.js +++ b/dest/simple-jekyll-search.js @@ -79,6 +79,8 @@ function FuzzySearchStrategy () { var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy() +const segmenter = new Intl.Segmenter([], { granularity: 'word' }) + function LiteralSearchStrategy () { this.matches = function (str, crit) { if (!str) return false @@ -93,9 +95,17 @@ function LiteralSearchStrategy () { crit = crit.substring(1, crit.length - 1) } crit = crit.toLowerCase() - crit = exact ? [crit] : crit.split(' ') + let critArray = [crit] + if (!exact) { + const segmentedText = segmenter.segment(crit) + critArray = [...segmentedText].filter(s => s.isWordLike).map(s => s.segment) + } - return crit.filter(word => str.indexOf(word) >= 0).length === crit.length + return ( + critArray + .filter((word) => str.indexOf(word) >= 0) + .length === critArray.length + ) } } diff --git a/dest/simple-jekyll-search.min.js b/dest/simple-jekyll-search.min.js index 6aa6048..8416f41 100644 --- a/dest/simple-jekyll-search.min.js +++ b/dest/simple-jekyll-search.min.js @@ -3,4 +3,4 @@ * Copyright 2015-2024, Christian Fei * Licensed under the MIT License. */ -!function(){"use strict";var o={compile:function(r){return i.template.replace(i.pattern,function(t,e){var n=i.middleware(e,r[e],i.template,r.query);return void 0!==n?n:r[e]||t})},setOptions:function(t){i.pattern=t.pattern||i.pattern,i.template=t.template||i.template,"function"==typeof t.middleware&&(i.middleware=t.middleware)}};const i={};i.pattern=/\{(.*?)\}/g,i.template="",i.middleware=function(){};var n=function(t,e){var n=e.length,r=t.length;if(n0<=e.indexOf(t)).length===t.length}};var u={put:function(t){if(f(t))return d(t);if(function(t){return Boolean(t)&&"[object Array]"===Object.prototype.toString.call(t)}(t))return function(n){var r=[];l();for(let t=0,e=n.length;t{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const T=function(t,e){e?(clearTimeout(n),n=setTimeout(t,e)):t.call()},x=["searchInput","resultsContainer","json"],j=t({required:x});function w(t){u.put(t),i.searchInput.addEventListener("input",function(t){-1===[13,16,20,37,38,39,40,91].indexOf(t.which)&&(g(),T(function(){O(t.target.value)},i.debounceTime))})}function g(){i.resultsContainer.innerHTML=""}function v(t){i.resultsContainer.innerHTML+=t}function O(t){var e;(e=t)&&0e.isWordLike).map(e=>e.segment)),r.filter(e=>0<=t.indexOf(e)).length===r.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0 s.isWordLike).map(s => s.segment) + } - return crit.filter(word => str.indexOf(word) >= 0).length === crit.length + return ( + critArray + .filter((word) => str.indexOf(word) >= 0) + .length === critArray.length + ) } } diff --git a/example/js/simple-jekyll-search.min.js b/example/js/simple-jekyll-search.min.js index 6aa6048..8416f41 100644 --- a/example/js/simple-jekyll-search.min.js +++ b/example/js/simple-jekyll-search.min.js @@ -3,4 +3,4 @@ * Copyright 2015-2024, Christian Fei * Licensed under the MIT License. */ -!function(){"use strict";var o={compile:function(r){return i.template.replace(i.pattern,function(t,e){var n=i.middleware(e,r[e],i.template,r.query);return void 0!==n?n:r[e]||t})},setOptions:function(t){i.pattern=t.pattern||i.pattern,i.template=t.template||i.template,"function"==typeof t.middleware&&(i.middleware=t.middleware)}};const i={};i.pattern=/\{(.*?)\}/g,i.template="",i.middleware=function(){};var n=function(t,e){var n=e.length,r=t.length;if(n0<=e.indexOf(t)).length===t.length}};var u={put:function(t){if(f(t))return d(t);if(function(t){return Boolean(t)&&"[object Array]"===Object.prototype.toString.call(t)}(t))return function(n){var r=[];l();for(let t=0,e=n.length;t{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const T=function(t,e){e?(clearTimeout(n),n=setTimeout(t,e)):t.call()},x=["searchInput","resultsContainer","json"],j=t({required:x});function w(t){u.put(t),i.searchInput.addEventListener("input",function(t){-1===[13,16,20,37,38,39,40,91].indexOf(t.which)&&(g(),T(function(){O(t.target.value)},i.debounceTime))})}function g(){i.resultsContainer.innerHTML=""}function v(t){i.resultsContainer.innerHTML+=t}function O(t){var e;(e=t)&&0e.isWordLike).map(e=>e.segment)),r.filter(e=>0<=t.indexOf(e)).length===r.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0 s.isWordLike).map(s => s.segment); + const segmentedText = segmenter.segment(crit) + critArray = [...segmentedText].filter(s => s.isWordLike).map(s => s.segment) } return ( From c72250c4f19b99a98fd7b2f9902d4d005cddc19d Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 04:57:41 +0000 Subject: [PATCH 07/18] don't use trailing space as exact search indicator --- src/SearchStrategies/LiteralSearchStrategy.js | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/SearchStrategies/LiteralSearchStrategy.js b/src/SearchStrategies/LiteralSearchStrategy.js index 7f83657..bc6fe20 100644 --- a/src/SearchStrategies/LiteralSearchStrategy.js +++ b/src/SearchStrategies/LiteralSearchStrategy.js @@ -4,30 +4,25 @@ module.exports = new LiteralSearchStrategy() const segmenter = new Intl.Segmenter([], { granularity: 'word' }) -function LiteralSearchStrategy () { +function LiteralSearchStrategy() { this.matches = function (str, crit) { - if (!str) return false + if (!str) { + return false + } str = str.trim().toLowerCase() + crit = crit.trim().toLowerCase() - let exact = false - if (crit.endsWith(' ')) { - exact = true - } if (crit.startsWith('"') && crit.endsWith('"')) { - exact = true - crit = crit.substring(1, crit.length - 1) - } - crit = crit.toLowerCase() - let critArray = [crit] - if (!exact) { + let critArray = [crit.substring(1, crit.length - 1)] + } else { const segmentedText = segmenter.segment(crit) - critArray = [...segmentedText].filter(s => s.isWordLike).map(s => s.segment) + let critArray = [...segmentedText] + .filter((s) => s.isWordLike) + .map((s) => s.segment) } - return ( - critArray - .filter((word) => str.indexOf(word) >= 0) - .length === critArray.length - ) + let filter = critArray.filter((word) => str.indexOf(word) >= 0) + + return filter.length === critArray.length // true if it found all the words } } From b398c108b22d183cf6fc4fc91761d108512a9b05 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 05:32:03 +0000 Subject: [PATCH 08/18] put back publish step, but ignore error --- .github/workflows/main.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 63b2aae..89f4e94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,9 +21,10 @@ jobs: # with: # record: false # # cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }} - # - name: publish - # env: - # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # run: | - # npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" - # npm publish + - name: publish + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" + npm publish + continue-on-error: true From 6f76a0b83e8d463e4518ff1356a48ace37391e2a Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 05:36:40 +0000 Subject: [PATCH 09/18] fix linter errors --- src/SearchStrategies/LiteralSearchStrategy.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SearchStrategies/LiteralSearchStrategy.js b/src/SearchStrategies/LiteralSearchStrategy.js index bc6fe20..3bf03ba 100644 --- a/src/SearchStrategies/LiteralSearchStrategy.js +++ b/src/SearchStrategies/LiteralSearchStrategy.js @@ -4,7 +4,7 @@ module.exports = new LiteralSearchStrategy() const segmenter = new Intl.Segmenter([], { granularity: 'word' }) -function LiteralSearchStrategy() { +function LiteralSearchStrategy () { this.matches = function (str, crit) { if (!str) { return false @@ -12,16 +12,17 @@ function LiteralSearchStrategy() { str = str.trim().toLowerCase() crit = crit.trim().toLowerCase() + let critArray = [] if (crit.startsWith('"') && crit.endsWith('"')) { - let critArray = [crit.substring(1, crit.length - 1)] + critArray = [crit.substring(1, crit.length - 1)] } else { const segmentedText = segmenter.segment(crit) - let critArray = [...segmentedText] + critArray = [...segmentedText] .filter((s) => s.isWordLike) .map((s) => s.segment) } - let filter = critArray.filter((word) => str.indexOf(word) >= 0) + const filter = critArray.filter((word) => str.indexOf(word) >= 0) return filter.length === critArray.length // true if it found all the words } From f8ac9214209c92213ed3cccb0a4152dabf2e654d Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 05:36:58 +0000 Subject: [PATCH 10/18] remove trailing space tests --- tests/SearchStrategies/LiteralSearchStrategy.test.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/SearchStrategies/LiteralSearchStrategy.test.js b/tests/SearchStrategies/LiteralSearchStrategy.test.js index 742827d..44e71da 100644 --- a/tests/SearchStrategies/LiteralSearchStrategy.test.js +++ b/tests/SearchStrategies/LiteralSearchStrategy.test.js @@ -14,10 +14,6 @@ test('matches a word that is contained in the search criteria (multiple words)', t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', 'hello text world'), true) }) -test('matches exact words when exacts words with space in the search criteria', t => { - t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', 'hello world '), true) -}) - test('matches exact words when exacts words with quotes in the search criteria', t => { t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', '"hello world"'), true) }) @@ -26,14 +22,6 @@ test('matches exact last words when exacts words with quotes in the search crite t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', '"search text"'), true) }) -test('does not matches multiple words if not exact words with space in the search criteria', t => { - t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', 'hello text world '), false) -}) - test('matches a word that is partially contained in the search criteria', t => { t.deepEqual(LiteralSearchStrategy.matches('this tasty tester text', 'test'), true) }) - -test('does not matches a word that is partially contained in the search criteria when followed by a space', t => { - t.deepEqual(LiteralSearchStrategy.matches('this tasty tester text', 'test '), false) -}) From 1907976d1d1d45e4798c967f7352e71be5b78dba Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 10:05:03 +0000 Subject: [PATCH 11/18] build current branch, only publish on master branch --- .github/workflows/main.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89f4e94..2d7e608 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,9 +4,8 @@ jobs: build_deploy: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@master - with: - ref: refs/heads/master + - name: Checkout + uses: actions/checkout@v4 - name: install run: | npm install @@ -22,9 +21,9 @@ jobs: # record: false # # cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }} - name: publish + if: github.ref == 'refs/heads/master' env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" npm publish - continue-on-error: true From fdff4af1108433c3a7e1493f0466cd05203ed138 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 10:05:54 +0000 Subject: [PATCH 12/18] recommend github actions extension --- .vscode/extensions.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index df3bcb5..c112f5b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,7 @@ { "recommendations": [ "esbenp.prettier-vscode", - "ms-vscode-remote.remote-containers" + "ms-vscode-remote.remote-containers", + "github.vscode-github-actions" ] } \ No newline at end of file From 8d0df14d1088e52892786fbf92324f86639104e9 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Thu, 8 Aug 2024 10:07:43 +0000 Subject: [PATCH 13/18] update readme --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 0127993..32d69bd 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ # [Simple-Jekyll-Search](https://www.npmjs.com/package/simple-jekyll-search) -[![Build Status](https://img.shields.io/travis/christian-fei/Simple-Jekyll-Search/master.svg?)](https://travis-ci.org/christian-fei/Simple-Jekyll-Search) -[![dependencies Status](https://img.shields.io/david/christian-fei/Simple-Jekyll-Search.svg)](https://david-dm.org/christian-fei/Simple-Jekyll-Search) -[![devDependencies Status](https://img.shields.io/david/dev/christian-fei/Simple-Jekyll-Search.svg)](https://david-dm.org/christian-fei/Simple-Jekyll-Search?type=dev) - A JavaScript library to add search functionality to any Jekyll blog. ## Use case @@ -328,7 +324,3 @@ Thanks to all [contributors](https://github.com/christian-fei/Simple-Jekyll-Sear [@kremalicious](https://github.com/kremalicious) [@tibotiber](https://github.com/tibotiber) and many others! - -## Stargazers over time - -[![Stargazers over time](https://starchart.cc/christian-fei/Simple-Jekyll-Search.svg)](https://starchart.cc/christian-fei/Simple-Jekyll-Search) From 9491f8d0695c733bc673681a894a1b7e8b4b0873 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 9 Aug 2024 04:55:02 +0000 Subject: [PATCH 14/18] test --- tests/SearchStrategies/LiteralSearchStrategy.test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/SearchStrategies/LiteralSearchStrategy.test.js b/tests/SearchStrategies/LiteralSearchStrategy.test.js index 44e71da..0dbb0c4 100644 --- a/tests/SearchStrategies/LiteralSearchStrategy.test.js +++ b/tests/SearchStrategies/LiteralSearchStrategy.test.js @@ -25,3 +25,11 @@ test('matches exact last words when exacts words with quotes in the search crite test('matches a word that is partially contained in the search criteria', t => { t.deepEqual(LiteralSearchStrategy.matches('this tasty tester text', 'test'), true) }) + +test('matches when search criteria has puncuation', t => { + t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', 'hello, world!'), true) +}) + +test('does not match when only only one word of search criteria is in the text', t => { + t.deepEqual(LiteralSearchStrategy.matches('hello world test search text', 'hello muppet'), false) +}) From 1f11095bda9f0cc9835ebec4b371723190eb7529 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 9 Aug 2024 04:56:06 +0000 Subject: [PATCH 15/18] increase version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ac5694..0bd32cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-jekyll-search", - "version": "1.11.1", + "version": "1.12.0", "description": "Simple Jekyll site search using javascript and json", "main": "dest/simple-jekyll-search.js", "scripts": { From 9fc85ab612abb7192dc1f6ce2d39341e7a7af8bf Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 9 Aug 2024 05:04:07 +0000 Subject: [PATCH 16/18] don't specify node version --- .devcontainer/devcontainer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e465240..3e8c1dc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,9 +7,7 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { - "ghcr.io/devcontainers-contrib/features/node-asdf:0": { - "version": "latest" - } + "ghcr.io/devcontainers-contrib/features/node-asdf:0": {} } // Use 'forwardPorts' to make a list of ports inside the container available locally. From 983ecdf4e6c82a44de60bc516d916ee6ffd0f7e5 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 9 Aug 2024 05:21:02 +0000 Subject: [PATCH 17/18] add version to header --- package.json | 2 +- scripts/stamp.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0bd32cd..3985ea7 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "pretest": "npm run lint", "prebuild": "npm run test", "postbuild": "npm run copy-example-code", - "browserify": "browserify -p browser-pack-flat/plugin src/index.js | node scripts/stamp.js > dest/simple-jekyll-search.js", + "browserify": "browserify -p browser-pack-flat/plugin src/index.js | node scripts/stamp.js ${npm_package_version} > dest/simple-jekyll-search.js", "build": "npm run browserify && npm run uglify", "dist": "npm run build && npm run copy-example-code", "test": "ava", diff --git a/scripts/stamp.js b/scripts/stamp.js index 9a3bd75..88f23db 100644 --- a/scripts/stamp.js +++ b/scripts/stamp.js @@ -4,11 +4,13 @@ 'use strict' +const version = process.argv[2] || '' + const year = new Date().getFullYear() const stampTop = `/*! - * Simple-Jekyll-Search + * Simple-Jekyll-Search ${version} * Copyright 2015-${year}, Christian Fei * Licensed under the MIT License. */ From 6db942f18533215a70c429934c5ebbde2f766140 Mon Sep 17 00:00:00 2001 From: Neil Boyd Date: Fri, 9 Aug 2024 05:23:29 +0000 Subject: [PATCH 18/18] npm run dist --- dest/simple-jekyll-search.js | 32 +++++++++++--------------- dest/simple-jekyll-search.min.js | 4 ++-- example/js/simple-jekyll-search.js | 32 +++++++++++--------------- example/js/simple-jekyll-search.min.js | 4 ++-- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/dest/simple-jekyll-search.js b/dest/simple-jekyll-search.js index 468c17e..df066db 100644 --- a/dest/simple-jekyll-search.js +++ b/dest/simple-jekyll-search.js @@ -1,5 +1,5 @@ /*! - * Simple-Jekyll-Search + * Simple-Jekyll-Search 1.12.0 * Copyright 2015-2024, Christian Fei * Licensed under the MIT License. */ @@ -83,29 +83,25 @@ const segmenter = new Intl.Segmenter([], { granularity: 'word' }) function LiteralSearchStrategy () { this.matches = function (str, crit) { - if (!str) return false + if (!str) { + return false + } str = str.trim().toLowerCase() + crit = crit.trim().toLowerCase() - let exact = false - if (crit.endsWith(' ')) { - exact = true - } + let critArray = [] if (crit.startsWith('"') && crit.endsWith('"')) { - exact = true - crit = crit.substring(1, crit.length - 1) - } - crit = crit.toLowerCase() - let critArray = [crit] - if (!exact) { + critArray = [crit.substring(1, crit.length - 1)] + } else { const segmentedText = segmenter.segment(crit) - critArray = [...segmentedText].filter(s => s.isWordLike).map(s => s.segment) + critArray = [...segmentedText] + .filter((s) => s.isWordLike) + .map((s) => s.segment) } - return ( - critArray - .filter((word) => str.indexOf(word) >= 0) - .length === critArray.length - ) + const filter = critArray.filter((word) => str.indexOf(word) >= 0) + + return filter.length === critArray.length // true if it found all the words } } diff --git a/dest/simple-jekyll-search.min.js b/dest/simple-jekyll-search.min.js index 8416f41..9964f7a 100644 --- a/dest/simple-jekyll-search.min.js +++ b/dest/simple-jekyll-search.min.js @@ -1,6 +1,6 @@ /*! - * Simple-Jekyll-Search + * Simple-Jekyll-Search 1.12.0 * Copyright 2015-2024, Christian Fei * Licensed under the MIT License. */ -!function(){"use strict";var o={compile:function(r){return i.template.replace(i.pattern,function(e,t){var n=i.middleware(t,r[t],i.template,r.query);return void 0!==n?n:r[t]||e})},setOptions:function(e){i.pattern=e.pattern||i.pattern,i.template=e.template||i.template,"function"==typeof e.middleware&&(i.middleware=e.middleware)}};const i={};i.pattern=/\{(.*?)\}/g,i.template="",i.middleware=function(){};var n=function(e,t){var n=t.length,r=e.length;if(ne.isWordLike).map(e=>e.segment)),r.filter(e=>0<=t.indexOf(e)).length===r.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0e.isWordLike).map(e=>e.segment)).filter(e=>0<=t.indexOf(e)).length===n.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0 s.isWordLike).map(s => s.segment) + critArray = [...segmentedText] + .filter((s) => s.isWordLike) + .map((s) => s.segment) } - return ( - critArray - .filter((word) => str.indexOf(word) >= 0) - .length === critArray.length - ) + const filter = critArray.filter((word) => str.indexOf(word) >= 0) + + return filter.length === critArray.length // true if it found all the words } } diff --git a/example/js/simple-jekyll-search.min.js b/example/js/simple-jekyll-search.min.js index 8416f41..9964f7a 100644 --- a/example/js/simple-jekyll-search.min.js +++ b/example/js/simple-jekyll-search.min.js @@ -1,6 +1,6 @@ /*! - * Simple-Jekyll-Search + * Simple-Jekyll-Search 1.12.0 * Copyright 2015-2024, Christian Fei * Licensed under the MIT License. */ -!function(){"use strict";var o={compile:function(r){return i.template.replace(i.pattern,function(e,t){var n=i.middleware(t,r[t],i.template,r.query);return void 0!==n?n:r[t]||e})},setOptions:function(e){i.pattern=e.pattern||i.pattern,i.template=e.template||i.template,"function"==typeof e.middleware&&(i.middleware=e.middleware)}};const i={};i.pattern=/\{(.*?)\}/g,i.template="",i.middleware=function(){};var n=function(e,t){var n=t.length,r=e.length;if(ne.isWordLike).map(e=>e.segment)),r.filter(e=>0<=t.indexOf(e)).length===r.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0e.isWordLike).map(e=>e.segment)).filter(e=>0<=t.indexOf(e)).length===n.length}};const u=new Intl.Segmenter([],{granularity:"word"});var c={put:function(e){if(d(e))return p(e);if(function(e){return Boolean(e)&&"[object Array]"===Object.prototype.toString.call(e)}(e))return function(n){var r=[];f();for(let e=0,t=n.length;e{title}',templateMiddleware:Function.prototype,sortMiddleware:function(){return 0},noResultsText:"No results found",limit:10,fuzzy:!1,debounceTime:null,exclude:[],onSearch:Function.prototype},n;const x=function(e,t){t?(clearTimeout(n),n=setTimeout(e,t)):e.call()},j=["searchInput","resultsContainer","json"],q=e({required:j});function w(e){c.put(e),i.searchInput.addEventListener("input",function(e){-1===[13,16,20,37,38,39,40,91].indexOf(e.which)&&(v(),x(function(){O(e.target.value)},i.debounceTime))})}function v(){i.resultsContainer.innerHTML=""}function S(e){i.resultsContainer.innerHTML+=e}function O(e){var t;(t=e)&&0