File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import fs from 'fs/promises'
22import path from 'path'
33import { cache } from 'react'
4- import { slug as githubSlug } from 'github-slugger'
4+ import GithubSlugger from 'github-slugger'
55import matter from 'gray-matter'
66import { compileMDX } from 'next-mdx-remote/rsc'
77import rehypeAutolinkHeadings from 'rehype-autolink-headings'
@@ -33,10 +33,6 @@ async function loadAuthors(): Promise<Record<string, any>> {
3333 return authors
3434}
3535
36- function slugify ( text : string ) : string {
37- return githubSlug ( text )
38- }
39-
4036async function scanFrontmatters ( ) : Promise < BlogMeta [ ] > {
4137 if ( cachedMeta ) {
4238 return cachedMeta
@@ -154,14 +150,16 @@ export async function getPostBySlug(slug: string): Promise<BlogPost> {
154150 } ,
155151 } ,
156152 } )
153+
154+ const slugger = new GithubSlugger ( )
157155 const headings : { text : string ; id : string ; level : number } [ ] = [ ]
158156 const lines = content . split ( '\n' )
159157 for ( const line of lines ) {
160158 const match = / ^ ( # { 2 , 3 } ) \s + ( .+ ) $ / . exec ( line . trim ( ) )
161159 if ( match ) {
162160 const level = match [ 1 ] . length
163161 const text = match [ 2 ] . trim ( )
164- headings . push ( { text, id : slugify ( text ) , level } )
162+ headings . push ( { text, id : slugger . slug ( text ) , level } )
165163 }
166164 }
167165 return {
You can’t perform that action at this time.
0 commit comments