Modify slufigy with GithubSlugger

This commit is contained in:
Sat Naing
2022-09-25 19:02:18 +06:30
parent e368cb7188
commit 191798217f
+10 -6
View File
@@ -1,9 +1,13 @@
const slugify = (str: string) => import GithubSlugger from "github-slugger";
str import type { Frontmatter } from "src/types";
.toLowerCase()
.replace(/ /g, "-")
.replace(/[^\w-]+/g, "");
export const slufigyAll = (arr: string[]) => arr.map((str) => slugify(str)); const slugger = GithubSlugger.slug;
export const slugifyStr = (str: string) => slugger(str);
const slugify = (frontmatter: Frontmatter) =>
frontmatter.slug ? frontmatter.slug : slugger(frontmatter.title);
export const slufigyAll = (arr: string[]) => arr.map((str) => slugifyStr(str));
export default slugify; export default slugify;