From 3330492b6c1343695e2258a600a83bc17a5ac6e7 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Wed, 27 Mar 2024 00:42:31 +0800 Subject: [PATCH 01/16] Add initial plugin --- packages/core/src/plugins/pageFind.ts | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/core/src/plugins/pageFind.ts diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts new file mode 100644 index 0000000000..be9debe32b --- /dev/null +++ b/packages/core/src/plugins/pageFind.ts @@ -0,0 +1,44 @@ +import cheerio from 'cheerio'; +import { FrontMatter, PluginContext } from './Plugin'; + +const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/+esm'; +const DEFAULT_UI_ADDRESS = 'https://cdn.jsdelivr.net/npm/@pagefind/default-ui@1.0.4/+esm'; + +const initPagefind = ` + `; + +function addPagefindUI(pluginContext: PluginContext) { + return ``; +} + +export = { + postRender: (_pluginContext: PluginContext, _frontmatter: FrontMatter, content: string) => { + const $ = cheerio.load(content); + $('searchbar').replaceWith(addPagefindUI(_pluginContext)); + const updatedContent = $.html(); + + return updatedContent; + }, + getScripts: () => [initPagefind], +}; From 6cbda193c78ffdeaa33666d8c330eed193ed9dbb Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Wed, 27 Mar 2024 17:00:47 +0800 Subject: [PATCH 02/16] Add test --- packages/cli/test/functional/testSites.js | 1 + packages/core/src/plugins/pageFind.ts | 33 +++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/cli/test/functional/testSites.js b/packages/cli/test/functional/testSites.js index 4db3aa6c80..a0c34afa06 100644 --- a/packages/cli/test/functional/testSites.js +++ b/packages/cli/test/functional/testSites.js @@ -2,6 +2,7 @@ const testSites = [ 'test_site', 'test_site_algolia_plugin', 'test_site_special_tags', + 'test_site_pagefind', ]; const testConvertSites = [ diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index be9debe32b..d562f6a4bc 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -1,8 +1,8 @@ import cheerio from 'cheerio'; -import { FrontMatter, PluginContext } from './Plugin'; +import { PluginContext } from './Plugin'; +import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/+esm'; -const DEFAULT_UI_ADDRESS = 'https://cdn.jsdelivr.net/npm/@pagefind/default-ui@1.0.4/+esm'; const initPagefind = ` `; function addPagefindUI(pluginContext: PluginContext) { - return ` + + `; } export = { - postRender: (_pluginContext: PluginContext, _frontmatter: FrontMatter, content: string) => { - const $ = cheerio.load(content); - $('searchbar').replaceWith(addPagefindUI(_pluginContext)); - const updatedContent = $.html(); - - return updatedContent; + processNode: (pluginContext: PluginContext, node: MbNode) => { + const $ = cheerio.load(node); + $('header').append(addPagefindUI(pluginContext)); }, getScripts: () => [initPagefind], }; From 8371395abb22827b194ce381a08dde8acf5ace63 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Wed, 27 Mar 2024 17:12:38 +0800 Subject: [PATCH 03/16] Fix plugin --- .../functional/test_site_pagefind/.gitignore | 23 +++ .../test/functional/test_site_pagefind/404.md | 7 + .../_markbind/layouts/404.md | 1 + .../_markbind/layouts/default.md | 55 +++++++ .../_markbind/variables.json | 3 + .../test_site_pagefind/_markbind/variables.md | 4 + .../test_site_pagefind/contents/topic1.md | 9 ++ .../test_site_pagefind/contents/topic2.md | 9 ++ .../test_site_pagefind/contents/topic3a.md | 9 ++ .../test_site_pagefind/contents/topic3b.md | 9 ++ .../functional/test_site_pagefind/index.md | 77 ++++++++++ .../functional/test_site_pagefind/site.json | 31 ++++ .../test_site_pagefind/stylesheets/main.css | 135 ++++++++++++++++++ packages/core/src/plugins/pageFind.ts | 5 +- 14 files changed, 374 insertions(+), 3 deletions(-) create mode 100644 packages/cli/test/functional/test_site_pagefind/.gitignore create mode 100644 packages/cli/test/functional/test_site_pagefind/404.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.json create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic1.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic2.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3a.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3b.md create mode 100755 packages/cli/test/functional/test_site_pagefind/index.md create mode 100755 packages/cli/test/functional/test_site_pagefind/site.json create mode 100644 packages/cli/test/functional/test_site_pagefind/stylesheets/main.css diff --git a/packages/cli/test/functional/test_site_pagefind/.gitignore b/packages/cli/test/functional/test_site_pagefind/.gitignore new file mode 100644 index 0000000000..3b8cd63a6d --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/.gitignore @@ -0,0 +1,23 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +_markbind/logs/ + +# Dependency directories +node_modules/ + +# Production +_site/ + +# Env +.env +.env.local + +# IDE configs +.vscode/ +.idea/* +*.iml diff --git a/packages/cli/test/functional/test_site_pagefind/404.md b/packages/cli/test/functional/test_site_pagefind/404.md new file mode 100644 index 0000000000..019786884d --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/404.md @@ -0,0 +1,7 @@ + + title: Page not found + layout: 404.md + + +->

404

<- +->

File not found
Click here to go back to the home page.

<- \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md new file mode 100644 index 0000000000..f5e54988e8 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md @@ -0,0 +1 @@ +
{{ content }}
\ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md new file mode 100644 index 0000000000..2507ae479e --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md @@ -0,0 +1,55 @@ + + + + +
+ + Your Logo +
  • Topic 1
  • +
  • Topic 2
  • + +
  • Topic 3a
  • +
  • Topic 3b
  • +
    +
  • + +
  • +
    +
    + +
    + +
    + + {{ content }} +
    + + +
    + +
    + +
    + [Generated by {{MarkBind}}] +
    +
    diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json new file mode 100644 index 0000000000..04d0b977d3 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json @@ -0,0 +1,3 @@ +{ + "jsonVariableExample": "Your variables can be defined here as well" +} \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md new file mode 100644 index 0000000000..4a19d29999 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md @@ -0,0 +1,4 @@ + +To inject this HTML segment in your MarkBind files, use {{ example }} where you want to place it. +More generally, surround the segment's id with double curly braces. + \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic1.md b/packages/cli/test/functional/test_site_pagefind/contents/topic1.md new file mode 100644 index 0000000000..3f28f03594 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic1.md @@ -0,0 +1,9 @@ + + title: Topic 1 + + +
    + +# Topic 1 + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic2.md b/packages/cli/test/functional/test_site_pagefind/contents/topic2.md new file mode 100644 index 0000000000..f86f7be568 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic2.md @@ -0,0 +1,9 @@ + + title: Topic 2 + + +
    + +# Topic 2 + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md new file mode 100644 index 0000000000..90194da60a --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md @@ -0,0 +1,9 @@ + + title: Topic 3a + + +
    + +# Topic 3a + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md new file mode 100644 index 0000000000..db7ba8e857 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md @@ -0,0 +1,9 @@ + + title: Topic 3b + + +
    + +# Topic 3b + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/index.md b/packages/cli/test/functional/test_site_pagefind/index.md new file mode 100755 index 0000000000..09177b769c --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/index.md @@ -0,0 +1,77 @@ + + title: Home Page + layout: default.md + pageNav: 4 + pageNavTitle: "Topics" + + +
    + +
    +
    +

    Great!
    You've just initialized a MarkBind site.

    +

    Let's get started...

    +
    +
    + +--- + +## What just happened? + +You have just initialized a _default_ MarkBind site! It is equipped with a set of core features, including site and page navigation. Additionally, we have included some convenient links to our User Guide, to help you get started quickly and easily. + + + +If you were intending to convert an existing GitHub wiki or a docs folder into MarkBind, use the `--convert` flag instead. See User Guide: MarkBind in the Project Workflow for more information. + +If you want to start with a _minimal_ template instead, use the `--template` flag with the "minimal" option to initialize a minimal site instead of the default. See User Guide: Templates for more information. + + + +--- + +## Navigating this site + +This _default_ site comes pre-configured with the core Navigation components: a **siteNav**, a **pageNav**, a **NavBar**, and a **Search Bar**. To help you get started with the **siteNav**, we have included five dummy placeholder pages. The **NavBar** also comes with a placeholder slot for your custom Logo. + +--- + +## Guide to MarkBind + +To see the capability of MarkBind in action, feel free to take a look at some of the websites built using MarkBind on our Showcase page. + +For more information on how to work with MarkBind sites and to add content, refer to our comprehensive User Guide. + + + +If you are interested in contributing to MarkBind, you can refer to our Developer Guide as well! + + + + + +##### **User Guide: Authoring Contents** + +> Learn about the variety of syntax schemes, formats, and custom MarkBind components that you can use in your MarkBind site. + +More info in: _User Guide → Authoring Contents_ + +--- + +##### **User Guide: Working with Sites** + +> Learn how to modify site properties, apply themes, and enable/disable plugins for your MarkBind site. + +More info in: _User Guide → Working with Sites_ + +--- + +##### **User Guide: Full Syntax Reference** + +> Refer to our Full Syntax Reference page to find a specific feature or component that you want to use in your MarkBind site. + +More info in: _User Guide → Full Syntax Reference_ + + + +--- diff --git a/packages/cli/test/functional/test_site_pagefind/site.json b/packages/cli/test/functional/test_site_pagefind/site.json new file mode 100755 index 0000000000..d9488eaf31 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/site.json @@ -0,0 +1,31 @@ +{ + "baseUrl": "", + "titlePrefix": "", + "titleSuffix": "", + "ignore": [ + "_markbind/layouts/*", + "_markbind/logs/*", + "_site/*", + "site.json", + "*.md", + "*.njk", + ".git/*", + ".gitignore", + "node_modules/*" + ], + "pagesExclude": ["node_modules/*"], + "pages": [ + { + "src": "index.md" + }, + { + "glob": ["**/index.md", "**/*.md"] + } + ], + "deploy": { + "message": "Site Update." + }, + "plugins" : [ + "pagefind" + ] +} diff --git a/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css b/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css new file mode 100644 index 0000000000..a380ffd4c2 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css @@ -0,0 +1,135 @@ +mark { + background-color: #ff0; + border-radius: 5px; + padding-top: 0; + padding-bottom: 0; +} + +.indented { + padding-left: 20px; +} + +.theme-card img { + width: 100%; +} + +/* Scrollbar */ + +.slim-scroll::-webkit-scrollbar { + width: 5px; +} + +.slim-scroll::-webkit-scrollbar-thumb { + background: #808080; + border-radius: 20px; +} + +.slim-scroll::-webkit-scrollbar-track { + background: transparent; + border-radius: 20px; +} + +.slim-scroll-blue::-webkit-scrollbar { + width: 5px; +} + +.slim-scroll-blue::-webkit-scrollbar-thumb { + background: #00b0ef; + border-radius: 20px; +} + +.slim-scroll-blue::-webkit-scrollbar-track { + background: transparent; + border-radius: 20px; +} + +/* Layout containers */ + +#flex-body { + display: flex; + flex: 1; + align-items: start; +} + +#content-wrapper { + flex: 1; + margin: 0 auto; + min-width: 0; + max-width: 1000px; + overflow-x: auto; + padding: 0.8rem 20px 0; + transition: 0.4s; +} + +#site-nav, +#page-nav { + display: flex; + flex-direction: column; + position: sticky; + top: var(--sticky-header-height); + flex: 0 0 auto; + max-width: 300px; + max-height: calc(100vh - var(--sticky-header-height)); + width: 300px; +} + +#site-nav { + border-right: 1px solid lightgrey; + padding-bottom: 20px; + z-index: 999; +} + +.site-nav-top { + margin: 0.8rem 0; + padding: 0 12px 12px; +} + +.nav-component { + overflow-y: auto; +} + +#page-nav { + border-left: 1px solid lightgrey; +} + +@media screen and (width <= 1299.98px) { + #page-nav { + display: none; + } +} + +/* Bootstrap medium(md) responsive breakpoint */ +@media screen and (width <= 991.98px) { + #site-nav { + display: none; + } +} + +/* Bootstrap small(sm) responsive breakpoint */ +@media (width <= 767.98px) { + .indented { + padding-left: 10px; + } + + #content-wrapper { + padding: 0 10px; + } +} + +/* Bootstrap extra small(xs) responsive breakpoint */ +@media screen and (width <= 575.98px) { + #site-nav { + display: none; + } +} + +/* Hide site navigation when printing */ +@media print { + #site-nav { + display: none; + } + + #page-nav { + display: none; + } +} diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index d562f6a4bc..17a9c02634 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -2,11 +2,10 @@ import cheerio from 'cheerio'; import { PluginContext } from './Plugin'; import { MbNode } from '../utils/node'; -const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/+esm'; +const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; const initPagefind = ` - `; +`; function addPagefindUI(pluginContext: PluginContext) { return ` - - - - + +`; + }); +`; } export = { @@ -38,5 +43,8 @@ export = { const $ = cheerio.load(node); $('header').append(addPagefindUI(pluginContext)); }, - getScripts: () => [initPagefind], + getScripts: () => [ + ``, + initPagefind, + ], }; From f06a25d383ed8f3f30a370e8ff249176ac98b084 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Wed, 27 Mar 2024 22:23:45 +0800 Subject: [PATCH 05/16] Update code --- packages/core/src/plugins/pageFind.ts | 35 ++++++++++----------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index 00b0271320..1f19d4f42a 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -4,32 +4,26 @@ import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; -const initPagefind = ` -`; + await index.addDirectory({ path: '_site' }); + await index.writeFiles({ outputPath: '_site/pagefind' }).then(() => { pagefind.close(); }); +} function addPagefindUI(pluginContext: PluginContext) { return ` - - + + `, - initPagefind, - ], + postRender: () => { initPagefind(); }, }; From abac73f1e7c65c2788fb9ffb83bbe8d6bc8cb2f5 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Wed, 27 Mar 2024 22:39:42 +0800 Subject: [PATCH 06/16] Update code --- packages/core/src/plugins/pageFind.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index 1f19d4f42a..5c2f82cd05 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -4,7 +4,9 @@ import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; -async function initPagefind() { +const initPagefind = ` +; +`; function addPagefindUI(pluginContext: PluginContext) { return ` @@ -37,5 +39,5 @@ export = { const $ = cheerio.load(node); $('header').append(addPagefindUI(pluginContext)); }, - postRender: () => { initPagefind(); }, + getScripts: () => [initPagefind], }; From c3453b13f00b0ec57c32a77df36ca9c7383c017e Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Thu, 28 Mar 2024 01:25:45 +0800 Subject: [PATCH 07/16] Update plugin and test --- packages/core/src/plugins/pageFind.ts | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index 5c2f82cd05..79e1333e6f 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -4,20 +4,21 @@ import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; -const initPagefind = ` -; -`; +function initPagefind() { + return `; + `; +} -function addPagefindUI(pluginContext: PluginContext) { +function addPagefindUI() { return ` @@ -28,7 +29,6 @@ function addPagefindUI(pluginContext: PluginContext) { element: "#search-testtesttest", showSubResults: true, showImages: false, - baseUrl: "${pluginContext.baseUrl}", }); }); `; @@ -37,7 +37,7 @@ function addPagefindUI(pluginContext: PluginContext) { export = { processNode: (pluginContext: PluginContext, node: MbNode) => { const $ = cheerio.load(node); - $('header').append(addPagefindUI(pluginContext)); + $('header').append(addPagefindUI()); }, - getScripts: () => [initPagefind], + getScripts: () => [initPagefind()], }; From 09e893493f5147582660a5af241ef91d17597d9c Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Thu, 28 Mar 2024 01:27:29 +0800 Subject: [PATCH 08/16] Remove old tests --- packages/cli/test/functional/testSites.js | 1 - .../functional/test_site_pagefind/.gitignore | 23 --- .../test/functional/test_site_pagefind/404.md | 7 - .../_markbind/layouts/404.md | 1 - .../_markbind/layouts/default.md | 55 ------- .../_markbind/variables.json | 3 - .../test_site_pagefind/_markbind/variables.md | 4 - .../test_site_pagefind/contents/topic1.md | 9 -- .../test_site_pagefind/contents/topic2.md | 9 -- .../test_site_pagefind/contents/topic3a.md | 9 -- .../test_site_pagefind/contents/topic3b.md | 9 -- .../functional/test_site_pagefind/index.md | 77 ---------- .../functional/test_site_pagefind/site.json | 31 ---- .../test_site_pagefind/stylesheets/main.css | 135 ------------------ 14 files changed, 373 deletions(-) delete mode 100644 packages/cli/test/functional/test_site_pagefind/.gitignore delete mode 100644 packages/cli/test/functional/test_site_pagefind/404.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.json delete mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic1.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic2.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3a.md delete mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3b.md delete mode 100755 packages/cli/test/functional/test_site_pagefind/index.md delete mode 100755 packages/cli/test/functional/test_site_pagefind/site.json delete mode 100644 packages/cli/test/functional/test_site_pagefind/stylesheets/main.css diff --git a/packages/cli/test/functional/testSites.js b/packages/cli/test/functional/testSites.js index a0c34afa06..4db3aa6c80 100644 --- a/packages/cli/test/functional/testSites.js +++ b/packages/cli/test/functional/testSites.js @@ -2,7 +2,6 @@ const testSites = [ 'test_site', 'test_site_algolia_plugin', 'test_site_special_tags', - 'test_site_pagefind', ]; const testConvertSites = [ diff --git a/packages/cli/test/functional/test_site_pagefind/.gitignore b/packages/cli/test/functional/test_site_pagefind/.gitignore deleted file mode 100644 index 3b8cd63a6d..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -_markbind/logs/ - -# Dependency directories -node_modules/ - -# Production -_site/ - -# Env -.env -.env.local - -# IDE configs -.vscode/ -.idea/* -*.iml diff --git a/packages/cli/test/functional/test_site_pagefind/404.md b/packages/cli/test/functional/test_site_pagefind/404.md deleted file mode 100644 index 019786884d..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/404.md +++ /dev/null @@ -1,7 +0,0 @@ - - title: Page not found - layout: 404.md - - -->

    404

    <- -->

    File not found
    Click here to go back to the home page.

    <- \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md deleted file mode 100644 index f5e54988e8..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md +++ /dev/null @@ -1 +0,0 @@ -
    {{ content }}
    \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md deleted file mode 100644 index 2507ae479e..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md +++ /dev/null @@ -1,55 +0,0 @@ - - - - -
    - - Your Logo -
  • Topic 1
  • -
  • Topic 2
  • - -
  • Topic 3a
  • -
  • Topic 3b
  • -
    -
  • - -
  • -
    -
    - -
    - -
    - - {{ content }} -
    - - -
    - -
    - -
    - [Generated by {{MarkBind}}] -
    -
    diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json deleted file mode 100644 index 04d0b977d3..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "jsonVariableExample": "Your variables can be defined here as well" -} \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md deleted file mode 100644 index 4a19d29999..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md +++ /dev/null @@ -1,4 +0,0 @@ - -To inject this HTML segment in your MarkBind files, use {{ example }} where you want to place it. -More generally, surround the segment's id with double curly braces. - \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic1.md b/packages/cli/test/functional/test_site_pagefind/contents/topic1.md deleted file mode 100644 index 3f28f03594..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/contents/topic1.md +++ /dev/null @@ -1,9 +0,0 @@ - - title: Topic 1 - - -
    - -# Topic 1 - -> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic2.md b/packages/cli/test/functional/test_site_pagefind/contents/topic2.md deleted file mode 100644 index f86f7be568..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/contents/topic2.md +++ /dev/null @@ -1,9 +0,0 @@ - - title: Topic 2 - - -
    - -# Topic 2 - -> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md deleted file mode 100644 index 90194da60a..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md +++ /dev/null @@ -1,9 +0,0 @@ - - title: Topic 3a - - -
    - -# Topic 3a - -> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md deleted file mode 100644 index db7ba8e857..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md +++ /dev/null @@ -1,9 +0,0 @@ - - title: Topic 3b - - -
    - -# Topic 3b - -> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/index.md b/packages/cli/test/functional/test_site_pagefind/index.md deleted file mode 100755 index 09177b769c..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/index.md +++ /dev/null @@ -1,77 +0,0 @@ - - title: Home Page - layout: default.md - pageNav: 4 - pageNavTitle: "Topics" - - -
    - -
    -
    -

    Great!
    You've just initialized a MarkBind site.

    -

    Let's get started...

    -
    -
    - ---- - -## What just happened? - -You have just initialized a _default_ MarkBind site! It is equipped with a set of core features, including site and page navigation. Additionally, we have included some convenient links to our User Guide, to help you get started quickly and easily. - - - -If you were intending to convert an existing GitHub wiki or a docs folder into MarkBind, use the `--convert` flag instead. See User Guide: MarkBind in the Project Workflow for more information. - -If you want to start with a _minimal_ template instead, use the `--template` flag with the "minimal" option to initialize a minimal site instead of the default. See User Guide: Templates for more information. - - - ---- - -## Navigating this site - -This _default_ site comes pre-configured with the core Navigation components: a **siteNav**, a **pageNav**, a **NavBar**, and a **Search Bar**. To help you get started with the **siteNav**, we have included five dummy placeholder pages. The **NavBar** also comes with a placeholder slot for your custom Logo. - ---- - -## Guide to MarkBind - -To see the capability of MarkBind in action, feel free to take a look at some of the websites built using MarkBind on our Showcase page. - -For more information on how to work with MarkBind sites and to add content, refer to our comprehensive User Guide. - - - -If you are interested in contributing to MarkBind, you can refer to our Developer Guide as well! - - - - - -##### **User Guide: Authoring Contents** - -> Learn about the variety of syntax schemes, formats, and custom MarkBind components that you can use in your MarkBind site. - -More info in: _User Guide → Authoring Contents_ - ---- - -##### **User Guide: Working with Sites** - -> Learn how to modify site properties, apply themes, and enable/disable plugins for your MarkBind site. - -More info in: _User Guide → Working with Sites_ - ---- - -##### **User Guide: Full Syntax Reference** - -> Refer to our Full Syntax Reference page to find a specific feature or component that you want to use in your MarkBind site. - -More info in: _User Guide → Full Syntax Reference_ - - - ---- diff --git a/packages/cli/test/functional/test_site_pagefind/site.json b/packages/cli/test/functional/test_site_pagefind/site.json deleted file mode 100755 index d9488eaf31..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/site.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "baseUrl": "", - "titlePrefix": "", - "titleSuffix": "", - "ignore": [ - "_markbind/layouts/*", - "_markbind/logs/*", - "_site/*", - "site.json", - "*.md", - "*.njk", - ".git/*", - ".gitignore", - "node_modules/*" - ], - "pagesExclude": ["node_modules/*"], - "pages": [ - { - "src": "index.md" - }, - { - "glob": ["**/index.md", "**/*.md"] - } - ], - "deploy": { - "message": "Site Update." - }, - "plugins" : [ - "pagefind" - ] -} diff --git a/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css b/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css deleted file mode 100644 index a380ffd4c2..0000000000 --- a/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css +++ /dev/null @@ -1,135 +0,0 @@ -mark { - background-color: #ff0; - border-radius: 5px; - padding-top: 0; - padding-bottom: 0; -} - -.indented { - padding-left: 20px; -} - -.theme-card img { - width: 100%; -} - -/* Scrollbar */ - -.slim-scroll::-webkit-scrollbar { - width: 5px; -} - -.slim-scroll::-webkit-scrollbar-thumb { - background: #808080; - border-radius: 20px; -} - -.slim-scroll::-webkit-scrollbar-track { - background: transparent; - border-radius: 20px; -} - -.slim-scroll-blue::-webkit-scrollbar { - width: 5px; -} - -.slim-scroll-blue::-webkit-scrollbar-thumb { - background: #00b0ef; - border-radius: 20px; -} - -.slim-scroll-blue::-webkit-scrollbar-track { - background: transparent; - border-radius: 20px; -} - -/* Layout containers */ - -#flex-body { - display: flex; - flex: 1; - align-items: start; -} - -#content-wrapper { - flex: 1; - margin: 0 auto; - min-width: 0; - max-width: 1000px; - overflow-x: auto; - padding: 0.8rem 20px 0; - transition: 0.4s; -} - -#site-nav, -#page-nav { - display: flex; - flex-direction: column; - position: sticky; - top: var(--sticky-header-height); - flex: 0 0 auto; - max-width: 300px; - max-height: calc(100vh - var(--sticky-header-height)); - width: 300px; -} - -#site-nav { - border-right: 1px solid lightgrey; - padding-bottom: 20px; - z-index: 999; -} - -.site-nav-top { - margin: 0.8rem 0; - padding: 0 12px 12px; -} - -.nav-component { - overflow-y: auto; -} - -#page-nav { - border-left: 1px solid lightgrey; -} - -@media screen and (width <= 1299.98px) { - #page-nav { - display: none; - } -} - -/* Bootstrap medium(md) responsive breakpoint */ -@media screen and (width <= 991.98px) { - #site-nav { - display: none; - } -} - -/* Bootstrap small(sm) responsive breakpoint */ -@media (width <= 767.98px) { - .indented { - padding-left: 10px; - } - - #content-wrapper { - padding: 0 10px; - } -} - -/* Bootstrap extra small(xs) responsive breakpoint */ -@media screen and (width <= 575.98px) { - #site-nav { - display: none; - } -} - -/* Hide site navigation when printing */ -@media print { - #site-nav { - display: none; - } - - #page-nav { - display: none; - } -} From d8e49369806fb7a67370a7511431d767ef53920f Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Fri, 29 Mar 2024 22:35:18 +0800 Subject: [PATCH 09/16] Add pagefind as dependency --- package-lock.json | 119 ++++++++++++++++++++++++++ packages/cli/package.json | 1 + packages/cli/src/cmd/build.js | 10 +++ packages/core/package.json | 1 + packages/core/src/plugins/pageFind.ts | 9 +- 5 files changed, 135 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index bccc9dff01..087203bd7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4713,6 +4713,66 @@ "@octokit/openapi-types": "^16.0.0" } }, + "node_modules/@pagefind/darwin-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.0.4.tgz", + "integrity": "sha512-2OcthvceX2xhm5XbgOmW+lT45oLuHqCmvFeFtxh1gsuP5cO8vcD8ZH8Laj4pXQFCcK6eAdSShx+Ztx/LsQWZFQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@pagefind/darwin-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-x64/-/darwin-x64-1.0.4.tgz", + "integrity": "sha512-xkdvp0D9Ld/ZKsjo/y1bgfhTEU72ITimd2PMMQtts7jf6JPIOJbsiErCvm37m/qMFuPGEq/8d+fZ4pydOj08HQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@pagefind/linux-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.0.4.tgz", + "integrity": "sha512-jGBrcCzIrMnNxLKVtogaQyajVfTAXM59KlBEwg6vTn8NW4fQ6nuFbbhlG4dTIsaamjEM5e8ZBEAKZfTB/qd9xw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@pagefind/linux-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/linux-x64/-/linux-x64-1.0.4.tgz", + "integrity": "sha512-LIn/QcvcEtLEBqKe5vpSbSC2O3fvqbRCWOTIklslqSORisCsvzsWbP6j+LYxE9q0oWIfkdMoWV1vrE/oCKRxHg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@pagefind/windows-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/windows-x64/-/windows-x64-1.0.4.tgz", + "integrity": "sha512-QlBCVeZfj9fc9sbUgdOz76ZDbeK4xZihOBAFqGuRJeChfM8pnVeH9iqSnXgO3+m9oITugTf7PicyRUFAG76xeQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@parcel/watcher": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.0.4.tgz", @@ -17829,6 +17889,21 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, + "node_modules/pagefind": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/pagefind/-/pagefind-1.0.4.tgz", + "integrity": "sha512-oRIizYe+zSI2Jw4zcMU0ebDZm27751hRFiSOBLwc1OIYMrsZKk+3m8p9EVaOmc6zZdtqwwdilNUNxXvBeHcP9w==", + "bin": { + "pagefind": "lib/runner/bin.cjs" + }, + "optionalDependencies": { + "@pagefind/darwin-arm64": "1.0.4", + "@pagefind/darwin-x64": "1.0.4", + "@pagefind/linux-arm64": "1.0.4", + "@pagefind/linux-x64": "1.0.4", + "@pagefind/windows-x64": "1.0.4" + } + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -23886,6 +23961,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", @@ -26604,6 +26680,7 @@ "memfs": "^3.0.1", "moment": "^2.29.4", "nunjucks": "3.2.4", + "pagefind": "^1.0.4", "path-is-inside": "^1.0.2", "simple-git": "^3.22.0", "ts-jest": "^27.1.4", @@ -27885,6 +27962,36 @@ "@octokit/openapi-types": "^16.0.0" } }, + "@pagefind/darwin-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-arm64/-/darwin-arm64-1.0.4.tgz", + "integrity": "sha512-2OcthvceX2xhm5XbgOmW+lT45oLuHqCmvFeFtxh1gsuP5cO8vcD8ZH8Laj4pXQFCcK6eAdSShx+Ztx/LsQWZFQ==", + "optional": true + }, + "@pagefind/darwin-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/darwin-x64/-/darwin-x64-1.0.4.tgz", + "integrity": "sha512-xkdvp0D9Ld/ZKsjo/y1bgfhTEU72ITimd2PMMQtts7jf6JPIOJbsiErCvm37m/qMFuPGEq/8d+fZ4pydOj08HQ==", + "optional": true + }, + "@pagefind/linux-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/linux-arm64/-/linux-arm64-1.0.4.tgz", + "integrity": "sha512-jGBrcCzIrMnNxLKVtogaQyajVfTAXM59KlBEwg6vTn8NW4fQ6nuFbbhlG4dTIsaamjEM5e8ZBEAKZfTB/qd9xw==", + "optional": true + }, + "@pagefind/linux-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/linux-x64/-/linux-x64-1.0.4.tgz", + "integrity": "sha512-LIn/QcvcEtLEBqKe5vpSbSC2O3fvqbRCWOTIklslqSORisCsvzsWbP6j+LYxE9q0oWIfkdMoWV1vrE/oCKRxHg==", + "optional": true + }, + "@pagefind/windows-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@pagefind/windows-x64/-/windows-x64-1.0.4.tgz", + "integrity": "sha512-QlBCVeZfj9fc9sbUgdOz76ZDbeK4xZihOBAFqGuRJeChfM8pnVeH9iqSnXgO3+m9oITugTf7PicyRUFAG76xeQ==", + "optional": true + }, "@parcel/watcher": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.0.4.tgz", @@ -38077,6 +38184,18 @@ } } }, + "pagefind": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/pagefind/-/pagefind-1.0.4.tgz", + "integrity": "sha512-oRIizYe+zSI2Jw4zcMU0ebDZm27751hRFiSOBLwc1OIYMrsZKk+3m8p9EVaOmc6zZdtqwwdilNUNxXvBeHcP9w==", + "requires": { + "@pagefind/darwin-arm64": "1.0.4", + "@pagefind/darwin-x64": "1.0.4", + "@pagefind/linux-arm64": "1.0.4", + "@pagefind/linux-x64": "1.0.4", + "@pagefind/windows-x64": "1.0.4" + } + }, "parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", diff --git a/packages/cli/package.json b/packages/cli/package.json index d21ffb2175..cb5735151a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -38,6 +38,7 @@ "fs-extra": "^9.0.1", "live-server": "1.2.1", "lodash": "^4.17.15", + "pagefind": "^1.0.4", "url-parse": "^1.5.10", "winston": "^2.4.4", "winston-daily-rotate-file": "^3.10.0" diff --git a/packages/cli/src/cmd/build.js b/packages/cli/src/cmd/build.js index 6c73ac863d..0acbccb648 100755 --- a/packages/cli/src/cmd/build.js +++ b/packages/cli/src/cmd/build.js @@ -2,6 +2,7 @@ const path = require('path'); const { Site } = require('@markbind/core').Site; +const pagefind = require('pagefind'); const cliUtil = require('../util/cliUtil'); const logger = require('../util/logger'); @@ -26,6 +27,15 @@ function build(userSpecifiedRoot, output, options) { .generate(baseUrl) .then(() => { logger.info('Build success!'); + // Start Pagefind indexing after successful site generation + logger.info('Starting Pagefind indexing...'); + const { index } = pagefind.createIndex({ + keepIndexUrl: true, + verbose: true, + }) + .then(() => index.addDirectory({ path: outputFolder })) + .then(() => index.writeFiles({ outputPath: path.join(outputFolder, 'pagefind') })) + .then(() => pagefind.close()); }) .catch((error) => { logger.error(error.message); diff --git a/packages/core/package.json b/packages/core/package.json index 85029823b9..d4ecf20d8c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -63,6 +63,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", diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index 79e1333e6f..d7d74caa51 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -3,11 +3,10 @@ import { PluginContext } from './Plugin'; import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; +const DEFAULT_UI = 'https://cdn.jsdelivr.net/npm/@pagefind/default-ui@1.0.4/+esm'; function initPagefind() { - return `; - `, initPagefind()], }; From 44fe0e0db0c6e440f3b53ac700c39d833042266a Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Fri, 29 Mar 2024 22:38:13 +0800 Subject: [PATCH 10/16] Add pagefind as dependency --- package-lock.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index 087203bd7d..160c17a73d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23892,6 +23892,7 @@ "fs-extra": "^9.0.1", "live-server": "1.2.1", "lodash": "^4.17.15", + "pagefind": "^1.0.4", "url-parse": "^1.5.10", "winston": "^2.4.4", "winston-daily-rotate-file": "^3.10.0" @@ -36114,6 +36115,7 @@ "live-server": "1.2.1", "lodash": "^4.17.15", "memfs": "^3.0.1", + "pagefind": "^1.0.4", "url-parse": "^1.5.10", "walk-sync": "^2.0.2", "winston": "^2.4.4", From 106a5cd84945611c42e611d08fc5fe343b8c4b3e Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Sat, 30 Mar 2024 00:36:17 +0800 Subject: [PATCH 11/16] Modify build process --- packages/cli/src/cmd/build.js | 10 -- .../functional/test_site_pagefind/.gitignore | 23 +++ .../test/functional/test_site_pagefind/404.md | 7 + .../_markbind/layouts/404.md | 1 + .../_markbind/layouts/default.md | 55 +++++++ .../_markbind/variables.json | 3 + .../test_site_pagefind/_markbind/variables.md | 4 + .../test_site_pagefind/contents/topic1.md | 9 ++ .../test_site_pagefind/contents/topic2.md | 9 ++ .../test_site_pagefind/contents/topic3a.md | 9 ++ .../test_site_pagefind/contents/topic3b.md | 9 ++ .../functional/test_site_pagefind/index.md | 77 ++++++++++ .../functional/test_site_pagefind/site.json | 28 ++++ .../test_site_pagefind/stylesheets/main.css | 135 ++++++++++++++++++ packages/core/src/Site/index.ts | 19 +++ packages/core/src/plugins/pageFind.ts | 15 +- 16 files changed, 390 insertions(+), 23 deletions(-) create mode 100644 packages/cli/test/functional/test_site_pagefind/.gitignore create mode 100644 packages/cli/test/functional/test_site_pagefind/404.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.json create mode 100644 packages/cli/test/functional/test_site_pagefind/_markbind/variables.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic1.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic2.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3a.md create mode 100644 packages/cli/test/functional/test_site_pagefind/contents/topic3b.md create mode 100755 packages/cli/test/functional/test_site_pagefind/index.md create mode 100755 packages/cli/test/functional/test_site_pagefind/site.json create mode 100644 packages/cli/test/functional/test_site_pagefind/stylesheets/main.css diff --git a/packages/cli/src/cmd/build.js b/packages/cli/src/cmd/build.js index 0acbccb648..6c73ac863d 100755 --- a/packages/cli/src/cmd/build.js +++ b/packages/cli/src/cmd/build.js @@ -2,7 +2,6 @@ const path = require('path'); const { Site } = require('@markbind/core').Site; -const pagefind = require('pagefind'); const cliUtil = require('../util/cliUtil'); const logger = require('../util/logger'); @@ -27,15 +26,6 @@ function build(userSpecifiedRoot, output, options) { .generate(baseUrl) .then(() => { logger.info('Build success!'); - // Start Pagefind indexing after successful site generation - logger.info('Starting Pagefind indexing...'); - const { index } = pagefind.createIndex({ - keepIndexUrl: true, - verbose: true, - }) - .then(() => index.addDirectory({ path: outputFolder })) - .then(() => index.writeFiles({ outputPath: path.join(outputFolder, 'pagefind') })) - .then(() => pagefind.close()); }) .catch((error) => { logger.error(error.message); diff --git a/packages/cli/test/functional/test_site_pagefind/.gitignore b/packages/cli/test/functional/test_site_pagefind/.gitignore new file mode 100644 index 0000000000..3b8cd63a6d --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/.gitignore @@ -0,0 +1,23 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +_markbind/logs/ + +# Dependency directories +node_modules/ + +# Production +_site/ + +# Env +.env +.env.local + +# IDE configs +.vscode/ +.idea/* +*.iml diff --git a/packages/cli/test/functional/test_site_pagefind/404.md b/packages/cli/test/functional/test_site_pagefind/404.md new file mode 100644 index 0000000000..019786884d --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/404.md @@ -0,0 +1,7 @@ + + title: Page not found + layout: 404.md + + +->

    404

    <- +->

    File not found
    Click here to go back to the home page.

    <- \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md new file mode 100644 index 0000000000..f5e54988e8 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/404.md @@ -0,0 +1 @@ +
    {{ content }}
    \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md new file mode 100644 index 0000000000..2507ae479e --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/layouts/default.md @@ -0,0 +1,55 @@ + + + + +
    + + Your Logo +
  • Topic 1
  • +
  • Topic 2
  • + +
  • Topic 3a
  • +
  • Topic 3b
  • +
    +
  • + +
  • +
    +
    + +
    + +
    + + {{ content }} +
    + + +
    + +
    + +
    + [Generated by {{MarkBind}}] +
    +
    diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json new file mode 100644 index 0000000000..04d0b977d3 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.json @@ -0,0 +1,3 @@ +{ + "jsonVariableExample": "Your variables can be defined here as well" +} \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md new file mode 100644 index 0000000000..4a19d29999 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/_markbind/variables.md @@ -0,0 +1,4 @@ + +To inject this HTML segment in your MarkBind files, use {{ example }} where you want to place it. +More generally, surround the segment's id with double curly braces. + \ No newline at end of file diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic1.md b/packages/cli/test/functional/test_site_pagefind/contents/topic1.md new file mode 100644 index 0000000000..3f28f03594 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic1.md @@ -0,0 +1,9 @@ + + title: Topic 1 + + +
    + +# Topic 1 + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic2.md b/packages/cli/test/functional/test_site_pagefind/contents/topic2.md new file mode 100644 index 0000000000..f86f7be568 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic2.md @@ -0,0 +1,9 @@ + + title: Topic 2 + + +
    + +# Topic 2 + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md new file mode 100644 index 0000000000..90194da60a --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic3a.md @@ -0,0 +1,9 @@ + + title: Topic 3a + + +
    + +# Topic 3a + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md b/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md new file mode 100644 index 0000000000..db7ba8e857 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/contents/topic3b.md @@ -0,0 +1,9 @@ + + title: Topic 3b + + +
    + +# Topic 3b + +> This is a placeholder page - more content to be added. diff --git a/packages/cli/test/functional/test_site_pagefind/index.md b/packages/cli/test/functional/test_site_pagefind/index.md new file mode 100755 index 0000000000..09177b769c --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/index.md @@ -0,0 +1,77 @@ + + title: Home Page + layout: default.md + pageNav: 4 + pageNavTitle: "Topics" + + +
    + +
    +
    +

    Great!
    You've just initialized a MarkBind site.

    +

    Let's get started...

    +
    +
    + +--- + +## What just happened? + +You have just initialized a _default_ MarkBind site! It is equipped with a set of core features, including site and page navigation. Additionally, we have included some convenient links to our User Guide, to help you get started quickly and easily. + + + +If you were intending to convert an existing GitHub wiki or a docs folder into MarkBind, use the `--convert` flag instead. See User Guide: MarkBind in the Project Workflow for more information. + +If you want to start with a _minimal_ template instead, use the `--template` flag with the "minimal" option to initialize a minimal site instead of the default. See User Guide: Templates for more information. + + + +--- + +## Navigating this site + +This _default_ site comes pre-configured with the core Navigation components: a **siteNav**, a **pageNav**, a **NavBar**, and a **Search Bar**. To help you get started with the **siteNav**, we have included five dummy placeholder pages. The **NavBar** also comes with a placeholder slot for your custom Logo. + +--- + +## Guide to MarkBind + +To see the capability of MarkBind in action, feel free to take a look at some of the websites built using MarkBind on our Showcase page. + +For more information on how to work with MarkBind sites and to add content, refer to our comprehensive User Guide. + + + +If you are interested in contributing to MarkBind, you can refer to our Developer Guide as well! + + + + + +##### **User Guide: Authoring Contents** + +> Learn about the variety of syntax schemes, formats, and custom MarkBind components that you can use in your MarkBind site. + +More info in: _User Guide → Authoring Contents_ + +--- + +##### **User Guide: Working with Sites** + +> Learn how to modify site properties, apply themes, and enable/disable plugins for your MarkBind site. + +More info in: _User Guide → Working with Sites_ + +--- + +##### **User Guide: Full Syntax Reference** + +> Refer to our Full Syntax Reference page to find a specific feature or component that you want to use in your MarkBind site. + +More info in: _User Guide → Full Syntax Reference_ + + + +--- diff --git a/packages/cli/test/functional/test_site_pagefind/site.json b/packages/cli/test/functional/test_site_pagefind/site.json new file mode 100755 index 0000000000..eb1d757851 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/site.json @@ -0,0 +1,28 @@ +{ + "baseUrl": "", + "titlePrefix": "", + "titleSuffix": "", + "ignore": [ + "_markbind/layouts/*", + "_markbind/logs/*", + "_site/*", + "site.json", + "*.md", + "*.njk", + ".git/*", + ".gitignore", + "node_modules/*" + ], + "pagesExclude": ["node_modules/*"], + "pages": [ + { + "src": "index.md" + }, + { + "glob": ["**/index.md", "**/*.md"] + } + ], + "deploy": { + "message": "Site Update." + } +} diff --git a/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css b/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css new file mode 100644 index 0000000000..a380ffd4c2 --- /dev/null +++ b/packages/cli/test/functional/test_site_pagefind/stylesheets/main.css @@ -0,0 +1,135 @@ +mark { + background-color: #ff0; + border-radius: 5px; + padding-top: 0; + padding-bottom: 0; +} + +.indented { + padding-left: 20px; +} + +.theme-card img { + width: 100%; +} + +/* Scrollbar */ + +.slim-scroll::-webkit-scrollbar { + width: 5px; +} + +.slim-scroll::-webkit-scrollbar-thumb { + background: #808080; + border-radius: 20px; +} + +.slim-scroll::-webkit-scrollbar-track { + background: transparent; + border-radius: 20px; +} + +.slim-scroll-blue::-webkit-scrollbar { + width: 5px; +} + +.slim-scroll-blue::-webkit-scrollbar-thumb { + background: #00b0ef; + border-radius: 20px; +} + +.slim-scroll-blue::-webkit-scrollbar-track { + background: transparent; + border-radius: 20px; +} + +/* Layout containers */ + +#flex-body { + display: flex; + flex: 1; + align-items: start; +} + +#content-wrapper { + flex: 1; + margin: 0 auto; + min-width: 0; + max-width: 1000px; + overflow-x: auto; + padding: 0.8rem 20px 0; + transition: 0.4s; +} + +#site-nav, +#page-nav { + display: flex; + flex-direction: column; + position: sticky; + top: var(--sticky-header-height); + flex: 0 0 auto; + max-width: 300px; + max-height: calc(100vh - var(--sticky-header-height)); + width: 300px; +} + +#site-nav { + border-right: 1px solid lightgrey; + padding-bottom: 20px; + z-index: 999; +} + +.site-nav-top { + margin: 0.8rem 0; + padding: 0 12px 12px; +} + +.nav-component { + overflow-y: auto; +} + +#page-nav { + border-left: 1px solid lightgrey; +} + +@media screen and (width <= 1299.98px) { + #page-nav { + display: none; + } +} + +/* Bootstrap medium(md) responsive breakpoint */ +@media screen and (width <= 991.98px) { + #site-nav { + display: none; + } +} + +/* Bootstrap small(sm) responsive breakpoint */ +@media (width <= 767.98px) { + .indented { + padding-left: 10px; + } + + #content-wrapper { + padding: 0 10px; + } +} + +/* Bootstrap extra small(xs) responsive breakpoint */ +@media screen and (width <= 575.98px) { + #site-nav { + display: none; + } +} + +/* Hide site navigation when printing */ +@media print { + #site-nav { + display: none; + } + + #page-nav { + display: none; + } +} diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 3b36f615fc..bd1cd5d1e1 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -6,6 +6,7 @@ import walkSync from 'walk-sync'; import simpleGit, { SimpleGit } from 'simple-git'; import Bluebird from 'bluebird'; import ghpages from 'gh-pages'; +import pagefind from 'pagefind'; import { Template as NunjucksTemplate } from 'nunjucks'; import { SiteConfig, SiteConfigPage, SiteConfigStyle } from './SiteConfig'; @@ -527,6 +528,7 @@ export class Site { await this.copyOcticonsAsset(); await this.copyMaterialIconsAsset(); await this.writeSiteData(); + await this.indexSiteWithPagefind(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { this.backgroundBuildNotViewedFiles(); @@ -567,6 +569,23 @@ export class Site { } } + /** + * Indexes all the pages of the site using pagefind + */ + async indexSiteWithPagefind() { + const newIndex = await pagefind.createIndex({ + keepIndexUrl: true, + verbose: true, + logfile: 'debug.log', + }); + const { index } = newIndex; + if (index) { + await index.addDirectory({ path: this.outputPath }); + await index.writeFiles({ outputPath: path.join(this.outputPath, 'pagefind') }); + } + await pagefind.close(); + } + /** * Adds all pages except the viewed pages to toRebuild, flagging them for lazy building later. */ diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index d7d74caa51..c5090e08f0 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -1,22 +1,11 @@ import cheerio from 'cheerio'; + import { PluginContext } from './Plugin'; import { MbNode } from '../utils/node'; const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; const DEFAULT_UI = 'https://cdn.jsdelivr.net/npm/@pagefind/default-ui@1.0.4/+esm'; -function initPagefind() { - return ``; -} - function addPagefindUI() { return ` @@ -38,5 +27,5 @@ export = { const $ = cheerio.load(node); $('header').append(addPagefindUI()); }, - getScripts: () => [``, initPagefind()], + getScripts: () => [``], }; From a64819a524318aef9945b98792f9aca7c61b18a4 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Sat, 30 Mar 2024 00:47:11 +0800 Subject: [PATCH 12/16] Change pagefind import --- packages/core/src/Site/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index bd1cd5d1e1..8586f51fd9 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -6,7 +6,6 @@ import walkSync from 'walk-sync'; import simpleGit, { SimpleGit } from 'simple-git'; import Bluebird from 'bluebird'; import ghpages from 'gh-pages'; -import pagefind from 'pagefind'; import { Template as NunjucksTemplate } from 'nunjucks'; import { SiteConfig, SiteConfigPage, SiteConfigStyle } from './SiteConfig'; @@ -573,7 +572,8 @@ export class Site { * Indexes all the pages of the site using pagefind */ async indexSiteWithPagefind() { - const newIndex = await pagefind.createIndex({ + const { createIndex, close } = await import('pagefind'); + const newIndex = await createIndex({ keepIndexUrl: true, verbose: true, logfile: 'debug.log', @@ -581,9 +581,9 @@ export class Site { const { index } = newIndex; if (index) { await index.addDirectory({ path: this.outputPath }); - await index.writeFiles({ outputPath: path.join(this.outputPath, 'pagefind') }); + await index.writeFiles({ outputPath: `${this.outputPath}/pagefind` }); } - await pagefind.close(); + await close(); } /** From a0c301c819abf4a5fc538f8e5020119a77cf50ff Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Sat, 30 Mar 2024 22:56:43 +0800 Subject: [PATCH 13/16] Remove index.ts changes --- packages/core/src/Site/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 8586f51fd9..cdca14c371 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -527,7 +527,7 @@ export class Site { await this.copyOcticonsAsset(); await this.copyMaterialIconsAsset(); await this.writeSiteData(); - await this.indexSiteWithPagefind(); + // await this.indexSiteWithPagefind(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { this.backgroundBuildNotViewedFiles(); @@ -570,7 +570,6 @@ export class Site { /** * Indexes all the pages of the site using pagefind - */ async indexSiteWithPagefind() { const { createIndex, close } = await import('pagefind'); const newIndex = await createIndex({ @@ -584,7 +583,7 @@ export class Site { await index.writeFiles({ outputPath: `${this.outputPath}/pagefind` }); } await close(); - } + } */ /** * Adds all pages except the viewed pages to toRebuild, flagging them for lazy building later. From 5e9fc0347d36e47793d30560eadc43af525290e3 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Thu, 11 Apr 2024 18:24:12 +0800 Subject: [PATCH 14/16] Eslint ignore import --- packages/core/src/Site/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 216f98f82d..329628afd6 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -572,8 +572,9 @@ export class Site { /** * Indexes all the pages of the site using pagefind + */ async indexSiteWithPagefind() { - const { createIndex, close } = await import('pagefind'); + const { createIndex, close } = await import('pagefind'); //eslint-disable-line const newIndex = await createIndex({ keepIndexUrl: true, verbose: true, @@ -585,7 +586,7 @@ export class Site { await index.writeFiles({ outputPath: `${this.outputPath}/pagefind` }); } await close(); - } */ + } /** * Adds all pages except the viewed pages to toRebuild, flagging them for lazy building later. From 8ee05e7640889b10bd251f614a0315dd39f0bde6 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Fri, 12 Apr 2024 18:22:15 +0800 Subject: [PATCH 15/16] change build process --- packages/core/src/Site/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 329628afd6..9fc79468a3 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -529,7 +529,7 @@ export class Site { await this.copyOcticonsAsset(); await this.copyMaterialIconsAsset(); await this.writeSiteData(); - // await this.indexSiteWithPagefind(); + await this.indexSiteWithPagefind(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { this.backgroundBuildNotViewedFiles(); From 0725d76b7cdebc2ab9fba695c39955b64220a871 Mon Sep 17 00:00:00 2001 From: jingting1412 Date: Mon, 15 Apr 2024 13:05:17 +0800 Subject: [PATCH 16/16] Update implementation --- packages/core/src/Site/index.ts | 5 ++--- packages/core/src/plugins/pageFind.ts | 13 +++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 9fc79468a3..6ee9d3e06b 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -529,7 +529,7 @@ export class Site { await this.copyOcticonsAsset(); await this.copyMaterialIconsAsset(); await this.writeSiteData(); - await this.indexSiteWithPagefind(); + // await this.indexSiteWithPagefind(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { this.backgroundBuildNotViewedFiles(); @@ -572,7 +572,6 @@ export class Site { /** * Indexes all the pages of the site using pagefind - */ async indexSiteWithPagefind() { const { createIndex, close } = await import('pagefind'); //eslint-disable-line const newIndex = await createIndex({ @@ -586,7 +585,7 @@ export class Site { await index.writeFiles({ outputPath: `${this.outputPath}/pagefind` }); } await close(); - } + } */ /** * Adds all pages except the viewed pages to toRebuild, flagging them for lazy building later. diff --git a/packages/core/src/plugins/pageFind.ts b/packages/core/src/plugins/pageFind.ts index c5090e08f0..eeaebbfff2 100644 --- a/packages/core/src/plugins/pageFind.ts +++ b/packages/core/src/plugins/pageFind.ts @@ -1,9 +1,6 @@ import cheerio from 'cheerio'; - import { PluginContext } from './Plugin'; -import { MbNode } from '../utils/node'; -const DEFAULT_CDN_ADDRESS = 'https://cdn.jsdelivr.net/npm/pagefind@1.0.4/lib/index.min.js'; const DEFAULT_UI = 'https://cdn.jsdelivr.net/npm/@pagefind/default-ui@1.0.4/+esm'; function addPagefindUI() { @@ -23,9 +20,13 @@ function addPagefindUI() { } export = { - processNode: (pluginContext: PluginContext, node: MbNode) => { - const $ = cheerio.load(node); + tagConfig: { + pagefind: { + isSpecial: true, + }, + }, + postRender: (pluginContext: PluginContext, content: string) => { + const $ = cheerio.load(content); $('header').append(addPagefindUI()); }, - getScripts: () => [``], };