Skip to content

Commit

Permalink
feat: add link transform for disableHtmlExt
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm committed Apr 24, 2024
1 parent 1ea0498 commit 8966735
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<DocInner
}

function YamlFileTransformer(content: string, transformOptions: FileTransformOptions): Object {
const {disableHtmlExt} = ArgvService.getConfig();
const ext = disableHtmlExt ? '' : '.html';

Check failure on line 124 in src/resolvers/md2html.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Delete `····`
let data: LeadingPage | null = null;

try {
Expand All @@ -136,7 +139,7 @@ function YamlFileTransformer(content: string, transformOptions: FileTransformOpt
if (Object.prototype.hasOwnProperty.call(data, 'blocks')) {
data = modifyValuesByKeys(data, LINK_KEYS, (link) => {
if (isString(link) && getLinksWithContentExtersion(link)) {
return link.replace(/.(md|yaml)$/gmu, '.html');
return link.replace(/.(md|yaml)$/gmu, ext);
}
});

Expand All @@ -149,7 +152,7 @@ function YamlFileTransformer(content: string, transformOptions: FileTransformOpt
});
} else {
const links = data?.links?.map((link) =>
link.href ? {...link, href: link.href.replace(/.md$/gmu, '.html')} : link,
link.href ? {...link, href: link.href.replace(/.md$/gmu, ext)} : link,
);

if (links) {
Expand Down Expand Up @@ -189,5 +192,6 @@ function MdFileTransformer(content: string, transformOptions: FileTransformOptio
assetsPublicPath: getAssetsPublicPath(filePath),
getVarsPerFile: getVarsPerRelativeFile,
extractTitle: true,
toLinkExtention: options.disableHtmlExt ? '' : null,
});
}

0 comments on commit 8966735

Please sign in to comment.