diff --git a/libs/docs-utils/src/kind/enum.ts b/libs/docs-utils/src/kind/enum.ts new file mode 100644 index 0000000000..335bd387a0 --- /dev/null +++ b/libs/docs-utils/src/kind/enum.ts @@ -0,0 +1,6 @@ +export enum DaffDocKind { + GUIDE = 'GUIDE', + EXPLANATION = 'EXPLANATION', + PACKAGE = 'PACKAGE', + API = 'API', +} diff --git a/libs/docs-utils/src/kind/path-segment-map.ts b/libs/docs-utils/src/kind/path-segment-map.ts new file mode 100644 index 0000000000..e0bf809686 --- /dev/null +++ b/libs/docs-utils/src/kind/path-segment-map.ts @@ -0,0 +1,8 @@ +import { DaffDocKind } from './enum'; + +export const DAFF_DOC_KIND_PATH_SEGMENT_MAP = { + [DaffDocKind.GUIDE]: 'guides', + [DaffDocKind.EXPLANATION]: 'explanations', + [DaffDocKind.PACKAGE]: 'packages', + [DaffDocKind.API]: 'api', +}; diff --git a/libs/docs-utils/src/kind/public_api.ts b/libs/docs-utils/src/kind/public_api.ts new file mode 100644 index 0000000000..dc3e8715e5 --- /dev/null +++ b/libs/docs-utils/src/kind/public_api.ts @@ -0,0 +1,2 @@ +export * from './enum'; +export * from './path-segment-map'; diff --git a/libs/docs-utils/src/public_api.ts b/libs/docs-utils/src/public_api.ts index 554895b309..e5c6605a60 100644 --- a/libs/docs-utils/src/public_api.ts +++ b/libs/docs-utils/src/public_api.ts @@ -1 +1,2 @@ export { crossOsFilename } from './cross-os-filename'; +export * from './kind/public_api'; diff --git a/tools/dgeni/src/processors/markdown.ts b/tools/dgeni/src/processors/markdown.ts index f8192cf86b..fea67ce626 100644 --- a/tools/dgeni/src/processors/markdown.ts +++ b/tools/dgeni/src/processors/markdown.ts @@ -12,6 +12,11 @@ import { slugify } from 'markdown-toc'; import { marked } from 'marked'; import { markedHighlight } from 'marked-highlight'; +import { + DAFF_DOC_KIND_PATH_SEGMENT_MAP, + DaffDocKind, +} from '@daffodil/docs-utils'; + hljs.registerLanguage('typescript', typescript); hljs.registerLanguage('ts', typescript); hljs.registerLanguage('xml', xml); @@ -20,17 +25,11 @@ hljs.registerLanguage('bash', bash); hljs.registerLanguage('graphql', graphql); hljs.registerLanguage('gql', graphql); -enum DocKind { - GUIDE = 'GUIDE', - EXPLANATION = 'EXPLANATION', - PACKAGE = 'PACKAGE', - API = 'API', -} const DOC_KIND_REGEX = { - [DocKind.GUIDE]: /\/docs\/guides\/(?.+)\.md/, - [DocKind.EXPLANATION]: /\/docs\/explanations\/(?.+)\.md/, - [DocKind.PACKAGE]: /\/libs\/(?.+)\.md/, - [DocKind.API]: /\/libs\/(?.+)\.ts/, + [DaffDocKind.GUIDE]: /\/docs\/guides\/(?.+)\.md/, + [DaffDocKind.EXPLANATION]: /\/docs\/explanations\/(?.+)\.md/, + [DaffDocKind.PACKAGE]: /\/libs\/(?.+)\.md/, + [DaffDocKind.API]: /\/libs\/(?.+)\.ts/, }; const getLinkUrl = (path: string): string => { const kind = (>Object.keys(DOC_KIND_REGEX)).find((k) => DOC_KIND_REGEX[k].test(path)); @@ -41,18 +40,14 @@ const getLinkUrl = (path: string): string => { } switch (kind) { - case DocKind.GUIDE: - return `/docs/guides/${match.groups.path}`; + case DaffDocKind.GUIDE: + case DaffDocKind.EXPLANATION: + case DaffDocKind.API: + return `/docs/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[kind]}/${match.groups.path}`; - case DocKind.EXPLANATION: - return `/docs/explanations/${match.groups.path}`; - - case DocKind.PACKAGE: + case DaffDocKind.PACKAGE: return `/docs/packages/${match.groups.path}`.replaceAll(/\/(?:readme|src|guides)/gi, ''); - case DocKind.API: - return `/docs/api/${match.groups.path}`; - default: return path; }