Skip to content

Commit fe8328b

Browse files
Merge pull request #3110 from OctopusDeploy/sf/update-search-json
Update search.json.ts and improve dot-handling
2 parents e2bc141 + f448ac0 commit fe8328b

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

public/docs/js/modules/string.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function sanitise(string) {
5252
string
5353
.trim()
5454
.normalize('NFD')
55+
.replace(/\./g, ' ')
5556
.replace(/[\u0300-\u036f]/g, '')
5657
.toLowerCase()
5758
.replace(/-/g, '');

public/docs/js/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ function initializeSearch() {
593593
}
594594

595595
// Words chained with . are combined, i.e. System.Text is "systemtext"
596-
var s = input.value.replace(/\./g, '');
596+
var s = input.value.replace(/\./g, ' ');
597597

598598
window.clearTimeout(debounceTimer);
599599
debounceTimer = window.setTimeout(function () {

src/pages/docs/search.json.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @format */
2+
13
// warning: This file is overwritten by Astro Accelerator
24

35
import { Accelerator, PostFiltering } from 'astro-accelerator-utils';
@@ -14,9 +16,7 @@ const getData = async () => {
1416
const accelerator = new Accelerator(SITE);
1517

1618
for (const path in allPages) {
17-
const page = (await allPages[path]()) as MarkdownInstance<
18-
Record<string, any>
19-
>;
19+
const page = (await allPages[path]()) as MarkdownInstance<Record<string, any>>;
2020

2121
if (!PostFiltering.showInSearch(page)) {
2222
continue;
@@ -29,14 +29,20 @@ const getData = async () => {
2929
}
3030

3131
const headings = await page.getHeadings();
32-
const title = await accelerator.markdown.getTextFrom(
33-
page.frontmatter.title ?? ''
34-
);
35-
const content = page.compiledContent ? page.compiledContent() : '';
32+
const title = await accelerator.markdown.getTextFrom(page.frontmatter?.title);
33+
const content = page.compiledContent ? await page.compiledContent() : '';
3634
let counted: { word: string; count: number }[] = [];
3735

3836
if (content) {
39-
const text = convert(content, { wordwrap: false });
37+
const options = {
38+
wordwrap: false,
39+
selectors: [
40+
{ selector: 'a', options: { ignoreHref: true } },
41+
{ selector: 'img', format: 'skip' },
42+
{ selector: 'h1', options: { uppercase: false } },
43+
],
44+
};
45+
const text = convert(content, options);
4046

4147
const words = keywordExtractor.extract(text, {
4248
language: 'english',
@@ -45,19 +51,22 @@ const getData = async () => {
4551
});
4652

4753
counted = words
48-
.map((w) => {
49-
return { word: w, count: words.filter((wd) => wd === w).length };
54+
.map(w => {
55+
return {
56+
word: w,
57+
count: words.filter(wd => wd === w).length,
58+
};
5059
})
51-
.filter((e) => e.word.replace(/[^a-z]+/g, '').length > 1);
60+
.filter(e => e.word.replace(/[^a-z]+/g, '').length > 1);
5261
}
5362

5463
items.push({
5564
title: title,
56-
headings: headings.map((h) => {
65+
headings: headings.map(h => {
5766
return { text: h.text, slug: h.slug };
5867
}),
5968
description: page.frontmatter.description ?? '',
60-
keywords: counted.map((c) => c.word).join(' '),
69+
keywords: counted.map(c => c.word).join(' '),
6170
tags: page.frontmatter.tags ?? [],
6271
url: SITE.url + accelerator.urlFormatter.formatAddress(url),
6372
date: page.frontmatter.pubDate ?? '',

0 commit comments

Comments
 (0)