Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dgeni): remove atoms and molecules from design doc IDs #3041

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]));
//
Loading