Skip to content

Commit

Permalink
feat: add language control selector for static build
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm authored and 3y3 committed Apr 23, 2024
1 parent a22e516 commit 77d9b34
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,26 @@ 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 @@ -59,7 +65,7 @@ const getFileMeta = async ({fileExtension, metadata, inputPath}: ResolverOptions
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 @@ -69,19 +75,22 @@ const getFileMeta = async ({fileExtension, metadata, inputPath}: ResolverOptions
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 @@ -104,10 +113,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

0 comments on commit 77d9b34

Please sign in to comment.