Skip to content

Commit

Permalink
feat: use base uri path
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm authored and 3y3 committed Apr 23, 2024
1 parent b606d8d commit c270da0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
31 changes: 11 additions & 20 deletions src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ?? [])
Expand All @@ -75,22 +69,19 @@ 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;
const tocBase: string = toc?.base ?? '';
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];
Expand All @@ -113,10 +104,10 @@ const getFileProps = async (options: ResolverOptions) => {
};

return props;
}
};

export async function resolveMd2HTML(options: ResolverOptions): Promise<DocInnerProps> {
const { outputPath, outputBundlePath, inputPath, deep } = options;
const {outputPath, outputBundlePath, inputPath, deep} = options;
const props = await getFileProps(options);

const outputDir = dirname(outputPath);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Meta = TitleMeta &
export function generateStaticMarkup(
props: DocInnerProps<DocPageData>,
pathToBundle: string,
deep: number = 0,
deep = 0,
): string {
const {style, script, metadata, ...restYamlConfigMeta} = (props.data.meta as Meta) || {};
const {title: tocTitle} = props.data.toc;
Expand Down

0 comments on commit c270da0

Please sign in to comment.