Use a more robust slugify function

This commit is contained in:
thiloho
2024-09-13 19:30:56 +02:00
parent db8b284d6f
commit 79d1c9f5c7
6 changed files with 25 additions and 53 deletions

View File

@@ -1,6 +1,6 @@
import { readFile, mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { type WebsiteOverview } from "$lib/utils";
import { type WebsiteOverview, slugify } from "$lib/utils";
import type { Actions, PageServerLoad } from "./$types";
import { API_BASE_PREFIX } from "$lib/server/utils";
import { render } from "svelte/server";
@@ -122,8 +122,6 @@ const generateStaticFiles = async (websiteData: WebsiteOverview, isPreview: bool
});
for (const article of websiteData.article ?? []) {
const articleFileName = article.title.toLowerCase().split(" ").join("-");
const { head, body } = render(websiteData.content_type === "Blog" ? BlogArticle : DocsArticle, {
props: {
websiteOverview: websiteData,
@@ -133,7 +131,7 @@ const generateStaticFiles = async (websiteData: WebsiteOverview, isPreview: bool
});
await writeFile(
join(uploadDir, "articles", `${articleFileName}.html`),
join(uploadDir, "articles", `${slugify(article.title)}.html`),
fileContents(head, body)
);
}