Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/storage-finder-data-generator/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,27 @@ async function writeJson(
await writeFile(path, content + "\n", "utf8");
}

function stripHtml(value: string | undefined): string {
return (value ?? "").replaceAll(/<[^>]+>/g, " ").replaceAll(/\s+/g, " ").trim();
}

function buildSearchMdx(services: ServiceRecord[]): string {
return [
"# Storage Finder Data",
"",
"This page is generated from the Storage Finder data so the search index can crawl service details.",
"",
...services.map((service) =>
[
`## ${service.title}`,
"",
...Object.values(service.field_data).map((field) =>
[`### ${field.label}`, "", stripHtml(field.value), ""].join("\n"),
),
].join("\n"),
),
].join("\n");
}
function slugify(value: string): string {
const normalized = value.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-");
const trimmed = normalized.replaceAll(/^-+|-+$/g, "");
Expand Down Expand Up @@ -336,6 +357,11 @@ async function main(): Promise<void> {
const facetOutputPath = `${outputDirectory}/${FACET_TREE_FILENAME}`;
await writeJson(serviceOutputPath, services, options.pretty);
await writeJson(facetOutputPath, facetTree, options.pretty);
await writeFile(
"src/pages/storage-finder-data.mdx",
buildSearchMdx(services),
"utf8",
);
logger.log(`Wrote ${services.length} services to ${serviceOutputPath}`);
logger.log(`Wrote ${facetTree.length} facets to ${facetOutputPath}`);
}
Expand Down
Loading