mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
Modify slufigy with GithubSlugger
This commit is contained in:
+10
-6
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user