Skip to content

Commit

Permalink
Local flexsearch (#160)
Browse files Browse the repository at this point in the history
* Switch to using local search
* Switch from lunr to FlexSearch
* Cache searchindex in localstorage
* Link unresolved links to 404 page in build step
  • Loading branch information
oleeskild authored May 23, 2023
1 parent 2899392 commit 48b7162
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 242 deletions.
12 changes: 9 additions & 3 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ module.exports = function (eleventyConfig) {

eleventyConfig.setLibrary("md", markdownLib);

eleventyConfig.addFilter("isoDate", function (date) {
return date && date.toISOString();
});


eleventyConfig.addFilter("link", function (str) {
return (
str &&
Expand Down Expand Up @@ -240,9 +245,10 @@ module.exports = function (eleventyConfig) {
deadLink = true;
}

return `<a class="internal-link ${
deadLink ? "is-unresolved" : ""
}" ${deadLink ? "" : 'data-note-icon="' + noteIcon + '"'} href="${permalink}${headerLinkPath}">${title}</a>`;
if(deadLink){
return `<a class="internal-link is-unresolved" href="/404">${title}</a>`;
}
return `<a class="internal-link data-note-icon="${noteIcon}" href="${permalink}${headerLinkPath}">${title}</a>`;
})
);
});
Expand Down
11 changes: 0 additions & 11 deletions api/search.js

This file was deleted.

49 changes: 0 additions & 49 deletions netlify/functions/search/search.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"build:eleventy": "cross-env ELEVENTY_ENV=prod NODE_OPTIONS=--max-old-space-size=4096 eleventy",
"build:sass": "sass src/site/styles:dist/styles --style compressed",
"get-theme": "node src/site/get-theme.js",
"build": "npm-run-all get-theme build:*",
"postbuild": "node src/site/lunr-index.js"
"build": "npm-run-all get-theme build:*"
},
"keywords": [],
"author": "",
Expand Down
20 changes: 11 additions & 9 deletions plugin-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"src/site/styles/style.css",
"src/site/index.njk",
"src/site/index.11tydata.js",
"src/site/_data/filetree.js"
"src/site/_data/filetree.js",
"api/search.js",
"netlify/functions/search/search.js",
"src/site/versionednote.njk",
"src/site/_includes/layouts/versionednote.njk",
"src/site/lunr-index.js",
"src/site/_data/versionednotes.js",
"src/site/lunr.njk"

],
"filesToAdd": [
"src/site/styles/custom-style.scss",
Expand All @@ -27,15 +35,13 @@
"src/site/404.njk",
"src/site/sitemap.njk",
"src/site/feed.njk",
"src/site/versionednote.njk",
"src/site/styles/style.scss",
"src/site/styles/digital-garden-base.scss",
"src/site/styles/obsidian-base.scss",
"src/site/notes/notes.json",
"src/site/notes/notes.11tydata.js",
"src/site/_includes/layouts/note.njk",
"src/site/_includes/layouts/index.njk",
"src/site/_includes/layouts/versionednote.njk",
"src/site/_includes/components/notegrowthhistory.njk",
"src/site/_includes/components/pageheader.njk",
"src/site/_includes/components/linkPreview.njk",
Expand All @@ -51,20 +57,16 @@
"src/site/_includes/components/calloutScript.njk",
"src/site/_includes/components/lucideIcons.njk",
"src/site/_includes/components/timestamps.njk",
"src/site/lunr-index.js",
"src/site/lunr.njk",
"src/site/_data/versionednotes.js",
"src/site/_data/meta.js",
"src/site/_data/dynamics.js",
"src/site/img/outgoing.svg",
"src/helpers/constants.js",
"src/helpers/utils.js",
"src/helpers/filetreeUtils.js",
"src/helpers/linkUtils.js",
"netlify/functions/search/search.js",
"src/site/get-theme.js",
"api/search.js",
"src/site/_data/eleventyComputed.js",
"src/site/graph.njk"
"src/site/graph.njk",
"src/site/search-index.njk"
]
}
2 changes: 1 addition & 1 deletion src/site/_data/eleventyComputed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const { userComputed } = require("../../helpers/userUtils");
module.exports = {
graph: (data) => getGraph(data),
filetree: (data) => getFileTree(data),
userComputed: (data) => userComputed(data),
userComputed: (data) => userComputed(data)
};
5 changes: 3 additions & 2 deletions src/site/_data/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
const crypto = require("crypto");
const { globSync } = require("glob");

module.exports = async () => {
module.exports = async (data) => {
let baseUrl = process.env.SITE_BASE_URL || "";
if (baseUrl && !baseUrl.startsWith("http")) {
baseUrl = "https://" + baseUrl;
Expand Down Expand Up @@ -67,7 +67,8 @@ module.exports = async () => {
baseTheme: process.env.BASE_THEME || "dark",
siteName: process.env.SITE_NAME_HEADER || "Digital Garden",
siteBaseUrl: baseUrl,
styleSettingsCss
styleSettingsCss,
buildDate: new Date(),
};

return meta;
Expand Down
66 changes: 0 additions & 66 deletions src/site/_data/versionednotes.js

This file was deleted.

Loading

0 comments on commit 48b7162

Please sign in to comment.