Skip to content

Commit f9e6c88

Browse files
committed
add keyword search capabilities
1 parent 25c6098 commit f9e6c88

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-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

+8-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ 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 = ast.attributes?.frontmatter?.match(
65+
/^keywords:\s*(.*?)\s*$/m,
66+
)?.[1].split(/,\s+/) || []
6367

6468
if (cache.get(file)?.[0] === md) {
6569
sections = cache.get(file)[1]
6670
} else {
67-
let ast = Markdoc.parse(md)
6871
let title =
6972
ast.attributes?.frontmatter?.match(
7073
/^title:\s*(.*?)\s*$/m,
@@ -74,7 +77,7 @@ export default function withSearch(nextConfig = {}) {
7477
cache.set(file, [md, sections])
7578
}
7679

77-
return { url, sections }
80+
return { url, sections, keywords }
7881
})
7982

8083
// When this file is imported within the application
@@ -87,7 +90,7 @@ export default function withSearch(nextConfig = {}) {
8790
document: {
8891
id: 'url',
8992
index: 'content',
90-
store: ['title', 'pageTitle'],
93+
store: ['title', 'pageTitle', 'keywords'],
9194
},
9295
context: {
9396
resolution: 9,
@@ -98,12 +101,12 @@ export default function withSearch(nextConfig = {}) {
98101
99102
let data = ${JSON.stringify(data)}
100103
101-
for (let { url, sections } of data) {
104+
for (let { url, sections, keywords } of data) {
102105
for (let [title, hash, content] of sections) {
103106
sectionIndex.add({
104107
url: url + (hash ? ('#' + hash) : ''),
105108
title,
106-
content: [title, ...content].join('\\n'),
109+
content: [title, ...keywords, ...content ].join('\\n'),
107110
pageTitle: hash ? sections[0][0] : undefined,
108111
})
109112
}

0 commit comments

Comments
 (0)