From 993966612fc2ab1cfaf423270987d48cd1dbc53d Mon Sep 17 00:00:00 2001 From: Maxim Karpov Date: Fri, 26 Apr 2024 13:17:00 +0300 Subject: [PATCH] feat: add relative path resolution for links --- src/resolvers/md2html.ts | 3 ++- src/services/metadata.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index 86f455f6..a0d1382a 100644 --- a/src/resolvers/md2html.ts +++ b/src/resolvers/md2html.ts @@ -13,7 +13,7 @@ import yaml from 'js-yaml'; import {Lang, PROCESSING_FINISHED} from '../constants'; import {LeadingPage, ResolverOptions, YfmToc} from '../models'; import {ArgvService, PluginService, TocService} from '../services'; -import {getAssetsPublicPath, getVCSMetadata} from '../services/metadata'; +import {getAssetsPublicPath, getAssetsRootPath, getVCSMetadata} from '../services/metadata'; import { generateStaticMarkup, getLinksWithContentExtersion, @@ -187,6 +187,7 @@ function MdFileTransformer(content: string, transformOptions: FileTransformOptio root, path, assetsPublicPath: getAssetsPublicPath(filePath), + rootPublicPath: getAssetsRootPath(filePath), getVarsPerFile: getVarsPerRelativeFile, extractTitle: true, }); diff --git a/src/services/metadata.ts b/src/services/metadata.ts index 529bd379..1e7292dd 100644 --- a/src/services/metadata.ts +++ b/src/services/metadata.ts @@ -337,9 +337,16 @@ function getAssetsPublicPath(filePath: string) { return deepBasePath; } +function getAssetsRootPath(filePath: string) { + const toc: YfmToc | null = TocService.getForPath(filePath) || null; + + return toc?.base; +} + export { getContentWithUpdatedMetadata, getContentWithUpdatedStaticMetadata, getVCSMetadata, getAssetsPublicPath, + getAssetsRootPath, };