Skip to content

Commit 13d8a86

Browse files
authored
Merge pull request #203 from replayio/filip/dev-495-docs-structure-does-not-play-well-with-search-and-breadcumbs
add keyword search capabilities
2 parents 25c6098 + a6e260c commit 13d8a86

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/app/basics/test-suites/pr-comments/page.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Pull Request Comments
3+
keywords: PR, PR Comments, GitHub
34
description: Pull Request Comments show updated results of your test run with links to replays and the Test Suite Dashboard, all from the pull request in GitHub.
45
image: /images/pr-comment.png
56
---

src/markdoc/search.mjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ export default function withSearch(nextConfig = {}) {
6060
let md = fs.readFileSync(path.join(pagesDir, file), 'utf8')
6161

6262
let sections
63+
let ast = Markdoc.parse(md)
64+
let keywords =
65+
ast.attributes?.frontmatter
66+
?.match(/^keywords:\s*(.*?)\s*$/m)?.[1]
67+
.split(/,\s+/) || []
6368

6469
if (cache.get(file)?.[0] === md) {
6570
sections = cache.get(file)[1]
6671
} else {
67-
let ast = Markdoc.parse(md)
6872
let title =
6973
ast.attributes?.frontmatter?.match(
7074
/^title:\s*(.*?)\s*$/m,
@@ -74,7 +78,7 @@ export default function withSearch(nextConfig = {}) {
7478
cache.set(file, [md, sections])
7579
}
7680

77-
return { url, sections }
81+
return { url, sections, keywords }
7882
})
7983

8084
// When this file is imported within the application
@@ -87,7 +91,7 @@ export default function withSearch(nextConfig = {}) {
8791
document: {
8892
id: 'url',
8993
index: 'content',
90-
store: ['title', 'pageTitle'],
94+
store: ['title', 'pageTitle', 'keywords'],
9195
},
9296
context: {
9397
resolution: 9,
@@ -98,12 +102,12 @@ export default function withSearch(nextConfig = {}) {
98102
99103
let data = ${JSON.stringify(data)}
100104
101-
for (let { url, sections } of data) {
105+
for (let { url, sections, keywords } of data) {
102106
for (let [title, hash, content] of sections) {
103107
sectionIndex.add({
104108
url: url + (hash ? ('#' + hash) : ''),
105109
title,
106-
content: [title, ...content].join('\\n'),
110+
content: [title, ...keywords, ...content ].join('\\n'),
107111
pageTitle: hash ? sections[0][0] : undefined,
108112
})
109113
}

0 commit comments

Comments
 (0)