Skip to content

Commit

Permalink
after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe committed Oct 25, 2023
1 parent ef9eb64 commit 0edecd1
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 177 deletions.
3 changes: 2 additions & 1 deletion src/cmd/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {join, resolve} from 'path';
import {ArgvService, Includers} from '../../services';
import OpenapiIncluder from '@diplodoc/openapi-extension/includer';
import {
initLinterWorkers, initProcessWorkers,
initLinterWorkers,
initProcessWorkers,
processAssets,
processExcludedFiles,
processLinter,
Expand Down
12 changes: 3 additions & 9 deletions src/resolvers/lintPage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {dirname, relative, resolve} from 'path';
import log from '@doc-tools/transform/lib/log';
import log from '@diplodoc/transform/lib/log';
import {
default as yfmlint,
LintMarkdownFunctionOptions,
PluginOptions,
} from '@doc-tools/transform/lib/yfmlint';
} from '@diplodoc/transform/lib/yfmlint';
import {bold} from 'chalk';

import {ArgvService, PluginService} from '../services';
Expand Down Expand Up @@ -54,13 +54,7 @@ export async function lintPage(options: ResolverLintOptions) {
}

function MdFileLinter(content: string, lintOptions: FileTransformOptions): void {
const {
input,
lintConfig,
disableLiquid,
outputFormat,
...options
} = ArgvService.getConfig();
const {input, lintConfig, disableLiquid, outputFormat, ...options} = ArgvService.getConfig();
const {path: filePath} = lintOptions;

const plugins = outputFormat === 'md' ? [] : PluginService.getPlugins();
Expand Down
43 changes: 26 additions & 17 deletions src/resolvers/processPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {VCSConnector} from '../vcs-connector/connector-models';
import {LeadingPage, MetaDataOptions, PathData, Resources, SinglePageResult} from '../models';
import {DocInnerProps} from '@diplodoc/client';
import {bold} from 'chalk';
import log from '@doc-tools/transform/lib/log';
import log from '@diplodoc/transform/lib/log';
import * as fs from 'fs';
import {dump, load} from 'js-yaml';
import {resolveMd2Md} from './md2md';
Expand Down Expand Up @@ -37,7 +37,13 @@ export async function processPage(options: ProcessPageOptions) {

const outputBundlePath = join(outputFolderPath, BUNDLE_FOLDER);

const pathData = getPathData(pathToFile, inputFolderPath, outputFolderPath, outputFormat, outputBundlePath);
const pathData = getPathData(
pathToFile,
inputFolderPath,
outputFolderPath,
outputFormat,
outputBundlePath,
);

logger.proc(pathToFile);

Expand All @@ -46,7 +52,6 @@ export async function processPage(options: ProcessPageOptions) {
await preparingPagesByOutputFormat(pathData, metaDataOptions, resolveConditions, singlePage);
}


function getPathData(
pathToFile: string,
inputFolderPath: string,
Expand Down Expand Up @@ -105,7 +110,10 @@ function savePageResultForSinglePage(pageProps: DocInnerProps, pathData: PathDat
});
}

function getMetaDataOptions(pathData: PathData, inputFolderPathLength: number, vcsConnector?: VCSConnector,
function getMetaDataOptions(
pathData: PathData,
inputFolderPathLength: number,
vcsConnector?: VCSConnector,
): MetaDataOptions {
const {contributors, addSystemMeta, resources, allowCustomResources} = ArgvService.getConfig();

Expand All @@ -120,7 +128,6 @@ function getMetaDataOptions(pathData: PathData, inputFolderPathLength: number, v
addSystemMeta,
};


if (allowCustomResources && resources) {
const allowedResources = Object.entries(resources).reduce((acc: Resources, [key, val]) => {
if (Object.keys(ResourceType).includes(key)) {
Expand All @@ -132,7 +139,6 @@ function getMetaDataOptions(pathData: PathData, inputFolderPathLength: number, v
metaDataOptions.resources = allowedResources;
}


return metaDataOptions;
}

Expand Down Expand Up @@ -167,8 +173,10 @@ async function preparingPagesByOutputFormat(
return;
}

if (outputFormat === 'md' && isYamlFileExtension ||
outputFormat === 'html' && !isYamlFileExtension && fileExtension !== '.md') {
if (
(outputFormat === 'md' && isYamlFileExtension) ||
(outputFormat === 'html' && !isYamlFileExtension && fileExtension !== '.md')
) {
await copyFileWithoutChanges(resolvedPathToFile, outputDir, filename);
return;
}
Expand Down Expand Up @@ -207,7 +215,11 @@ async function processingYamlFile(path: PathData, metaDataOptions: MetaDataOptio
await fs.promises.writeFile(resolve(outputFolderPath, pathToFile), dump(parsedContent));
}

async function copyFileWithoutChanges(resolvedPathToFile: string, outputDir: string, filename: string) {
async function copyFileWithoutChanges(
resolvedPathToFile: string,
outputDir: string,
filename: string,
) {
const from = resolvedPathToFile;
const to = resolve(outputDir, filename);

Expand All @@ -224,14 +236,11 @@ async function processingFileToMd(path: PathData, metaDataOptions: MetaDataOptio
});
}

async function processingFileToHtml(path: PathData, metaDataOptions: MetaDataOptions): Promise<DocInnerProps> {
const {
outputBundlePath,
filename,
fileExtension,
outputPath,
pathToFile,
} = path;
async function processingFileToHtml(
path: PathData,
metaDataOptions: MetaDataOptions,
): Promise<DocInnerProps> {
const {outputBundlePath, filename, fileExtension, outputPath, pathToFile} = path;

return resolveMd2HTML({
inputPath: pathToFile,
Expand Down
51 changes: 24 additions & 27 deletions src/services/leading.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import {dirname, resolve} from 'path';
import {dump, load} from 'js-yaml';
import log from '@doc-tools/transform/lib/log';
import log from '@diplodoc/transform/lib/log';

import {ArgvService, PresetService} from './index';
import {LeadingPage} from '../models';
import {filterTextItems, filterFiles, firstFilterTextItems, liquidFields, liquidField} from './utils';
import {
filterTextItems,
filterFiles,
firstFilterTextItems,
liquidFields,
liquidField,
} from './utils';
import * as fs from 'fs';

async function filterFile(path: string) {
const {
input: inputFolderPath,
vars,
} = ArgvService.getConfig();
const {input: inputFolderPath, vars} = ArgvService.getConfig();

const pathToDir = dirname(path);
const filePath = resolve(inputFolderPath, path);
Expand All @@ -25,26 +28,20 @@ async function filterFile(path: string) {

/* Should remove all links with false expressions */
try {
const title = firstFilterTextItems(
parsedIndex.title,
combinedVars,
{resolveConditions: true},
);
const title = firstFilterTextItems(parsedIndex.title, combinedVars, {
resolveConditions: true,
});
parsedIndex.title = liquidField(title, combinedVars, path);

const description = filterTextItems(
parsedIndex.description,
combinedVars,
{resolveConditions: true},
);
const description = filterTextItems(parsedIndex.description, combinedVars, {
resolveConditions: true,
});
parsedIndex.description = liquidFields(description, combinedVars, path);

if (parsedIndex.meta?.title) {
const metaTitle = firstFilterTextItems(
parsedIndex.meta.title,
combinedVars,
{resolveConditions: true},
);
const metaTitle = firstFilterTextItems(parsedIndex.meta.title, combinedVars, {
resolveConditions: true,
});
parsedIndex.meta.title = liquidField(metaTitle, combinedVars, path);
}

Expand All @@ -58,15 +55,15 @@ async function filterFile(path: string) {
}

if (parsedIndex.nav) {
const navTitle = firstFilterTextItems(
parsedIndex.nav.title,
combinedVars,
{resolveConditions: true},
);
const navTitle = firstFilterTextItems(parsedIndex.nav.title, combinedVars, {
resolveConditions: true,
});
parsedIndex.nav.title = liquidField(navTitle, combinedVars, path);
}

parsedIndex.links = filterFiles(parsedIndex.links, 'links', combinedVars, {resolveConditions: true});
parsedIndex.links = filterFiles(parsedIndex.links, 'links', combinedVars, {
resolveConditions: true,
});

parsedIndex.links.forEach((link) => {
if (link.title) {
Expand Down
6 changes: 5 additions & 1 deletion src/services/tocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ function dumpData() {
};
}

function loadData({storageKeyValue, includedTocPathsArr, navigationPaths: navigationPathsLocal}: TocServiceDataDump) {
function loadData({
storageKeyValue,
includedTocPathsArr,
navigationPaths: navigationPathsLocal,
}: TocServiceDataDump) {
navigationPaths.splice(0);
navigationPaths.push(...navigationPathsLocal);

Expand Down
Loading

0 comments on commit 0edecd1

Please sign in to comment.