Skip to content

Commit 0416918

Browse files
authored
Add stripHtml function and buildSearchMdx function
1 parent 71b5c70 commit 0416918

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

scripts/storage-finder-data-generator/generate.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,32 @@ function slugify(value: string): string {
316316
return trimmed;
317317
}
318318

319+
function stripHtml(value: string | undefined): string {
320+
return (value ?? "")
321+
.replaceAll(/<[^>]+>/g, " ")
322+
.replaceAll(/\s+/g, " ")
323+
.trim();
324+
}
325+
326+
function buildSearchMdx(services: ServiceRecord[]): string {
327+
return [
328+
"# Storage Finder Data",
329+
"",
330+
"This page is generated from the Storage Finder data so the search index can crawl service details.",
331+
"",
332+
...services.map((service) =>
333+
[
334+
`## ${service.title}`,
335+
"",
336+
...Object.values(service.field_data).map((field) =>
337+
[`### ${field.label}`, "", stripHtml(field.value), ""].join("\n"),
338+
),
339+
].join("\n"),
340+
),
341+
"",
342+
].join("\n");
343+
}
344+
319345
async function main(): Promise<void> {
320346
const options = parseArgs(process.argv.slice(2));
321347
if (options.showHelp) {

0 commit comments

Comments
 (0)