Skip to content

Commit 75d98c0

Browse files
authored
Merge pull request #5 from neilboyd/split-words
Split words
2 parents 9746038 + 6db942f commit 75d98c0

15 files changed

+133
-60
lines changed

Diff for: .devcontainer/devcontainer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/jekyll
3+
{
4+
"name": "Jekyll",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/jekyll:2-bullseye",
7+
8+
// Features to add to the dev container. More info: https://containers.dev/features.
9+
"features": {
10+
"ghcr.io/devcontainers-contrib/features/node-asdf:0": {}
11+
}
12+
13+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
14+
// "forwardPorts": [],
15+
16+
// Uncomment the next line to run commands after the container is created.
17+
// "postCreateCommand": "jekyll --version"
18+
19+
// Configure tool-specific properties.
20+
// "customizations": {},
21+
22+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
23+
// "remoteUser": "root"
24+
}

Diff for: .editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
trim_trailing_whitespace = true
8+
# Unix-style newlines with a newline ending every file
9+
end_of_line = lf
10+
insert_final_newline = true
11+
12+
[*.{js,css,scss}]
13+
quote_type = single
14+
15+
[*.{yml,yaml}]
16+
quote_type = double
17+
18+
[*.md]
19+
trim_trailing_whitespace = false

Diff for: .github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

Diff for: .github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ jobs:
44
build_deploy:
55
runs-on: ubuntu-22.04
66
steps:
7-
- uses: actions/checkout@master
8-
with:
9-
ref: refs/heads/master
7+
- name: Checkout
8+
uses: actions/checkout@v4
109
- name: install
1110
run: |
1211
npm install
@@ -22,6 +21,7 @@ jobs:
2221
# record: false
2322
# # cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }}
2423
- name: publish
24+
if: github.ref == 'refs/heads/master'
2525
env:
2626
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2727
run: |

Diff for: .prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": false
3+
}

Diff for: .vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"ms-vscode-remote.remote-containers",
5+
"github.vscode-github-actions"
6+
]
7+
}

Diff for: README.md

-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# [Simple-Jekyll-Search](https://www.npmjs.com/package/simple-jekyll-search)
22

3-
[![Build Status](https://img.shields.io/travis/christian-fei/Simple-Jekyll-Search/master.svg?)](https://travis-ci.org/christian-fei/Simple-Jekyll-Search)
4-
[![dependencies Status](https://img.shields.io/david/christian-fei/Simple-Jekyll-Search.svg)](https://david-dm.org/christian-fei/Simple-Jekyll-Search)
5-
[![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)
6-
73
A JavaScript library to add search functionality to any Jekyll blog.
84

95
## Use case
@@ -328,7 +324,3 @@ Thanks to all [contributors](https://github.com/christian-fei/Simple-Jekyll-Sear
328324
[@kremalicious](https://github.com/kremalicious)
329325
[@tibotiber](https://github.com/tibotiber)
330326
and many others!
331-
332-
## Stargazers over time
333-
334-
[![Stargazers over time](https://starchart.cc/christian-fei/Simple-Jekyll-Search.svg)](https://starchart.cc/christian-fei/Simple-Jekyll-Search)

Diff for: dest/simple-jekyll-search.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Simple-Jekyll-Search
2+
* Simple-Jekyll-Search 1.12.0
33
* Copyright 2015-2024, Christian Fei
44
* Licensed under the MIT License.
55
*/
@@ -79,23 +79,29 @@ function FuzzySearchStrategy () {
7979

8080
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
8181

82+
const segmenter = new Intl.Segmenter([], { granularity: 'word' })
83+
8284
function LiteralSearchStrategy () {
8385
this.matches = function (str, crit) {
84-
if (!str) return false
86+
if (!str) {
87+
return false
88+
}
8589
str = str.trim().toLowerCase()
90+
crit = crit.trim().toLowerCase()
8691

87-
let exact = false
88-
if (crit.endsWith(' ')) {
89-
exact = true
90-
}
92+
let critArray = []
9193
if (crit.startsWith('"') && crit.endsWith('"')) {
92-
exact = true
93-
crit = crit.substring(1, crit.length - 1)
94+
critArray = [crit.substring(1, crit.length - 1)]
95+
} else {
96+
const segmentedText = segmenter.segment(crit)
97+
critArray = [...segmentedText]
98+
.filter((s) => s.isWordLike)
99+
.map((s) => s.segment)
94100
}
95-
crit = crit.toLowerCase()
96-
crit = exact ? [crit] : crit.split(' ')
97101

98-
return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
102+
const filter = critArray.filter((word) => str.indexOf(word) >= 0)
103+
104+
return filter.length === critArray.length // true if it found all the words
99105
}
100106
}
101107

Diff for: dest/simple-jekyll-search.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: example/js/simple-jekyll-search.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Simple-Jekyll-Search
2+
* Simple-Jekyll-Search 1.12.0
33
* Copyright 2015-2024, Christian Fei
44
* Licensed under the MIT License.
55
*/
@@ -79,23 +79,29 @@ function FuzzySearchStrategy () {
7979

8080
var _$LiteralSearchStrategy_6 = new LiteralSearchStrategy()
8181

82+
const segmenter = new Intl.Segmenter([], { granularity: 'word' })
83+
8284
function LiteralSearchStrategy () {
8385
this.matches = function (str, crit) {
84-
if (!str) return false
86+
if (!str) {
87+
return false
88+
}
8589
str = str.trim().toLowerCase()
90+
crit = crit.trim().toLowerCase()
8691

87-
let exact = false
88-
if (crit.endsWith(' ')) {
89-
exact = true
90-
}
92+
let critArray = []
9193
if (crit.startsWith('"') && crit.endsWith('"')) {
92-
exact = true
93-
crit = crit.substring(1, crit.length - 1)
94+
critArray = [crit.substring(1, crit.length - 1)]
95+
} else {
96+
const segmentedText = segmenter.segment(crit)
97+
critArray = [...segmentedText]
98+
.filter((s) => s.isWordLike)
99+
.map((s) => s.segment)
94100
}
95-
crit = crit.toLowerCase()
96-
crit = exact ? [crit] : crit.split(' ')
97101

98-
return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
102+
const filter = critArray.filter((word) => str.indexOf(word) >= 0)
103+
104+
return filter.length === critArray.length // true if it found all the words
99105
}
100106
}
101107

0 commit comments

Comments
 (0)