Skip to content

Commit

Permalink
Merge pull request #5 from neilboyd/split-words
Browse files Browse the repository at this point in the history
Split words
  • Loading branch information
neilboyd authored Aug 9, 2024
2 parents 9746038 + 6db942f commit 75d98c0
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 60 deletions.
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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": {
"ghcr.io/devcontainers-contrib/features/node-asdf:0": {}
}

// 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"
}
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +21,7 @@ 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: |
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"semi": false
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"ms-vscode-remote.remote-containers",
"github.vscode-github-actions"
]
}
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
28 changes: 17 additions & 11 deletions dest/simple-jekyll-search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Simple-Jekyll-Search
* Simple-Jekyll-Search 1.12.0
* Copyright 2015-2024, Christian Fei
* Licensed under the MIT License.
*/
Expand Down Expand Up @@ -79,23 +79,29 @@ 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
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)
critArray = [crit.substring(1, crit.length - 1)]
} else {
const segmentedText = segmenter.segment(crit)
critArray = [...segmentedText]
.filter((s) => s.isWordLike)
.map((s) => s.segment)
}
crit = crit.toLowerCase()
crit = exact ? [crit] : crit.split(' ')

return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
const filter = critArray.filter((word) => str.indexOf(word) >= 0)

return filter.length === critArray.length // true if it found all the words
}
}

Expand Down
4 changes: 2 additions & 2 deletions dest/simple-jekyll-search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions example/js/simple-jekyll-search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Simple-Jekyll-Search
* Simple-Jekyll-Search 1.12.0
* Copyright 2015-2024, Christian Fei
* Licensed under the MIT License.
*/
Expand Down Expand Up @@ -79,23 +79,29 @@ 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
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)
critArray = [crit.substring(1, crit.length - 1)]
} else {
const segmentedText = segmenter.segment(crit)
critArray = [...segmentedText]
.filter((s) => s.isWordLike)
.map((s) => s.segment)
}
crit = crit.toLowerCase()
crit = exact ? [crit] : crit.split(' ')

return crit.filter(word => str.indexOf(word) >= 0).length === crit.length
const filter = critArray.filter((word) => str.indexOf(word) >= 0)

return filter.length === critArray.length // true if it found all the words
}
}

Expand Down
Loading

0 comments on commit 75d98c0

Please sign in to comment.