remove lunr dependencies in favor of https://pagefind.app/
This commit is contained in:
parent
39485035ba
commit
bf5acb097c
14
README.md
14
README.md
|
@ -15,7 +15,7 @@ These simple scripts **enrich your Jamstack-site** by adding/manipulating/whatev
|
|||
Usage:
|
||||
|
||||
1. `yarn add jam-my-stack`
|
||||
2. `const { mastodon, goodreads, lunr } = require('jam-my-stack')`
|
||||
2. `const { mastodon, goodreads } = require('jam-my-stack')`
|
||||
|
||||
### 1. Mastodon
|
||||
|
||||
|
@ -102,18 +102,10 @@ Usage example:
|
|||
|
||||
### 3. Lunr
|
||||
|
||||
#### 3.1 `buildIndex`
|
||||
As of version `1.0.30`, Lunr functionality was removed in favor of https://pagefind.app/
|
||||
|
||||
An async function that reads all `.md` files of certain locations (pass as an array `[]`), generating a [Lunr.js](https://lunrjs.com/) `.json` index object. Serialize it yourself wherever you'd like it to go.
|
||||
With Pagefind, there's no need to integrate it into jam-my-stack, greatly simplifying things _and_ reducing the index file size.
|
||||
|
||||
Usage example:
|
||||
|
||||
```js
|
||||
const index = await lunr.buildIndex([
|
||||
`${__dirname}/content/post`,
|
||||
`${__dirname}/content/notes`])
|
||||
await fsp.writeFile(`${__dirname}/static/js/brainbaking-post.json`, JSON.stringify(index), 'utf-8')
|
||||
```
|
||||
|
||||
### 4. Howlongtobeat
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jam-my-stack",
|
||||
"version": "1.0.29",
|
||||
"version": "1.0.30",
|
||||
"repository": {
|
||||
"url": "https://github.com/wgroeneveld/jam-my-stack",
|
||||
"type": "git"
|
||||
|
@ -19,7 +19,6 @@
|
|||
"got": "11.8.3",
|
||||
"howlongtobeat": "^1.5.1",
|
||||
"imagemagick": "^0.1.3",
|
||||
"lunr": "^2.3.9",
|
||||
"parser-front-matter": "^1.6.4",
|
||||
"youtube-dl-exec": "^1.2.4"
|
||||
},
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const { parseMastoFeed } = require('./mastodon/feed-parser')
|
||||
const { widgetify } = require('./goodreads/widgetify.js')
|
||||
const { buildIndex } = require('./lunr/index-builder.js')
|
||||
const { howlong } = require('./howlongtobeat/howlong.js')
|
||||
const { thumbify } = require('./youtube/thumbify.js')
|
||||
|
||||
|
@ -15,9 +14,6 @@ module.exports = {
|
|||
goodreads: {
|
||||
createWidget: widgetify
|
||||
},
|
||||
lunr: {
|
||||
buildIndex: buildIndex
|
||||
},
|
||||
howlongtobeat: {
|
||||
howlong: howlong
|
||||
},
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
const fs = require('fs').promises;
|
||||
const { getFiles } = require('./../file-utils');
|
||||
const { promisify } = require('util');
|
||||
const frontMatterParser = require('parser-front-matter');
|
||||
|
||||
const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
|
||||
|
||||
|
||||
async function loadPostsWithFrontMatter(postsDirectoryPath) {
|
||||
const postNames = await getFiles(postsDirectoryPath);
|
||||
const posts = await Promise.all(
|
||||
// could be .DS_Store stuff found using recursive function above...
|
||||
postNames.filter(name => name.endsWith('.md')).map(async fileName => {
|
||||
const fileContent = await fs.readFile(fileName, 'utf8');
|
||||
const {content, data} = await parse(fileContent);
|
||||
return {
|
||||
content: content.slice(0, 3000),
|
||||
...data
|
||||
};
|
||||
})
|
||||
);
|
||||
return posts;
|
||||
}
|
||||
|
||||
const lunrjs = require('lunr');
|
||||
|
||||
function makeIndex(posts) {
|
||||
return lunrjs(function() {
|
||||
this.ref('title');
|
||||
this.field('title');
|
||||
this.field('content');
|
||||
this.field('tags');
|
||||
posts.forEach(p => {
|
||||
this.add(p);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function run(contentDirs) {
|
||||
const posts = await Promise.all(contentDirs.map(async (dir) => {
|
||||
return await loadPostsWithFrontMatter(dir)
|
||||
}))
|
||||
return makeIndex(posts.flat());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildIndex: run
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
const { buildIndex } = require('../../src/lunr/index-builder')
|
||||
|
||||
let result = null
|
||||
|
||||
beforeEach(async () => {
|
||||
result = await buildIndex([
|
||||
`${__dirname}/postsstub1`,
|
||||
`${__dirname}/postsstub2`])
|
||||
})
|
||||
|
||||
test('lunr inverted index stuffed with loads of goodies from both dirs', async() => {
|
||||
expect(result.invertedIndex.cool).not.toBe(undefined)
|
||||
expect(result.invertedIndex.gravediggaz).not.toBe(undefined)
|
||||
expect(result.invertedIndex.wu).not.toBe(undefined)
|
||||
expect(result.invertedIndex.tang).not.toBe(undefined)
|
||||
expect(result.invertedIndex.east).not.toBe(undefined)
|
||||
expect(result.invertedIndex.side).not.toBe(undefined)
|
||||
})
|
||||
|
||||
test('lunr index builder fields are title, content, tags', async () => {
|
||||
// Do not forget to add JSON.Stringify() when calling this in production
|
||||
expect(result.fields).toEqual(["title", "content", "tags"])
|
||||
})
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
---
|
||||
title: some cool article
|
||||
date: 2021-03-02
|
||||
---
|
||||
|
||||
Hi gayz whas goin' on gravediggaz style!
|
||||
|
||||
kkthxxbbye
|
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
title: another cool article east-side
|
||||
date: 2021-03-03
|
||||
---
|
||||
|
||||
It's just a hobby that I picked up in the lobby
|
||||
|
||||
---
|
||||
|
||||
The W, Wu-tang Clan yoo
|
|
@ -3216,7 +3216,6 @@ fsevents@^2.1.2:
|
|||
howlongtobeat: ^1.5.1
|
||||
imagemagick: ^0.1.3
|
||||
jest: ^26.6.3
|
||||
lunr: ^2.3.9
|
||||
mockdate: ^3.0.2
|
||||
parser-front-matter: ^1.6.4
|
||||
youtube-dl-exec: ^1.2.4
|
||||
|
@ -3929,13 +3928,6 @@ fsevents@^2.1.2:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lunr@npm:^2.3.9":
|
||||
version: 2.3.9
|
||||
resolution: "lunr@npm:2.3.9"
|
||||
checksum: a2b66320c2f6632322b91c43621eed9e623c0f1b81e7c2d74c238884a02229698baa4478bd238e9b32d7abf0db5ae9233b311c28e1edbcc481774e1ce83bec6f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"make-dir@npm:^3.0.0":
|
||||
version: 3.1.0
|
||||
resolution: "make-dir@npm:3.1.0"
|
||||
|
|
Loading…
Reference in New Issue