Skip to content

Commit

Permalink
Add patch to fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
bbhtt committed Jul 15, 2024
1 parent f7570db commit 398c312
Show file tree
Hide file tree
Showing 3 changed files with 3,055 additions and 2,264 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
diff --git a/lib/server/utils/scanDocuments.js b/lib/server/utils/scanDocuments.js
index 6b5d8bfa646c2cdf6be383bdbe46a782c539c10c..97177eae076da24a919dfdfad0f5a55c5d82a71f 100644
--- a/lib/server/utils/scanDocuments.js
+++ b/lib/server/utils/scanDocuments.js
@@ -12,6 +12,17 @@ let nextDocId = 0;
const getNextDocId = () => {
return (nextDocId += 1);
};
+
+function getSlicedHash(hash, url) {
+ if (hash.includes("#") && !hash.startsWith("#")) {
+ if (hash.startsWith(url) && hash[url.length] === "#") {
+ return hash.slice(url.length);
+ }
+ return false;
+ }
+ return hash;
+}
+
async function scanDocuments(DocInfoWithFilePathList) {
const titleDocuments = [];
const headingDocuments = [];
@@ -29,7 +40,12 @@ async function scanDocuments(DocInfoWithFilePathList) {
b: breadcrumb,
});
for (const section of sections) {
+ const slicedHash = getSlicedHash(section.hash, url);
+
if (section.title !== pageTitle) {
+ if (typeof slicedHash === 'boolean' && slicedHash === false) {
+ continue;
+ }
headingDocuments.push({
i: getNextDocId(),
t: section.title,
@@ -39,6 +55,9 @@ async function scanDocuments(DocInfoWithFilePathList) {
});
}
if (section.content) {
+ if (typeof slicedHash === 'boolean' && slicedHash === false) {
+ continue;
+ }
contentDocuments.push({
i: getNextDocId(),
t: section.content,
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@docusaurus/preset-classic": "^3.4.0",
"@mdx-js/react": "^3.0.1",
"clsx": "^2.1.1",
"docusaurus-plugin-search-local": "^2.0.1",
"docusaurus-plugin-search-local": "patch:docusaurus-plugin-search-local@npm%3A2.0.1#./.yarn/patches/docusaurus-plugin-search-local-npm-2.0.1-4a07fbb27a.patch",
"prism-react-renderer": "^2.3.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
Loading

0 comments on commit 398c312

Please sign in to comment.