diff --git a/core/docz-core/src/lib/Entries.ts b/core/docz-core/src/lib/Entries.ts index 09bba563e..71b09d05a 100644 --- a/core/docz-core/src/lib/Entries.ts +++ b/core/docz-core/src/lib/Entries.ts @@ -91,7 +91,7 @@ export class Entries { const createEntry = async (file: string) => { try { const ast = await parseMdx(file) - const entry = new Entry(ast, file, src) + const entry = new Entry(ast, file, src, config) if (this.repoEditUrl) entry.setLink(this.repoEditUrl) const { settings, ...rest } = entry diff --git a/core/docz-core/src/lib/Entry.ts b/core/docz-core/src/lib/Entry.ts index c73560e8c..dce5bb7ea 100644 --- a/core/docz-core/src/lib/Entry.ts +++ b/core/docz-core/src/lib/Entry.ts @@ -11,6 +11,8 @@ import { import * as paths from '../config/paths' +import { Config } from './commands/args' + const createId = (file: string) => crypto .createHash('md5') @@ -46,7 +48,7 @@ export class Entry { [key: string]: any } - constructor(ast: any, file: string, src: string) { + constructor(ast: any, file: string, src: string, config: Config) { const filepath = this.getFilepath(file, src) const parsed = getParsedData(ast) const name = this.getName(filepath, parsed) @@ -54,7 +56,7 @@ export class Entry { this.id = createId(file) this.filepath = filepath this.link = null - this.slug = this.slugify(filepath) + this.slug = this.slugify(filepath, config.separator) this.route = this.getRoute(parsed) this.name = name this.order = parsed.order || 0 @@ -85,11 +87,11 @@ export class Entry { return parsed && parsed.name ? parsed.name : filename } - private slugify(filepath: string): string { + private slugify(filepath: string, separator: string): string { const ext = path.extname(filepath) const fileWithoutExt = filepath.replace(ext, '') - return slugify(fileWithoutExt) + return slugify(fileWithoutExt, { separator }) } private getRoute(parsed: any): string { diff --git a/core/docz-core/src/states/config.ts b/core/docz-core/src/states/config.ts index 274c290ba..120bf8ecb 100644 --- a/core/docz-core/src/states/config.ts +++ b/core/docz-core/src/states/config.ts @@ -18,6 +18,7 @@ interface Payload { native: boolean codeSandbox: boolean themeConfig: ThemeConfig + separator: string } const getInitialConfig = (config: Config): Payload => { @@ -34,6 +35,7 @@ const getInitialConfig = (config: Config): Payload => { native: config.native, codeSandbox: config.codeSandbox, themeConfig: config.themeConfig, + separator: config.separator, } } diff --git a/packages/docz-core/src/commands/args.ts b/packages/docz-core/src/commands/args.ts index 14a0b766a..f28ac17d2 100644 --- a/packages/docz-core/src/commands/args.ts +++ b/packages/docz-core/src/commands/args.ts @@ -79,6 +79,8 @@ export interface Argv { hashRouter: boolean wrapper?: string indexHtml?: string + /* slugify separator */ + separator: string } export interface Config extends Argv { @@ -202,4 +204,8 @@ export const args = (env: Env) => (yargs: any) => { type: 'boolean', default: getEnv('docz.sourcemaps') || true, }) + yargs.positional('separator', { + type: 'string', + default: getEnv('docz.separator', '-'), + }) }