@diplodoc/cli 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.client.css +2678 -41
- package/build/app.client.js +1 -1
- package/build/index.js +376 -267
- package/build/index.js.map +3 -3
- package/build/linter.js +54 -46
- package/build/linter.js.map +2 -2
- package/package.json +12 -11
- package/src/cmd/build/index.ts +29 -15
- package/src/cmd/publish/index.ts +1 -6
- package/src/cmd/publish/upload.ts +22 -16
- package/src/cmd/translate/index.ts +51 -37
- package/src/cmd/xliff/compose.ts +16 -7
- package/src/cmd/xliff/extract.ts +18 -9
- package/src/cmd/xliff/index.ts +4 -1
- package/src/constants.ts +4 -4
- package/src/index.ts +2 -2
- package/src/models.ts +12 -7
- package/src/resolvers/lintPage.ts +1 -7
- package/src/resolvers/md2html.ts +23 -15
- package/src/resolvers/md2md.ts +13 -13
- package/src/services/authors.ts +4 -2
- package/src/services/contributors.ts +26 -12
- package/src/services/includers/batteries/common.ts +14 -2
- package/src/services/includers/batteries/generic.ts +27 -9
- package/src/services/includers/batteries/sourcedocs.ts +4 -1
- package/src/services/includers/batteries/unarchive.ts +8 -4
- package/src/services/includers/index.ts +6 -4
- package/src/services/leading.ts +23 -26
- package/src/services/metadata.ts +35 -10
- package/src/services/preset.ts +2 -2
- package/src/services/tocs.ts +26 -21
- package/src/services/utils.ts +13 -3
- package/src/steps/processAssets.ts +2 -8
- package/src/steps/processExcludedFiles.ts +11 -20
- package/src/steps/processLinter.ts +8 -7
- package/src/steps/processLogs.ts +1 -6
- package/src/steps/processMapFile.ts +8 -11
- package/src/steps/processPages.ts +96 -66
- package/src/steps/processServiceFiles.ts +3 -1
- package/src/steps/publishFilesToS3.ts +16 -12
- package/src/utils/file.ts +5 -1
- package/src/utils/glob.ts +1 -3
- package/src/utils/markup.ts +28 -13
- package/src/utils/singlePage.ts +10 -9
- package/src/utils/toc.ts +20 -7
- package/src/utils/worker.ts +1 -1
- package/src/validator.ts +24 -16
- package/src/vcs-connector/client/github.ts +15 -7
- package/src/vcs-connector/connector-validator.ts +12 -6
- package/src/vcs-connector/github.ts +38 -11
- package/src/vcs-connector/index.ts +1 -1
- package/src/workers/linter/index.ts +1 -5
- package/CHANGELOG.md +0 -793
package/src/resolvers/md2html.ts
CHANGED
|
@@ -8,7 +8,13 @@ import liquid from '@diplodoc/transform/lib/liquid';
|
|
|
8
8
|
|
|
9
9
|
import {ResolverOptions, YfmToc, ResolveMd2HTMLResult, LeadingPage} from '../models';
|
|
10
10
|
import {ArgvService, TocService, PluginService} from '../services';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
generateStaticMarkup,
|
|
13
|
+
logger,
|
|
14
|
+
transformToc,
|
|
15
|
+
getVarsPerFile,
|
|
16
|
+
getVarsPerRelativeFile,
|
|
17
|
+
} from '../utils';
|
|
12
18
|
import {PROCESSING_FINISHED, Lang} from '../constants';
|
|
13
19
|
import {getAssetsPublicPath, getUpdatedMetadata} from '../services/metadata';
|
|
14
20
|
import {MarkdownItPluginCb} from '@diplodoc/transform/lib/plugins/typings';
|
|
@@ -31,9 +37,10 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<ResolveM
|
|
|
31
37
|
const {inputPath, fileExtension, outputPath, outputBundlePath, metadata} = options;
|
|
32
38
|
|
|
33
39
|
const pathToDir: string = dirname(inputPath);
|
|
34
|
-
const toc: YfmToc|null = TocService.getForPath(inputPath) || null;
|
|
40
|
+
const toc: YfmToc | null = TocService.getForPath(inputPath) || null;
|
|
35
41
|
const tocBase: string = toc && toc.base ? toc.base : '';
|
|
36
|
-
const pathToFileDir: string =
|
|
42
|
+
const pathToFileDir: string =
|
|
43
|
+
pathToDir === tocBase ? '' : pathToDir.replace(`${tocBase}${sep}`, '');
|
|
37
44
|
const relativePathToIndex = relative(pathToDir, `${tocBase}${sep}`);
|
|
38
45
|
|
|
39
46
|
const {input, lang, allowCustomResources} = ArgvService.getConfig();
|
|
@@ -43,17 +50,18 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise<ResolveM
|
|
|
43
50
|
const transformFn: Function = FileTransformer[fileExtension];
|
|
44
51
|
const {result} = transformFn(content, {path: inputPath});
|
|
45
52
|
|
|
46
|
-
const updatedMetadata =
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
const updatedMetadata =
|
|
54
|
+
metadata && metadata.isContributorsEnabled
|
|
55
|
+
? await getUpdatedMetadata(metadata, content, result?.meta)
|
|
56
|
+
: result.meta;
|
|
49
57
|
|
|
50
|
-
const fileMeta = fileExtension === '.yaml' ?
|
|
58
|
+
const fileMeta = fileExtension === '.yaml' ? result.data.meta ?? {} : updatedMetadata;
|
|
51
59
|
|
|
52
60
|
if (allowCustomResources) {
|
|
53
61
|
const {script, style} = metadata?.resources || {};
|
|
54
|
-
fileMeta.style = (fileMeta.style || []).concat(style || [])
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
fileMeta.style = (fileMeta.style || []).concat(style || []).map(fixRelativePath(inputPath));
|
|
63
|
+
fileMeta.script = (fileMeta.script || [])
|
|
64
|
+
.concat(script || [])
|
|
57
65
|
.map(fixRelativePath(inputPath));
|
|
58
66
|
} else {
|
|
59
67
|
fileMeta.style = [];
|
|
@@ -98,12 +106,13 @@ function YamlFileTransformer(content: string): Object {
|
|
|
98
106
|
};
|
|
99
107
|
}
|
|
100
108
|
|
|
101
|
-
const links = data?.links?.map(
|
|
102
|
-
(
|
|
103
|
-
link.href ? ({...link, href: link.href.replace(/.md$/gmu, '.html')}) : link,
|
|
109
|
+
const links = data?.links?.map((link) =>
|
|
110
|
+
link.href ? {...link, href: link.href.replace(/.md$/gmu, '.html')} : link,
|
|
104
111
|
);
|
|
105
112
|
|
|
106
|
-
if (links) {
|
|
113
|
+
if (links) {
|
|
114
|
+
data.links = links;
|
|
115
|
+
}
|
|
107
116
|
|
|
108
117
|
return {
|
|
109
118
|
result: {data},
|
|
@@ -128,7 +137,6 @@ function MdFileTransformer(content: string, transformOptions: FileTransformOptio
|
|
|
128
137
|
const root = resolve(input);
|
|
129
138
|
const path: string = resolve(input, filePath);
|
|
130
139
|
|
|
131
|
-
|
|
132
140
|
return transform(content, {
|
|
133
141
|
...options,
|
|
134
142
|
plugins: plugins as MarkdownItPluginCb<unknown>[],
|
package/src/resolvers/md2md.ts
CHANGED
|
@@ -50,7 +50,10 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void>
|
|
|
50
50
|
changesName = Math.trunc(new Date(changesDate).getTime() / 1000);
|
|
51
51
|
}
|
|
52
52
|
if (!changesName) {
|
|
53
|
-
changesName = `name-${mdFilename}-${String(changelogs.length - index).padStart(
|
|
53
|
+
changesName = `name-${mdFilename}-${String(changelogs.length - index).padStart(
|
|
54
|
+
3,
|
|
55
|
+
'0',
|
|
56
|
+
)}`;
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
const changesPath = join(outputDir, `changes-${changesName}.json`);
|
|
@@ -59,10 +62,13 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise<void>
|
|
|
59
62
|
throw new Error(`Changelog ${changesPath} already exists!`);
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
writeFileSync(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
writeFileSync(
|
|
66
|
+
changesPath,
|
|
67
|
+
JSON.stringify({
|
|
68
|
+
...changes,
|
|
69
|
+
source: mdFilename,
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
|
|
@@ -85,11 +91,7 @@ function copyFile(targetPath: string, targetDestPath: string, options?: PluginOp
|
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
export function liquidMd2Md(input: string, vars: Record<string, unknown>, path: string) {
|
|
88
|
-
const {
|
|
89
|
-
applyPresets,
|
|
90
|
-
resolveConditions,
|
|
91
|
-
conditionsInCode,
|
|
92
|
-
} = ArgvService.getConfig();
|
|
94
|
+
const {applyPresets, resolveConditions, conditionsInCode} = ArgvService.getConfig();
|
|
93
95
|
|
|
94
96
|
return liquid(input, vars, path, {
|
|
95
97
|
conditions: resolveConditions,
|
|
@@ -101,9 +103,7 @@ export function liquidMd2Md(input: string, vars: Record<string, unknown>, path:
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
function transformMd2Md(input: string, options: PluginOptions) {
|
|
104
|
-
const {
|
|
105
|
-
disableLiquid,
|
|
106
|
-
} = ArgvService.getConfig();
|
|
106
|
+
const {disableLiquid} = ArgvService.getConfig();
|
|
107
107
|
const {
|
|
108
108
|
vars = {},
|
|
109
109
|
path,
|
package/src/services/authors.ts
CHANGED
|
@@ -18,7 +18,6 @@ async function updateAuthorMetadataStringByAuthorLogin(
|
|
|
18
18
|
return '';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
async function updateAuthorMetadataStringByFilePath(
|
|
23
22
|
filePath: string,
|
|
24
23
|
vcsConnector?: VCSConnector,
|
|
@@ -37,7 +36,10 @@ async function updateAuthorMetadataStringByFilePath(
|
|
|
37
36
|
return '';
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
async function getAuthorDetails(
|
|
39
|
+
async function getAuthorDetails(
|
|
40
|
+
vcsConnector: VCSConnector,
|
|
41
|
+
author: string | object,
|
|
42
|
+
): Promise<string | null> {
|
|
41
43
|
if (typeof author === 'object') {
|
|
42
44
|
// Avoiding problems when adding to html markup
|
|
43
45
|
return replaceDoubleToSingleQuotes(JSON.stringify(author));
|
|
@@ -6,17 +6,24 @@ import {REGEXP_INCLUDE_CONTENTS, REGEXP_INCLUDE_FILE_PATH} from '../constants';
|
|
|
6
6
|
import {Contributor, Contributors, FileData} from '../models';
|
|
7
7
|
import {FileContributors, VCSConnector} from '../vcs-connector/connector-models';
|
|
8
8
|
|
|
9
|
-
async function getFileContributorsMetadata(
|
|
9
|
+
async function getFileContributorsMetadata(
|
|
10
|
+
fileData: FileData,
|
|
11
|
+
vcsConnector: VCSConnector,
|
|
12
|
+
): Promise<string> {
|
|
10
13
|
const contributors = await getFileContributorsString(fileData, vcsConnector);
|
|
11
14
|
|
|
12
15
|
return `contributors: ${contributors}`;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
async function getFileContributorsString(
|
|
18
|
+
async function getFileContributorsString(
|
|
19
|
+
fileData: FileData,
|
|
20
|
+
vcsConnector: VCSConnector,
|
|
21
|
+
): Promise<string> {
|
|
16
22
|
const {tmpInputFilePath, inputFolderPathLength} = fileData;
|
|
17
23
|
|
|
18
24
|
const relativeFilePath = tmpInputFilePath.substring(inputFolderPathLength);
|
|
19
|
-
const fileContributors: FileContributors =
|
|
25
|
+
const fileContributors: FileContributors =
|
|
26
|
+
await vcsConnector.getContributorsByPath(relativeFilePath);
|
|
20
27
|
let nestedContributors: Contributors = {};
|
|
21
28
|
|
|
22
29
|
if (!fileContributors.hasIncludes) {
|
|
@@ -29,13 +36,17 @@ async function getFileContributorsString(fileData: FileData, vcsConnector: VCSCo
|
|
|
29
36
|
...nestedContributors,
|
|
30
37
|
};
|
|
31
38
|
|
|
32
|
-
const contributorsArray: Contributor[] =
|
|
33
|
-
|
|
39
|
+
const contributorsArray: Contributor[] = Object.entries(
|
|
40
|
+
fileContributorsWithContributorsIncludedFiles,
|
|
41
|
+
).map(([, contributor]) => contributor);
|
|
34
42
|
|
|
35
43
|
return replaceDoubleToSingleQuotes(JSON.stringify(contributorsArray));
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
async function getContributorsForNestedFiles(
|
|
46
|
+
async function getContributorsForNestedFiles(
|
|
47
|
+
fileData: FileData,
|
|
48
|
+
vcsConnector: VCSConnector,
|
|
49
|
+
): Promise<Contributors> {
|
|
39
50
|
const {fileContent, inputFolderPathLength} = fileData;
|
|
40
51
|
|
|
41
52
|
const includeContents = fileContent.match(REGEXP_INCLUDE_CONTENTS);
|
|
@@ -44,7 +55,10 @@ async function getContributorsForNestedFiles(fileData: FileData, vcsConnector: V
|
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
const includesContributors: Contributors[] = [];
|
|
47
|
-
const relativeIncludeFilePaths: Set<string> = getRelativeIncludeFilePaths(
|
|
58
|
+
const relativeIncludeFilePaths: Set<string> = getRelativeIncludeFilePaths(
|
|
59
|
+
fileData,
|
|
60
|
+
includeContents,
|
|
61
|
+
);
|
|
48
62
|
|
|
49
63
|
for (const relativeIncludeFilePath of relativeIncludeFilePaths.values()) {
|
|
50
64
|
const relativeFilePath = relativeIncludeFilePath.substring(inputFolderPathLength);
|
|
@@ -89,7 +103,10 @@ function getRelativeIncludeFilePaths(fileData: FileData, includeContents: string
|
|
|
89
103
|
|
|
90
104
|
if (relativeIncludeFilePath && relativeIncludeFilePath.length !== 0) {
|
|
91
105
|
const relativeIncludeFilePathWithoutHash = relativeIncludeFilePath[0].split('#');
|
|
92
|
-
const includeFilePath = join(
|
|
106
|
+
const includeFilePath = join(
|
|
107
|
+
dirname(tmpInputFilePath),
|
|
108
|
+
relativeIncludeFilePathWithoutHash[0],
|
|
109
|
+
);
|
|
93
110
|
|
|
94
111
|
relativeIncludeFilePaths.add(includeFilePath);
|
|
95
112
|
}
|
|
@@ -98,7 +115,4 @@ function getRelativeIncludeFilePaths(fileData: FileData, includeContents: string
|
|
|
98
115
|
return relativeIncludeFilePaths;
|
|
99
116
|
}
|
|
100
117
|
|
|
101
|
-
export {
|
|
102
|
-
getFileContributorsMetadata,
|
|
103
|
-
getFileContributorsString,
|
|
104
|
-
};
|
|
118
|
+
export {getFileContributorsMetadata, getFileContributorsString};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
const {
|
|
2
|
+
const {
|
|
3
|
+
promises: {readdir},
|
|
4
|
+
} = require('fs');
|
|
3
5
|
|
|
4
6
|
async function getDirs(path: string) {
|
|
5
7
|
const isDir = (i: any) => i.isDirectory();
|
|
@@ -31,4 +33,14 @@ function concatNewLine(prefix: string, suffix: string) {
|
|
|
31
33
|
return prefix.trim().length ? `${prefix}<br>${suffix}` : suffix;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
export {
|
|
36
|
+
export {
|
|
37
|
+
complement,
|
|
38
|
+
isMdExtension,
|
|
39
|
+
isHidden,
|
|
40
|
+
allPass,
|
|
41
|
+
compose,
|
|
42
|
+
prop,
|
|
43
|
+
getDirs,
|
|
44
|
+
getFiles,
|
|
45
|
+
concatNewLine,
|
|
46
|
+
};
|
|
@@ -31,7 +31,14 @@ type Params = {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
async function includerFunction(params: IncluderFunctionParams<Params>) {
|
|
34
|
-
const {
|
|
34
|
+
const {
|
|
35
|
+
readBasePath,
|
|
36
|
+
writeBasePath,
|
|
37
|
+
tocPath,
|
|
38
|
+
item,
|
|
39
|
+
passedParams: {input, leadingPage},
|
|
40
|
+
index,
|
|
41
|
+
} = params;
|
|
35
42
|
|
|
36
43
|
if (!input?.length || !item.include?.path) {
|
|
37
44
|
throw new GenericIncluderError('provide includer with input parameter', tocPath);
|
|
@@ -42,14 +49,17 @@ async function includerFunction(params: IncluderFunctionParams<Params>) {
|
|
|
42
49
|
|
|
43
50
|
const tocDirPath = dirname(tocPath);
|
|
44
51
|
|
|
45
|
-
const contentPath =
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
const contentPath =
|
|
53
|
+
index === 0
|
|
54
|
+
? join(writeBasePath, tocDirPath, input)
|
|
55
|
+
: join(readBasePath, tocDirPath, input);
|
|
48
56
|
|
|
49
57
|
let cache = {};
|
|
50
58
|
let found = [];
|
|
51
59
|
|
|
52
|
-
({
|
|
60
|
+
({
|
|
61
|
+
state: {found, cache},
|
|
62
|
+
} = await glob(MD_GLOB, {
|
|
53
63
|
cwd: contentPath,
|
|
54
64
|
nosort: true,
|
|
55
65
|
nocase: true,
|
|
@@ -93,9 +103,14 @@ function createGraphFromPaths(paths: string[]) {
|
|
|
93
103
|
|
|
94
104
|
const file = chunks.pop();
|
|
95
105
|
|
|
96
|
-
updateWith(
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
updateWith(
|
|
107
|
+
graph,
|
|
108
|
+
chunks,
|
|
109
|
+
(old) => {
|
|
110
|
+
return old ? {files: [...old.files, file]} : {files: [file]};
|
|
111
|
+
},
|
|
112
|
+
Object,
|
|
113
|
+
);
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
return graph;
|
|
@@ -103,7 +118,10 @@ function createGraphFromPaths(paths: string[]) {
|
|
|
103
118
|
|
|
104
119
|
function createToc(leadingPageName: string, tocName: string) {
|
|
105
120
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
return function createTocRec(
|
|
121
|
+
return function createTocRec(
|
|
122
|
+
graph: Record<string, any>,
|
|
123
|
+
cursor: string[],
|
|
124
|
+
): Record<string, any> {
|
|
107
125
|
const handler = (file: string) => ({
|
|
108
126
|
name: parse(file).name === 'index' ? leadingPageName : file,
|
|
109
127
|
href: join(...cursor, file),
|
|
@@ -23,7 +23,10 @@ type Params = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
async function includerFunction(params: IncluderFunctionParams<Params>) {
|
|
26
|
-
logger.warn(
|
|
26
|
+
logger.warn(
|
|
27
|
+
params.tocPath,
|
|
28
|
+
`sourcedocs inlcuder is getting depricated in favor of generic includer\n${usage}`,
|
|
29
|
+
);
|
|
27
30
|
|
|
28
31
|
await generic.includerFunction(params);
|
|
29
32
|
}
|
|
@@ -73,15 +73,19 @@ type Params = {
|
|
|
73
73
|
};
|
|
74
74
|
|
|
75
75
|
async function includerFunction(params: IncluderFunctionParams<Params>) {
|
|
76
|
-
const {
|
|
76
|
+
const {
|
|
77
|
+
readBasePath,
|
|
78
|
+
writeBasePath,
|
|
79
|
+
tocPath,
|
|
80
|
+
passedParams: {input, output},
|
|
81
|
+
index,
|
|
82
|
+
} = params;
|
|
77
83
|
|
|
78
84
|
if (!input?.length || !output?.length) {
|
|
79
85
|
throw new UnarchiveIncluderError('provide includer with input parameter', tocPath);
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
const contentPath = index === 0
|
|
83
|
-
? join(writeBasePath, input)
|
|
84
|
-
: join(readBasePath, input);
|
|
88
|
+
const contentPath = index === 0 ? join(writeBasePath, input) : join(readBasePath, input);
|
|
85
89
|
|
|
86
90
|
const writePath = join(writeBasePath, output);
|
|
87
91
|
|
|
@@ -40,7 +40,9 @@ class IncludersError extends Error {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function init(custom: Includer[] = []) {
|
|
43
|
-
if (includersMap) {
|
|
43
|
+
if (includersMap) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
44
46
|
|
|
45
47
|
includersMap = {generic, sourcedocs, unarchive};
|
|
46
48
|
|
|
@@ -55,7 +57,7 @@ async function applyIncluders(path: string, item: YfmToc, vars: YfmPreset) {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
if (!includeValid(item.include)) {
|
|
58
|
-
throw new IncludersError(
|
|
60
|
+
throw new IncludersError("include doesn't comply with includers standard", path);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// normalize include mode (includers support link mode only)
|
|
@@ -126,7 +128,7 @@ function includerExists(includer: YfmTocIncluder) {
|
|
|
126
128
|
return includersMap[includer.name as keyof typeof includersMap];
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
export type
|
|
131
|
+
export type ApplyIncluderParams = {
|
|
130
132
|
path: string;
|
|
131
133
|
item: YfmToc;
|
|
132
134
|
includer: Includer;
|
|
@@ -136,7 +138,7 @@ export type applyIncluderParams = {
|
|
|
136
138
|
vars: YfmPreset;
|
|
137
139
|
};
|
|
138
140
|
|
|
139
|
-
async function applyIncluder(args:
|
|
141
|
+
async function applyIncluder(args: ApplyIncluderParams) {
|
|
140
142
|
const {rootInput: readBasePath, input: writeBasePath} = ArgvService.getConfig();
|
|
141
143
|
|
|
142
144
|
const {path, item, includer, passedParams, index, vars} = args;
|
package/src/services/leading.ts
CHANGED
|
@@ -5,13 +5,16 @@ import log from '@diplodoc/transform/lib/log';
|
|
|
5
5
|
|
|
6
6
|
import {ArgvService, PresetService} from './index';
|
|
7
7
|
import {LeadingPage} from '../models';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
filterTextItems,
|
|
10
|
+
filterFiles,
|
|
11
|
+
firstFilterTextItems,
|
|
12
|
+
liquidFields,
|
|
13
|
+
liquidField,
|
|
14
|
+
} from './utils';
|
|
9
15
|
|
|
10
16
|
function filterFile(path: string) {
|
|
11
|
-
const {
|
|
12
|
-
input: inputFolderPath,
|
|
13
|
-
vars,
|
|
14
|
-
} = ArgvService.getConfig();
|
|
17
|
+
const {input: inputFolderPath, vars} = ArgvService.getConfig();
|
|
15
18
|
|
|
16
19
|
const pathToDir = dirname(path);
|
|
17
20
|
const filePath = resolve(inputFolderPath, path);
|
|
@@ -25,26 +28,20 @@ function filterFile(path: string) {
|
|
|
25
28
|
|
|
26
29
|
/* Should remove all links with false expressions */
|
|
27
30
|
try {
|
|
28
|
-
const title = firstFilterTextItems(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{resolveConditions: true},
|
|
32
|
-
);
|
|
31
|
+
const title = firstFilterTextItems(parsedIndex.title, combinedVars, {
|
|
32
|
+
resolveConditions: true,
|
|
33
|
+
});
|
|
33
34
|
parsedIndex.title = liquidField(title, combinedVars, path);
|
|
34
35
|
|
|
35
|
-
const description = filterTextItems(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
{resolveConditions: true},
|
|
39
|
-
);
|
|
36
|
+
const description = filterTextItems(parsedIndex.description, combinedVars, {
|
|
37
|
+
resolveConditions: true,
|
|
38
|
+
});
|
|
40
39
|
parsedIndex.description = liquidFields(description, combinedVars, path);
|
|
41
40
|
|
|
42
41
|
if (parsedIndex.meta?.title) {
|
|
43
|
-
const metaTitle = firstFilterTextItems(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{resolveConditions: true},
|
|
47
|
-
);
|
|
42
|
+
const metaTitle = firstFilterTextItems(parsedIndex.meta.title, combinedVars, {
|
|
43
|
+
resolveConditions: true,
|
|
44
|
+
});
|
|
48
45
|
parsedIndex.meta.title = liquidField(metaTitle, combinedVars, path);
|
|
49
46
|
}
|
|
50
47
|
|
|
@@ -58,15 +55,15 @@ function filterFile(path: string) {
|
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
if (parsedIndex.nav) {
|
|
61
|
-
const navTitle = firstFilterTextItems(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{resolveConditions: true},
|
|
65
|
-
);
|
|
58
|
+
const navTitle = firstFilterTextItems(parsedIndex.nav.title, combinedVars, {
|
|
59
|
+
resolveConditions: true,
|
|
60
|
+
});
|
|
66
61
|
parsedIndex.nav.title = liquidField(navTitle, combinedVars, path);
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
parsedIndex.links = filterFiles(parsedIndex.links, 'links', combinedVars, {
|
|
64
|
+
parsedIndex.links = filterFiles(parsedIndex.links, 'links', combinedVars, {
|
|
65
|
+
resolveConditions: true,
|
|
66
|
+
});
|
|
70
67
|
|
|
71
68
|
parsedIndex.links.forEach((link) => {
|
|
72
69
|
if (link.title) {
|
package/src/services/metadata.ts
CHANGED
|
@@ -35,7 +35,12 @@ async function getContentWithUpdatedMetadata(
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function getContentWithUpdatedStaticMetadata({
|
|
38
|
-
fileContent,
|
|
38
|
+
fileContent,
|
|
39
|
+
sourcePath,
|
|
40
|
+
addSystemMeta,
|
|
41
|
+
addSourcePath,
|
|
42
|
+
resources,
|
|
43
|
+
systemVars,
|
|
39
44
|
}: {
|
|
40
45
|
fileContent: string;
|
|
41
46
|
sourcePath?: string;
|
|
@@ -105,14 +110,22 @@ async function getContentWithUpdatedDynamicMetadata(
|
|
|
105
110
|
const matchAuthor = fileMetadata.match(REGEXP_AUTHOR);
|
|
106
111
|
if (matchAuthor) {
|
|
107
112
|
const matchedAuthor = matchAuthor[0];
|
|
108
|
-
authorMetadata = await updateAuthorMetadataStringByAuthorLogin(
|
|
113
|
+
authorMetadata = await updateAuthorMetadataStringByAuthorLogin(
|
|
114
|
+
matchedAuthor,
|
|
115
|
+
options.vcsConnector,
|
|
116
|
+
);
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
if (!authorMetadata) {
|
|
113
|
-
const {
|
|
121
|
+
const {
|
|
122
|
+
fileData: {tmpInputFilePath, inputFolderPathLength},
|
|
123
|
+
} = options;
|
|
114
124
|
const relativeFilePath = tmpInputFilePath.substring(inputFolderPathLength);
|
|
115
|
-
authorMetadata = await updateAuthorMetadataStringByFilePath(
|
|
125
|
+
authorMetadata = await updateAuthorMetadataStringByFilePath(
|
|
126
|
+
relativeFilePath,
|
|
127
|
+
options.vcsConnector,
|
|
128
|
+
);
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
if (authorMetadata) {
|
|
@@ -158,7 +171,8 @@ function matchMetadata(fileContent: string) {
|
|
|
158
171
|
}
|
|
159
172
|
|
|
160
173
|
async function getContributorsMetadataString(
|
|
161
|
-
options: MetaDataOptions,
|
|
174
|
+
options: MetaDataOptions,
|
|
175
|
+
fileContent: string,
|
|
162
176
|
): Promise<string | undefined> {
|
|
163
177
|
const {isContributorsEnabled, vcsConnector, fileData} = options;
|
|
164
178
|
|
|
@@ -180,10 +194,16 @@ function getUpdatedMetadataString(newMetadatas: string[], defaultMetadata = ''):
|
|
|
180
194
|
const defaultMetadataСarriage = preparedDefaultMetadata ? сarriage : '';
|
|
181
195
|
const updatedMetadata = `${preparedDefaultMetadata}${defaultMetadataСarriage}${newMetadata}`;
|
|
182
196
|
|
|
183
|
-
return `${metadataBorder}${сarriage}${updatedMetadata}${metadataBorder}${
|
|
197
|
+
return `${metadataBorder}${сarriage}${updatedMetadata}${metadataBorder}${
|
|
198
|
+
defaultMetadata.length ? '' : сarriage
|
|
199
|
+
}`;
|
|
184
200
|
}
|
|
185
201
|
|
|
186
|
-
async function getUpdatedMetadata(
|
|
202
|
+
async function getUpdatedMetadata(
|
|
203
|
+
options: MetaDataOptions,
|
|
204
|
+
fileContent: string,
|
|
205
|
+
meta?: Metadata,
|
|
206
|
+
): Promise<Metadata> {
|
|
187
207
|
const {vcsConnector} = options;
|
|
188
208
|
|
|
189
209
|
const newMetadata: Metadata = {
|
|
@@ -203,7 +223,10 @@ async function getUpdatedMetadata(options: MetaDataOptions, fileContent: string,
|
|
|
203
223
|
};
|
|
204
224
|
}
|
|
205
225
|
|
|
206
|
-
async function getContributorsMetadata(
|
|
226
|
+
async function getContributorsMetadata(
|
|
227
|
+
options: MetaDataOptions,
|
|
228
|
+
fileContent: string,
|
|
229
|
+
): Promise<string> {
|
|
207
230
|
const {isContributorsEnabled, vcsConnector, fileData} = options;
|
|
208
231
|
|
|
209
232
|
if (isContributorsEnabled && vcsConnector) {
|
|
@@ -218,7 +241,10 @@ async function getContributorsMetadata(options: MetaDataOptions, fileContent: st
|
|
|
218
241
|
return JSON.stringify([]);
|
|
219
242
|
}
|
|
220
243
|
|
|
221
|
-
async function getAuthorMetadata(
|
|
244
|
+
async function getAuthorMetadata(
|
|
245
|
+
meta: Metadata,
|
|
246
|
+
vcsConnector?: VCSConnector,
|
|
247
|
+
): Promise<string | null> {
|
|
222
248
|
if (meta.author && vcsConnector) {
|
|
223
249
|
const updatedAuthor = await getAuthorDetails(vcsConnector, meta.author);
|
|
224
250
|
|
|
@@ -232,7 +258,6 @@ function getSystemVarsMetadataString(systemVars: object) {
|
|
|
232
258
|
return `__system: ${JSON.stringify(systemVars)}`;
|
|
233
259
|
}
|
|
234
260
|
|
|
235
|
-
|
|
236
261
|
function getAssetsPublicPath(filePath: string) {
|
|
237
262
|
const {input} = ArgvService.getConfig();
|
|
238
263
|
const path: string = resolve(input, filePath);
|
package/src/services/preset.ts
CHANGED
|
@@ -8,8 +8,8 @@ let presetStorage: PresetStorage = new Map();
|
|
|
8
8
|
|
|
9
9
|
function add(parsedPreset: DocPreset, path: string, varsPreset: string) {
|
|
10
10
|
const combinedValues: YfmPreset = {
|
|
11
|
-
...parsedPreset.default || {},
|
|
12
|
-
...parsedPreset[varsPreset] || {},
|
|
11
|
+
...(parsedPreset.default || {}),
|
|
12
|
+
...(parsedPreset[varsPreset] || {}),
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const key = dirname(normalize(path));
|