use custom kebabcase function

This commit is contained in:
Timothy 2021-01-16 18:07:08 +08:00
parent 6f90fc50db
commit fdda4c2042
7 changed files with 10 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import Link from 'next/link'
import kebabCase from 'just-kebab-case'
import { kebabCase } from '@/lib/utils'
const Tag = ({ text }) => {
return (

View File

@ -1,7 +1,7 @@
import fs from 'fs'
import matter from 'gray-matter'
import path from 'path'
import kebabCase from 'just-kebab-case'
import { kebabCase } from './utils'
const root = process.cwd()

6
lib/utils.js Normal file
View File

@ -0,0 +1,6 @@
export const kebabCase = (str) =>
str &&
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map((x) => x.toLowerCase())
.join('-')

5
package-lock.json generated
View File

@ -5646,11 +5646,6 @@
"object.assign": "^4.1.2"
}
},
"just-kebab-case": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/just-kebab-case/-/just-kebab-case-1.1.0.tgz",
"integrity": "sha512-QkuwuBMQ9BQHMUEkAtIA4INLrkmnnveqlFB1oFi09gbU0wBdZo6tTnyxNWMR84zHxBuwK7GLAwqN8nrvVxOLTA=="
},
"katex": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/katex/-/katex-0.12.0.tgz",

View File

@ -19,7 +19,6 @@
"autoprefixer": "^10.1.0",
"gray-matter": "^4.0.2",
"image-size": "0.9.3",
"just-kebab-case": "^1.1.0",
"next": "10.0.5",
"next-mdx-remote": "^2.0.0",
"next-seo": "4.17.0",

View File

@ -1,5 +1,5 @@
import kebabCase from 'just-kebab-case'
import siteMetadata from '@/data/siteMetadata'
import { kebabCase } from '@/lib/utils'
import { getAllTags } from '@/lib/tags'
import Tag from '@/components/Tag'
import Link from '@/components/Link'

View File

@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import kebabCase from 'just-kebab-case'
import { kebabCase } from '@/lib/utils'
import { getAllFilesFrontMatter } from '@/lib/mdx'
import { getAllTags } from '@/lib/tags'
import siteMetadata from '@/data/siteMetadata'