@diplodoc/cli 4.19.1 → 4.19.3

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Yandex Data UI Team <data-ui@yandex-team.ru>",
4
4
  "description": "Make documentation using yfm-docs in Markdown and HTML formats",
5
5
  "license": "MIT",
6
- "version": "4.19.1",
6
+ "version": "4.19.3",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git@github.com:diplodoc-platform/cli.git"
@@ -55,12 +55,12 @@
55
55
  "@types/chalk": "2.2.0",
56
56
  "@types/glob": "^8.1.0",
57
57
  "@types/html-escaper": "^3.0.0",
58
- "@types/js-yaml": "4.0.5",
58
+ "@types/js-yaml": "4.0.9",
59
59
  "@types/json-stringify-safe": "^5.0.3",
60
60
  "@types/lodash": "4.14.195",
61
- "@types/mime-types": "2.1.1",
61
+ "@types/mime-types": "2.1.4",
62
62
  "@types/node": "14.*",
63
- "@types/shelljs": "0.8.12",
63
+ "@types/shelljs": "0.8.15",
64
64
  "@types/tar-stream": "^2.2.2",
65
65
  "@types/yargs": "17.0.24",
66
66
  "ajv": "^8.11.0",
@@ -2,9 +2,9 @@ import walkSync from 'walk-sync';
2
2
  import {load} from 'js-yaml';
3
3
  import {readFileSync} from 'fs';
4
4
  import shell from 'shelljs';
5
- import {join, resolve} from 'path';
5
+ import {join, resolve, sep} from 'path';
6
6
 
7
- import {ArgvService} from '../services';
7
+ import {ArgvService, TocService} from '../services';
8
8
  import {checkPathExists, copyFiles, findAllValuesByKeys} from '../utils';
9
9
 
10
10
  import {LINK_KEYS} from '@diplodoc/client/ssr';
@@ -18,6 +18,7 @@ import {
18
18
  YFM_CONFIG_FILENAME,
19
19
  } from '../constants';
20
20
  import {Resources} from '../models';
21
+ import {resolveRelativePath} from '@diplodoc/transform/lib/utilsFS';
21
22
 
22
23
  /**
23
24
  * Processes assets files (everything except .md files)
@@ -60,7 +61,7 @@ function processAssetsHtmlRun({outputBundlePath}) {
60
61
  }
61
62
 
62
63
  function processAssetsMdRun({args, tmpOutputFolder}) {
63
- const {allowCustomResources, resources} = ArgvService.getConfig();
64
+ const {input: inputFolderPath, allowCustomResources, resources} = ArgvService.getConfig();
64
65
 
65
66
  const pathToConfig = args.config || join(args.input, YFM_CONFIG_FILENAME);
66
67
  const pathToRedirects = join(args.input, REDIRECTS_FILENAME);
@@ -82,14 +83,16 @@ function processAssetsMdRun({args, tmpOutputFolder}) {
82
83
  copyFiles(args.input, tmpOutputFolder, resourcePaths);
83
84
  }
84
85
 
85
- const yamlFiles: string[] = walkSync(args.input, {
86
- globs: ['**/*.yaml'],
87
- directories: false,
88
- includeBasePath: true,
89
- ignore: ['**/toc.yaml', resolve(pathToRedirects)],
90
- });
86
+ const tocYamlFiles = TocService.getNavigationPaths().reduce((acc, file) => {
87
+ if (file.endsWith('.yaml')) {
88
+ const resolvedPathToFile = resolve(inputFolderPath, file);
91
89
 
92
- yamlFiles.forEach((yamlFile) => {
90
+ acc.push(resolvedPathToFile);
91
+ }
92
+ return acc;
93
+ }, []);
94
+
95
+ tocYamlFiles.forEach((yamlFile) => {
93
96
  const content = load(readFileSync(yamlFile, 'utf8'));
94
97
 
95
98
  if (!Object.prototype.hasOwnProperty.call(content, 'blocks')) {
@@ -97,17 +100,25 @@ function processAssetsMdRun({args, tmpOutputFolder}) {
97
100
  }
98
101
 
99
102
  const contentLinks = findAllValuesByKeys(content, LINK_KEYS);
100
- const localMediaLinks = contentLinks.filter(
101
- (link) =>
102
- new RegExp(/^\S.*\.(svg|png|gif|jpg|jpeg|bmp|webp|ico)$/gm).test(link) &&
103
- isLocalUrl(link),
103
+ const localMediaLinks = contentLinks.reduce(
104
+ (acc, link) => {
105
+ const linkHasMediaExt = new RegExp(
106
+ /^\S.*\.(svg|png|gif|jpg|jpeg|bmp|webp|ico)$/gm,
107
+ ).test(link);
108
+
109
+ if (linkHasMediaExt && isLocalUrl(link) && checkPathExists(link, yamlFile)) {
110
+ const linkAbsolutePath = resolveRelativePath(yamlFile, link);
111
+ const linkRootPath = linkAbsolutePath.replace(`${inputFolderPath}${sep}`, '');
112
+
113
+ acc.push(linkRootPath);
114
+ }
115
+ return acc;
116
+ },
117
+
118
+ [],
104
119
  );
105
120
 
106
- copyFiles(
107
- args.input,
108
- tmpOutputFolder,
109
- localMediaLinks.filter((link) => checkPathExists(link, yamlFile)),
110
- );
121
+ copyFiles(args.input, tmpOutputFolder, localMediaLinks);
111
122
  });
112
123
  }
113
124