Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PageFind Plugin (Re-PR) #2568

Draft
wants to merge 42 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3330492
Add initial plugin
jingting1412 Mar 26, 2024
6cbda19
Add test
jingting1412 Mar 27, 2024
8371395
Fix plugin
jingting1412 Mar 27, 2024
f302eca
Update plugin
jingting1412 Mar 27, 2024
f06a25d
Update code
jingting1412 Mar 27, 2024
abac73f
Update code
jingting1412 Mar 27, 2024
c3453b1
Update plugin and test
jingting1412 Mar 27, 2024
09e8934
Remove old tests
jingting1412 Mar 27, 2024
d8e4936
Add pagefind as dependency
jingting1412 Mar 29, 2024
44fe0e0
Add pagefind as dependency
jingting1412 Mar 29, 2024
974795c
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Mar 29, 2024
db737a4
Merge branch 'addFullSearch' of https://github.com/jingting1412/markb…
jingting1412 Mar 29, 2024
106a5cd
Modify build process
jingting1412 Mar 29, 2024
a64819a
Change pagefind import
jingting1412 Mar 29, 2024
88489ba
Merge branch 'master' into addFullSearch
jingting1412 Mar 29, 2024
c198553
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Mar 30, 2024
106ca72
Merge branch 'addFullSearch' of https://github.com/jingting1412/markb…
jingting1412 Mar 30, 2024
a0c301c
Remove index.ts changes
jingting1412 Mar 30, 2024
b4f6d6c
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Apr 8, 2024
99d9ae2
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Apr 11, 2024
b15c6a5
Merge branch 'addFullSearch' of https://github.com/jingting1412/markb…
jingting1412 Apr 11, 2024
5e9fc03
Eslint ignore import
jingting1412 Apr 11, 2024
916b44e
Merge branch 'master' into addFullSearch
kaixin-hc Apr 12, 2024
caafbc5
Merge branch 'addFullSearch' of https://github.com/jingting1412/markb…
jingting1412 Apr 12, 2024
8ee05e7
change build process
jingting1412 Apr 12, 2024
6088950
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Apr 12, 2024
c618c38
Merge branch 'MarkBind:master' into addFullSearch
jingting1412 Apr 15, 2024
0725d76
Update implementation
jingting1412 Apr 15, 2024
fe5407e
Merge branch 'addFullSearch' of https://github.com/jingting1412/markb…
jingting1412 Apr 15, 2024
625d23c
Merge branch 'MarkBind:master' into branch-addFullSearch
gerteck Jul 9, 2024
6531589
Merge branch 'MarkBind:master' into branch-addFullSearch
gerteck Jul 15, 2024
ff25a59
Update TypeScript config
gerteck Jul 15, 2024
6eb05fe
Enable Pagefind
gerteck Jul 15, 2024
10fe379
Merge branch 'branch-addFullSearch' of https://github.com/gerteck/mar…
gerteck Jul 15, 2024
c7babfc
Add pageFind assets
gerteck Jul 15, 2024
c715402
Update pagefind plugin
gerteck Jul 15, 2024
6b37e6c
Add css styling
gerteck Jul 15, 2024
9779bfc
Add indexing logic, update vue searchbar
gerteck Aug 1, 2024
8633721
Merge branch 'master' into branch-addFullSearch
gerteck Aug 10, 2024
105ea59
Update comments
gerteck Aug 12, 2024
4a795b5
Remove unused test files
gerteck Aug 12, 2024
fa24c9c
Remove misplaced dependency
gerteck Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"material-icons": "^1.9.1",
"moment": "^2.29.4",
"nunjucks": "3.2.4",
"pagefind": "^1.0.4",
"path-is-inside": "^1.0.2",
"simple-git": "^3.22.0",
"url-parse": "^1.5.10",
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/Site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ export class Site {
await this.copyOcticonsAsset();
await this.copyMaterialIconsAsset();
await this.writeSiteData();
if (this.siteConfig.plugins.includes('pagefind')) {
await this.indexSiteWithPagefind();
}
this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString);
if (this.backgroundBuildMode) {
this.backgroundBuildNotViewedFiles();
Expand Down Expand Up @@ -569,6 +572,25 @@ export class Site {
}
}

/**
* Indexes all the pages of the site using pagefind for pagefind plugin.
*/
async indexSiteWithPagefind() {
logger.info('Creating Pagefind Search Index');
const { createIndex, close } = await import('pagefind');
const newIndex = await createIndex({
keepIndexUrl: true,
verbose: true,
logfile: 'debug.log',
});
const { index } = newIndex;
if (index) {
await index.addDirectory({ path: this.outputPath });
await index.writeFiles({ outputPath: `${this.outputPath}/pagefind` });
}
await close();
}

/**
* Adds all pages except the viewed pages to toRebuild, flagging them for lazy building later.
*/
Expand Down
43 changes: 43 additions & 0 deletions packages/core/src/plugins/pageFind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// import cheerio from 'cheerio';
// import { PluginContext, FrontMatter } from './Plugin';
// todo: find a way to import the UI and Script from the working directory.
// const DEFAULT_UI = 'https://cdn.jsdelivr.net/npm/@pagefind/[email protected]/+esm';

const JS_FILE_NAME = 'pageFindAssets/pagefind-ui.min.js';
const CSS_FILE_NAME = 'pageFindAssets/pagefind-ui.min.css';
const ADDTIONAL_CSS_FILE_NAME = 'pageFindAssets/pagefind-ui-additional.css';
const PAGEFIND_INPUT_SELECTOR = '#pagefind-search-input';

/**
* Generates the script to initialize the PageFind UI
*/
function genScript() {
return `
<script>
window.addEventListener('DOMContentLoaded', (event) => {
const searchContainers = document.querySelectorAll('${PAGEFIND_INPUT_SELECTOR}');
if (searchContainers.length) {
searchContainers.forEach((container) => {
new window.PagefindUI({
element: container,
showSubResults: true,
showImages: false,
});
});
}
});
</script>`;
}

export = {
tagConfig: {
pagefind: {
isSpecial: true,
},
},
getScripts: () => [`<script src="${JS_FILE_NAME}"></script>`, genScript()],
getLinks: () => [
`<link rel="stylesheet" href="${CSS_FILE_NAME}">`,
`<link rel="stylesheet" href="${ADDTIONAL_CSS_FILE_NAME}">`,
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* custom-pagefind-ui.css */

/* General Pagefind UI styling */
:root {
--pagefind-ui-border: #000000; /* Black border color */
--pagefind-ui-border-width: 2px; /* Border width */
--pagefind-ui-border-radius: 8px; /* Border radius */
--pagefind-ui-image-border-radius: 8px; /* Image border radius */
}

/* Additional custom styles for dark mode if needed */
body.dark {
--pagefind-ui-border: #000000; /* Black border color for dark mode */
}
Loading
Loading