From c270da0cb0599d9db0ad8c3f45c415ba651ef898 Mon Sep 17 00:00:00 2001 From: Maxim Karpov Date: Thu, 28 Mar 2024 13:16:17 +0300 Subject: [PATCH] feat: use base uri path --- src/resolvers/md2html.ts | 31 +++++++++++-------------------- src/utils/markup.ts | 2 +- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index 860f9e75..3090c861 100644 --- a/src/resolvers/md2html.ts +++ b/src/resolvers/md2html.ts @@ -37,26 +37,20 @@ const fixRelativePath = (relativeTo: string) => (path: string) => { return join(getAssetsPublicPath(relativeTo), path); }; -const getFileMeta = async ({ - fileExtension, - metadata, - inputPath, -}: ResolverOptions) => { - const { input, allowCustomResources } = ArgvService.getConfig(); +const getFileMeta = async ({fileExtension, metadata, inputPath}: ResolverOptions) => { + const {input, allowCustomResources} = ArgvService.getConfig(); const resolvedPath: string = resolve(input, inputPath); const content: string = readFileSync(resolvedPath, 'utf8'); const transformFn: Function = FileTransformer[fileExtension]; - const { result } = transformFn(content, { path: inputPath }); + const {result} = transformFn(content, {path: inputPath}); const vars = getVarsPerFile(inputPath); const updatedMetadata = metadata?.isContributorsEnabled ? await getVCSMetadata(metadata, content, result?.meta) : result?.meta; - const fileMeta = fileExtension === '.yaml' - ? (result?.data?.meta ?? {}) - : updatedMetadata; + const fileMeta = fileExtension === '.yaml' ? result?.data?.meta ?? {} : updatedMetadata; if (!Array.isArray(fileMeta?.metadata)) { fileMeta.metadata = [fileMeta?.metadata].filter(Boolean); @@ -65,7 +59,7 @@ const getFileMeta = async ({ fileMeta.metadata = fileMeta.metadata.concat(vars.__metadata?.filter(Boolean) || []); if (allowCustomResources) { - const { script, style } = metadata?.resources ?? {}; + const {script, style} = metadata?.resources ?? {}; fileMeta.style = (fileMeta.style ?? []).concat(style || []).map(fixRelativePath(inputPath)); fileMeta.script = (fileMeta.script ?? []) .concat(script ?? []) @@ -75,11 +69,11 @@ const getFileMeta = async ({ fileMeta.script = []; } - return { ...result, meta: fileMeta }; -} + return {...result, meta: fileMeta}; +}; const getFileProps = async (options: ResolverOptions) => { - const { inputPath, outputPath } = options; + const {inputPath, outputPath} = options; const pathToDir: string = dirname(inputPath); const toc: YfmToc | null = TocService.getForPath(inputPath) || null; @@ -87,10 +81,7 @@ const getFileProps = async (options: ResolverOptions) => { const pathToFileDir: string = pathToDir === tocBase ? '' : pathToDir.replace(`${tocBase}${sep}`, ''); - const { - lang: configLang, - langs: configLangs, - } = ArgvService.getConfig(); + const {lang: configLang, langs: configLangs} = ArgvService.getConfig(); const meta = await getFileMeta(options); const tocBaseLang = tocBase?.split('/')[0]; @@ -113,10 +104,10 @@ const getFileProps = async (options: ResolverOptions) => { }; return props; -} +}; export async function resolveMd2HTML(options: ResolverOptions): Promise { - const { outputPath, outputBundlePath, inputPath, deep } = options; + const {outputPath, outputBundlePath, inputPath, deep} = options; const props = await getFileProps(options); const outputDir = dirname(outputPath); diff --git a/src/utils/markup.ts b/src/utils/markup.ts index ae124c43..de4a13d7 100644 --- a/src/utils/markup.ts +++ b/src/utils/markup.ts @@ -28,7 +28,7 @@ export type Meta = TitleMeta & export function generateStaticMarkup( props: DocInnerProps, pathToBundle: string, - deep: number = 0, + deep = 0, ): string { const {style, script, metadata, ...restYamlConfigMeta} = (props.data.meta as Meta) || {}; const {title: tocTitle} = props.data.toc;