Skip to content

Commit

Permalink
feat(dgeni): remove atoms and molecules from design doc IDs (#3041)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Sep 3, 2024
1 parent 5504966 commit d6e9058
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
16 changes: 16 additions & 0 deletions tools/dgeni/src/services/id-sanitizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Removes segments from IDs.
*/
export class IdSanitizer {
segmentsToRemove: Array<string | RegExp> = [];

sanitize(id: string): string {
return this.segmentsToRemove.reduce<string>((acc, test) => {
try {
return acc.replaceAll(test, '');
} catch {
return acc.replace(test, '');
}
}, id);
}
}
2 changes: 2 additions & 0 deletions tools/dgeni/src/transforms/daffodil-base-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as path from 'path';

import { AddKindProcessor } from '../../processors/add-kind';
import { ConvertToJsonProcessor } from '../../processors/convertToJson';
import { IdSanitizer } from '../../services/id-sanitizer';
import {
PROJECT_ROOT,
TEMPLATES_PATH,
Expand All @@ -23,6 +24,7 @@ export const daffodilBasePackage = new Package('daffodil-base', [
nunjucksPackage,
])
.processor(new AddKindProcessor())
.factory('idSanitizer', () => new IdSanitizer())
.processor('convertToJson', (log, createDocMessage) => new ConvertToJsonProcessor(log, createDocMessage))
.factory('packageInfo', () => require(path.resolve(PROJECT_ROOT, 'package.json')))

Expand Down
32 changes: 20 additions & 12 deletions tools/dgeni/src/transforms/daffodil-guides-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DAFF_DGENI_EXCLUDED_PACKAGES_REGEX } from '../../constants/excluded-pac
import { AddKindProcessor } from '../../processors/add-kind';
import { GenerateNavListProcessor } from '../../processors/generateNavList';
import { MarkdownCodeProcessor } from '../../processors/markdown';
import { IdSanitizer } from '../../services/id-sanitizer';
import { outputPathsConfigurator } from '../../utils/configurator/output';
import { pathsConfigurator } from '../../utils/configurator/path';
import { generateNavigationTrieFromDocuments } from '../../utils/navigation-trie';
Expand Down Expand Up @@ -41,19 +42,19 @@ const base = new Package('daffodil-guides-base', [daffodilBasePackage])
// Where to find the templates for the API doc rendering
templateFinder.templateFolders.unshift(GUIDES_TEMPLATES_PATH);
})
.config((computeIdsProcessor) => {
.config((computeIdsProcessor, idSanitizer: IdSanitizer) => {
computeIdsProcessor.idTemplates.push({
docTypes,
getId: (doc) => doc
.fileInfo
.relativePath
.replaceAll('src/', '')
.replaceAll('docs/', '')
.replaceAll('guides/', '')
.replaceAll('/README', '')
.replace(/\.\w*$/, ''),
getId: (doc) => idSanitizer.sanitize(doc.fileInfo.relativePath),
getAliases: (doc) => [doc.id],
});
idSanitizer.segmentsToRemove = [
'src/',
'docs/',
'guides/',
'/README',
/\.\w*$/,
];
})
.config((generateNavList: GenerateNavListProcessor) => {
generateNavList.transform = (docs) => generateNavigationTrieFromDocuments(docs.map(transformGuideDoc));
Expand Down Expand Up @@ -88,11 +89,18 @@ export const explanationDocsPackage = pathsConfigurator({
//

// design
const design = new Package('design-base', [base])
.config((idSanitizer: IdSanitizer) => {
idSanitizer.segmentsToRemove.push(
'atoms/',
'molecules/',
);
});
export const designDocsPackage = outputPathsConfigurator({
kind: DaffDocKind.PACKAGE,
outputPath: `${DAFF_DOCS_PATH}/${DAFF_DOCS_DESIGN_PATH}`,
docTypes,
})(new Package('design-packages', [base]))
})(new Package('design-packages', [design]))
.config((readFilesProcessor) => {
readFilesProcessor.basePath = DESIGN_PATH;
readFilesProcessor.sourceFiles = [
Expand All @@ -105,12 +113,12 @@ export const designGuidesPackage = pathsConfigurator({
outputPath: `${DAFF_DOCS_PATH}/${DAFF_DOCS_DESIGN_PATH}`,
inputPathBase: DESIGN_PATH,
docTypes,
})(new Package('design-guides', [base]));
})(new Package('design-guides', [design]));

export const designExplanationsPackage = pathsConfigurator({
kind: DaffDocKind.EXPLANATION,
outputPath: `${DAFF_DOCS_PATH}/${DAFF_DOCS_DESIGN_PATH}`,
inputPathBase: DESIGN_PATH,
docTypes,
})(new Package('design-explanations', [base]));
})(new Package('design-explanations', [design]));
//

0 comments on commit d6e9058

Please sign in to comment.