refactor: modify slugger for blog content collection

This commit is contained in:
satnaing
2023-01-26 22:42:15 +06:30
parent 7243d29607
commit e7b93c560f
+3 -3
View File
@@ -1,10 +1,10 @@
import type { CollectionEntry } from "astro:content";
import { slug as slugger } from "github-slugger"; import { slug as slugger } from "github-slugger";
import type { Frontmatter } from "src/types";
export const slugifyStr = (str: string) => slugger(str); export const slugifyStr = (str: string) => slugger(str);
const slugify = (frontmatter: Frontmatter) => const slugify = (post: CollectionEntry<"blog">) =>
frontmatter.slug ? slugger(frontmatter.slug) : slugger(frontmatter.title); post.data.slug ? slugger(post.data.slug) : post.slug;
export const slufigyAll = (arr: string[]) => arr.map(str => slugifyStr(str)); export const slufigyAll = (arr: string[]) => arr.map(str => slugifyStr(str));