hikerpig / gatsby-project-kb

Developing gatsby-theme-kb, a Gatsby theme for publishing Knowledge Base.
https://gatsby-project-kb.vercel.app/
MIT License
62 stars 15 forks source link

CJK characters in slug #46

Closed hikerpig closed 1 year ago

hikerpig commented 2 years ago

Up to gatsby-theme-kb@0.9.2 , I use slugify(fileName) to generate url slug.

But this function will not keep most of the utf-8 characters. For example 认知.md will be an empty string, makes navigation imposibble.

hikerpig commented 2 years ago

From gatsby-theme-kb@0.9.2 , you can customise the slugifyFn during page creation.

I use this in my own wiki.

gatsby-config.js

function mySlugify(str) {
  if (!str) return str
  let out = str.trim().replace(/\s+/g, '-')
  return out
}

module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-theme-kb',
      options: {
        // ...
        slugifyFn: mySlugify,
      },
    },
  ],
}