Skip to content

Commit

Permalink
fix: document route
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 8, 2020
1 parent 53389b4 commit 4dc8969
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions core/core/src/stories-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { Document, defDocType } from './stories';

export const strToId = (str: string) => str.replace(/\W/g, '-').toLowerCase();

export const ensureTrailingSlash = (route: string) =>
route.endsWith('/') ? route : route + '/';

export const ensureStartingSlash = (route: string) =>
route.startsWith('/') ? route : '/' + route;

export const getDocPath = (
docType: DocType,
doc?: Document,
Expand All @@ -14,8 +20,12 @@ export const getDocPath = (
const { basePath = '' } = pagesConfig?.[docType] || {};
const route = doc
? doc.route ||
`/${basePath}${activeTab ? `${activeTab}/` : ''}${strToId(doc.title)}/`
: `/${basePath}${activeTab ? `${activeTab}/` : ''}${strToId(name)}/`;
`${ensureStartingSlash(ensureTrailingSlash(basePath))}${
activeTab ? `${ensureTrailingSlash(activeTab)}` : ''
}${ensureTrailingSlash(strToId(doc.title))}`
: `${ensureStartingSlash(ensureTrailingSlash(basePath))}${
activeTab ? `${ensureTrailingSlash(activeTab)}` : ''
}${ensureTrailingSlash(strToId(name))}`;
return route;
};

Expand All @@ -31,7 +41,11 @@ export const getStoryPath = (
}

const { basePath = '' } = pagesConfig?.[docType] || {};
const route = `/${basePath}${activeTab ? `${activeTab}/` : ''}`;
const route = `${
doc?.route
? ensureStartingSlash(ensureTrailingSlash(doc?.route))
: `${ensureStartingSlash(ensureTrailingSlash(basePath))}`
}${activeTab ? `${ensureTrailingSlash(activeTab)}` : ''}`;
return `${route}${storyId || ''}`;
};

Expand Down

0 comments on commit 4dc8969

Please sign in to comment.