import diacritics from 'diacritics' ; import consola from 'consola' ; import { sep } from 'path' ; import Database from './content/database' ; /**
 * Slugifies a string
 * Borrowed from vuepress, those guys are amazing
 * string.js slugify drops non ascii chars so we have to
 * use a custom implementation here
 */ export const slugify = ( str ) : string => { const rControl = /[\u0000-\u001f]/g ; const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g ; return ( diacritics . remove ( str ) . normalize ( 'NFD' ) . replace ( rControl , '' ) . replace ( rSpecial , '-' ) . replace ( /\-{2,}/g , '-' ) . replace ( /^\-+|\-+$/g , '' ) . replace ( /^(\d)/ , '_$1' ) . toLowerCase ( ) ) ; } ; export const logger = consola . withScope ( 'nuxt:nuxtent' ) ; param { string } routePath returns { string } export const pathToName = ( routePath ) : string => { const firstSlash = /^\// ; return routePath . replace ( firstSlash , '' ) . replace ( sep , '-' ) . replace ( '_' , '' ) ; } ; description param assetMap export function generatePluginMap ( assetMap ) { const webpackAlias = '~/content/' ; const mdComps = [ ] ; for ( const collections of assetMap . values ( ) ) { for ( const page of collections . pagesMap . values ( ) ) { if ( page . meta . fileName . endsWith ( '.comp.md' ) ) { if ( typeof page . body === 'string' ) { logger . error ( 'Content component file should have a relativePath' ) ; } else { const filePath = webpackAlias + page . body . relativePath . substring ( 1 ) ; mdComps . push ( [ page . body . relativePath , filePath ] ) ; } } } } return mdComps ; }