From be2814c2dbe559f5eadf7df959a3edb836fdcc6c Mon Sep 17 00:00:00 2001 From: birman111 Date: Wed, 1 Dec 2021 16:44:25 +0300 Subject: [PATCH] DOCSTOOLS-884: add source path to md metadata when merging --- package-lock.json | 38 ++++++ package.json | 4 +- src/models.ts | 8 +- src/services/metadata.ts | 110 +++++++++++------- src/services/tocs.ts | 24 +++- src/steps/processPages.ts | 5 +- tests/include-toc.test.ts | 16 +++ .../test2/expected-output/fileA.md | 5 + .../test2/expected-output/fileB.md | 11 ++ .../test2/expected-output/fileC.md | 3 + .../test2/expected-output/folder/fileA.md | 3 + .../test2/expected-output/folder/fileB.md | 8 ++ .../test2/expected-output/folder/fileC.md | 3 + .../include-toc/test2/input/folder/fileA.md | 3 + .../include-toc/test2/input/folder/fileB.md | 8 ++ .../expected-output/product1/_includes/inc.md | 4 + .../expected-output/product1/article1.md | 6 + .../test3/expected-output/product1/toc.yaml | 5 + .../product2/overlay1/_includes/inc.md | 4 + .../product2/overlay1/article1.md | 6 + .../product2/overlay2/_includes/inc.md | 4 + .../product2/overlay2/article1.md | 6 + .../product2/overlay3/_includes/inc.md | 4 + .../product2/overlay3/article1.md | 6 + .../test3/expected-output/product2/p2.md | 4 + .../test3/expected-output/product2/toc.yaml | 17 +++ .../input/product1/core/_includes/inc.md | 1 + .../test3/input/product1/core/article1.md | 3 + .../test3/input/product1/core/toc_m.yaml | 2 + .../test3/input/product1/product/toc_p.yaml | 3 + .../include-toc/test3/input/product1/toc.yaml | 3 + .../input/product2/core/_includes/inc.md | 1 + .../test3/input/product2/core/article1.md | 3 + .../test3/input/product2/core/toc_m.yaml | 2 + .../product2/overlay1/product/article1.md | 3 + .../product2/overlay1/product/toc_p.yaml | 3 + .../test3/input/product2/overlay1/toc.yaml | 2 + .../product2/overlay2/product/article1.md | 3 + .../product2/overlay2/product/toc_p.yaml | 3 + .../test3/input/product2/overlay2/toc.yaml | 2 + .../product2/overlay3/product/toc_p.yaml | 3 + .../test3/input/product2/overlay3/toc.yaml | 2 + .../include-toc/test3/input/product2/p2.md | 4 + .../include-toc/test3/input/product2/toc.yaml | 10 ++ 44 files changed, 321 insertions(+), 47 deletions(-) create mode 100644 tests/mocks/include-toc/test3/expected-output/product1/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product1/article1.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product1/toc.yaml create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay1/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay1/article1.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay2/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay2/article1.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay3/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/overlay3/article1.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/p2.md create mode 100644 tests/mocks/include-toc/test3/expected-output/product2/toc.yaml create mode 100644 tests/mocks/include-toc/test3/input/product1/core/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/input/product1/core/article1.md create mode 100644 tests/mocks/include-toc/test3/input/product1/core/toc_m.yaml create mode 100644 tests/mocks/include-toc/test3/input/product1/product/toc_p.yaml create mode 100644 tests/mocks/include-toc/test3/input/product1/toc.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/core/_includes/inc.md create mode 100644 tests/mocks/include-toc/test3/input/product2/core/article1.md create mode 100644 tests/mocks/include-toc/test3/input/product2/core/toc_m.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay1/product/article1.md create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay1/product/toc_p.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay1/toc.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay2/product/article1.md create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay2/product/toc_p.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay2/toc.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay3/product/toc_p.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/overlay3/toc.yaml create mode 100644 tests/mocks/include-toc/test3/input/product2/p2.md create mode 100644 tests/mocks/include-toc/test3/input/product2/toc.yaml diff --git a/package-lock.json b/package-lock.json index 14cda3f3..818b1cd2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5145,6 +5145,16 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "@types/yaml-front-matter": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@types/yaml-front-matter/-/yaml-front-matter-4.1.0.tgz", + "integrity": "sha512-d4YGe2onl1T4VA6QhT4agdxaStOBe/ig9RAFAT1OltytvO2z9Ro69DiwHD2FUwewcjeD9PWEfUeZhw7E9hApcQ==", + "dev": true, + "requires": { + "@types/js-yaml": "*", + "@types/node": "*" + } + }, "@types/yargs": { "version": "15.0.5", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz", @@ -16781,6 +16791,34 @@ "integrity": "sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==", "dev": true }, + "yaml-front-matter": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/yaml-front-matter/-/yaml-front-matter-4.1.1.tgz", + "integrity": "sha512-ULGbghCLsN8Hs8vfExlqrJIe8Hl2TUjD7/zsIGMP8U+dgRXEsDXk4yydxeZJgdGiimP1XB7zhmhOB4/HyfqOyQ==", + "dev": true, + "requires": { + "commander": "^6.2.0", + "js-yaml": "^3.14.1" + }, + "dependencies": { + "commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true + }, + "js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + } + } + }, "yargs": { "version": "15.3.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz", diff --git a/package.json b/package.json index 4f974619..d4662684 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@types/react": "^16.9.23", "@types/react-dom": "^16.9.5", "@types/shelljs": "^0.8.7", + "@types/yaml-front-matter": "^4.1.0", "@types/yargs": "^15.0.4", "@typescript-eslint/eslint-plugin": "^2.27.0", "@typescript-eslint/parser": "^2.29.0", @@ -85,7 +86,8 @@ "ts-jest": "^27.0.5", "typescript": "^3.9.2", "webpack": "^4.42.1", - "webpack-cli": "^3.3.11" + "webpack-cli": "^3.3.11", + "yaml-front-matter": "^4.1.1" }, "husky": { "hooks": { diff --git a/src/models.ts b/src/models.ts index 3c3cd454..67a9868f 100644 --- a/src/models.ts +++ b/src/models.ts @@ -111,9 +111,10 @@ export interface Contributors { } export interface FileData { - tmpInputFilePath: string; - inputFolderPathLength: number; - fileContent: string; + tmpInputFilePath?: string; + inputFolderPathLength?: number; + fileContent?: string; + sourcePath?: string; } export interface MetaDataOptions { @@ -121,6 +122,7 @@ export interface MetaDataOptions { isContributorsEnabled?: boolean; vcsConnector?: VCSConnector; addSystemMeta?: boolean; + addSourcePath?: boolean; } export interface PluginOptions { diff --git a/src/services/metadata.ts b/src/services/metadata.ts index be053e6e..e0f45326 100644 --- a/src/services/metadata.ts +++ b/src/services/metadata.ts @@ -1,3 +1,6 @@ +import {safeLoadFront} from 'yaml-front-matter'; +import {dump} from 'js-yaml'; + import {VCSConnector} from '../vcs-connector/connector-models'; import {Metadata, MetaDataOptions} from '../models'; import {getAuthorDetails, updateAuthorMetadataString} from './authors'; @@ -9,48 +12,74 @@ async function getContentWithUpdatedMetadata( options?: MetaDataOptions, systemVars?: unknown, ): Promise { - if (!options?.isContributorsEnabled && (!options?.addSystemMeta || !systemVars)) { + let result; + + result = getContentWithUpdatedStaticMetadata(fileContent, options, systemVars); + result = await getContentWithUpdatedDynamicMetadata(result, options); + + return result; +} + +function getContentWithUpdatedStaticMetadata( + fileContent: string, + options?: MetaDataOptions, + systemVars?: unknown, +): string { + if (!options || (!options?.addSystemMeta || !systemVars) && !options?.addSourcePath) { return fileContent; } - // Search by format: - // --- - // metaName1: metaValue1 - // metaName2: meta value2 - // incorrectMetadata - // --- - const regexpMetadata = '(?<=-{3}\\r?\\n)((.*\\r?\\n)*)(?=-{3}\\r?\\n)'; - // Search by format: - // --- - // main content 123 - const regexpFileContent = '---((.*[\r?\n]*)*)'; - - const regexpParseFileContent = new RegExp(`${regexpMetadata}${regexpFileContent}`, 'gm'); - const matches = regexpParseFileContent.exec(fileContent); - - const newMetadatas = []; - - if (options) { - const {isContributorsEnabled, addSystemMeta} = options; - - if (addSystemMeta && systemVars && isObject(systemVars)) { - newMetadatas.push(getSystemVarsMetadataString(systemVars)); - } - - if (isContributorsEnabled) { - newMetadatas.push(await getContributorsMetadataString(options, fileContent)); - } - - if (matches && matches.length > 0) { - const [, fileMetadata, , fileMainContent] = matches; - let updatedDefaultMetadata = ''; - - updatedDefaultMetadata = await updateAuthorMetadataString(fileMetadata, options.vcsConnector); - - return `${getUpdatedMetadataString(newMetadatas, updatedDefaultMetadata)}${fileMainContent}`; - } + + const matches = matchMetadata(fileContent); + const newMetadatas: string[] = []; + + const {addSystemMeta, addSourcePath, fileData} = options; + + if (addSystemMeta && systemVars && isObject(systemVars)) { + newMetadatas.push(getSystemVarsMetadataString(systemVars)); + } + + if (addSourcePath && fileData.sourcePath) { + const sourcePathMetadataString = `sourcePath: ${fileData.sourcePath}`; + newMetadatas.push(sourcePathMetadataString); } - return `${getUpdatedMetadataString(newMetadatas)}${fileContent}`; + const {fileMetadata, fileMainContent} = matches; + + return `${getUpdatedMetadataString(newMetadatas, fileMetadata)}${fileMainContent}`; +} + +async function getContentWithUpdatedDynamicMetadata( + fileContent: string, + options?: MetaDataOptions, +): Promise { + if (!options || !options?.isContributorsEnabled) { + return fileContent; + } + + const matches = matchMetadata(fileContent); + const newMetadatas: string[] = []; + + const {isContributorsEnabled} = options; + + if (isContributorsEnabled) { + newMetadatas.push(await getContributorsMetadataString(options, fileContent)); + } + + const {fileMetadata, fileMainContent} = matches; + + const updatedDefaultMetadata = await updateAuthorMetadataString(fileMetadata, options.vcsConnector); + + return `${getUpdatedMetadataString(newMetadatas, updatedDefaultMetadata)}${fileMainContent}`; +} + +function matchMetadata(fileContent: string) { + const {__content: fileMainContent, ...metadata} = safeLoadFront(fileContent); + const fileMetadata = Object.keys(metadata).length ? dump(metadata) : ''; + + return { + fileMainContent, + fileMetadata, + }; } async function getContributorsMetadataString(options: MetaDataOptions, fileContent: string): Promise { @@ -74,7 +103,9 @@ function getUpdatedMetadataString(newMetadatas: string[], defaultMetadata = ''): const metadataBorder = `---${metadataСarriage}`; const newMetadata = newMetadatas.join(metadataСarriage); - const updatedMetadata = `${defaultMetadata}${metadataСarriage}${newMetadata}${metadataСarriage}`; + const preparedDefaultMetadata = defaultMetadata.trimRight(); + const defaultMetadataСarriage = preparedDefaultMetadata ? metadataСarriage : ''; + const updatedMetadata = `${preparedDefaultMetadata}${defaultMetadataСarriage}${newMetadata}${metadataСarriage}`; return `${metadataBorder}${updatedMetadata}${metadataBorder}`; } @@ -130,5 +161,6 @@ function getSystemVarsMetadataString(systemVars: object) { export { getContentWithUpdatedMetadata, + getContentWithUpdatedStaticMetadata, getUpdatedMetadata, }; diff --git a/src/services/tocs.ts b/src/services/tocs.ts index fecc7224..c3b88759 100644 --- a/src/services/tocs.ts +++ b/src/services/tocs.ts @@ -9,6 +9,7 @@ import {getSinglePageAnchorId} from '@doc-tools/transform/lib/utilsFS'; import {bold} from 'chalk'; import {ArgvService, PresetService} from './index'; +import {getContentWithUpdatedStaticMetadata} from './metadata'; import {YfmToc} from '../models'; import {Stage, SINGLE_PAGE_FOLDER, IncludeMode} from '../constants'; import {isExternalHref} from '../utils'; @@ -200,6 +201,8 @@ function _normalizeHref(href: string): string { * @private */ function _copyTocDir(tocPath: string, destDir: string) { + const {input: inputFolderPath} = ArgvService.getConfig(); + const {dir: tocDir} = parse(tocPath); const files: string[] = walkSync(tocDir, { globs: ['**/*.*'], @@ -210,9 +213,24 @@ function _copyTocDir(tocPath: string, destDir: string) { files.forEach((relPath) => { const from = resolve(tocDir, relPath); const to = resolve(destDir, relPath); + const fileExtension = extname(relPath); + const isMdFile = fileExtension === '.md'; shell.mkdir('-p', parse(to).dir); - copyFileSync(from, to); + + if (isMdFile) { + const fileContent = readFileSync(from, 'utf8'); + const sourcePath = relative(inputFolderPath, from); + const fileData = {sourcePath}; + const updatedFileContent = getContentWithUpdatedStaticMetadata(fileContent, { + fileData, + addSourcePath: true, + }); + + writeFileSync(to, updatedFileContent); + } else { + copyFileSync(from, to); + } }); } @@ -320,7 +338,9 @@ function _replaceIncludes(items: YfmToc[], tocDir: string, sourcesDir: string, v includedInlineItems = includedTocItems; } } catch (err) { - log.error(`Error while including toc: ${bold(includeTocPath)} to ${bold(join(tocDir, 'toc.yaml'))}`); + const message = `Error while including toc: ${bold(includeTocPath)} to ${bold(join(tocDir, 'toc.yaml'))}`; + console.log(message, err); + log.error(message); return acc; } finally { delete item.include; diff --git a/src/steps/processPages.ts b/src/steps/processPages.ts index 750413e6..0f9da337 100644 --- a/src/steps/processPages.ts +++ b/src/steps/processPages.ts @@ -175,8 +175,9 @@ async function preparingPagesByOutputFormat( return; } } catch (e) { - console.log(e); - log.error(` No such file or has no access to ${bold(resolvedPathToFile)}`); + const message = `No such file or has no access to ${bold(resolvedPathToFile)}`; + console.log(message, e); + log.error(message); } } diff --git a/tests/include-toc.test.ts b/tests/include-toc.test.ts index 1c371a6b..9d47903c 100644 --- a/tests/include-toc.test.ts +++ b/tests/include-toc.test.ts @@ -34,4 +34,20 @@ describe('Include toc', () => { expect(expectedContent).toEqual(outputContent); } }); + + test('Nested toc inclusions with mixed including modes', () => { + const testRootPath = './tests/mocks/include-toc/test3'; + const {inputPath, outputPath, expectedOutputPath} = getTestPaths(testRootPath); + runYfmDocs(inputPath, outputPath); + + const compareResult = compareDirectories(outputPath, expectedOutputPath); + + if (typeof compareResult === 'boolean') { + expect(true).toEqual(compareResult); + } else { + const {expectedContent, outputContent} = compareResult; + + expect(expectedContent).toEqual(outputContent); + } + }); }); diff --git a/tests/mocks/include-toc/test2/expected-output/fileA.md b/tests/mocks/include-toc/test2/expected-output/fileA.md index eb88b4f4..1168fdb3 100644 --- a/tests/mocks/include-toc/test2/expected-output/fileA.md +++ b/tests/mocks/include-toc/test2/expected-output/fileA.md @@ -1 +1,6 @@ +--- +title: File A +sourcePath: folder/fileA.md +--- + # File A diff --git a/tests/mocks/include-toc/test2/expected-output/fileB.md b/tests/mocks/include-toc/test2/expected-output/fileB.md index 16e71803..aa247056 100644 --- a/tests/mocks/include-toc/test2/expected-output/fileB.md +++ b/tests/mocks/include-toc/test2/expected-output/fileB.md @@ -1 +1,12 @@ +--- +sourcePath: folder/fileB.md +--- # File B + +Lorem Ipsum is simply dummy text of the printing and typesetting industry. + +--- + +Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. + +--- diff --git a/tests/mocks/include-toc/test2/expected-output/fileC.md b/tests/mocks/include-toc/test2/expected-output/fileC.md index f7255f27..e8aec637 100644 --- a/tests/mocks/include-toc/test2/expected-output/fileC.md +++ b/tests/mocks/include-toc/test2/expected-output/fileC.md @@ -1 +1,4 @@ +--- +sourcePath: folder/folder/fileC.md +--- # File C diff --git a/tests/mocks/include-toc/test2/expected-output/folder/fileA.md b/tests/mocks/include-toc/test2/expected-output/folder/fileA.md index eb88b4f4..6588bf93 100644 --- a/tests/mocks/include-toc/test2/expected-output/folder/fileA.md +++ b/tests/mocks/include-toc/test2/expected-output/folder/fileA.md @@ -1 +1,4 @@ +--- +title: File A +--- # File A diff --git a/tests/mocks/include-toc/test2/expected-output/folder/fileB.md b/tests/mocks/include-toc/test2/expected-output/folder/fileB.md index 16e71803..f366a828 100644 --- a/tests/mocks/include-toc/test2/expected-output/folder/fileB.md +++ b/tests/mocks/include-toc/test2/expected-output/folder/fileB.md @@ -1 +1,9 @@ # File B + +Lorem Ipsum is simply dummy text of the printing and typesetting industry. + +--- + +Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. + +--- diff --git a/tests/mocks/include-toc/test2/expected-output/folder/fileC.md b/tests/mocks/include-toc/test2/expected-output/folder/fileC.md index f7255f27..e8aec637 100644 --- a/tests/mocks/include-toc/test2/expected-output/folder/fileC.md +++ b/tests/mocks/include-toc/test2/expected-output/folder/fileC.md @@ -1 +1,4 @@ +--- +sourcePath: folder/folder/fileC.md +--- # File C diff --git a/tests/mocks/include-toc/test2/input/folder/fileA.md b/tests/mocks/include-toc/test2/input/folder/fileA.md index eb88b4f4..6588bf93 100644 --- a/tests/mocks/include-toc/test2/input/folder/fileA.md +++ b/tests/mocks/include-toc/test2/input/folder/fileA.md @@ -1 +1,4 @@ +--- +title: File A +--- # File A diff --git a/tests/mocks/include-toc/test2/input/folder/fileB.md b/tests/mocks/include-toc/test2/input/folder/fileB.md index 16e71803..f366a828 100644 --- a/tests/mocks/include-toc/test2/input/folder/fileB.md +++ b/tests/mocks/include-toc/test2/input/folder/fileB.md @@ -1 +1,9 @@ # File B + +Lorem Ipsum is simply dummy text of the printing and typesetting industry. + +--- + +Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. + +--- diff --git a/tests/mocks/include-toc/test3/expected-output/product1/_includes/inc.md b/tests/mocks/include-toc/test3/expected-output/product1/_includes/inc.md new file mode 100644 index 00000000..296f9862 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product1/_includes/inc.md @@ -0,0 +1,4 @@ +--- +sourcePath: product1/core/_includes/inc.md +--- +This is the core include. \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/expected-output/product1/article1.md b/tests/mocks/include-toc/test3/expected-output/product1/article1.md new file mode 100644 index 00000000..bd6a17a9 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product1/article1.md @@ -0,0 +1,6 @@ +--- +sourcePath: product1/core/article1.md +--- +This is the core content of Article 1. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/expected-output/product1/toc.yaml b/tests/mocks/include-toc/test3/expected-output/product1/toc.yaml new file mode 100644 index 00000000..885da266 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product1/toc.yaml @@ -0,0 +1,5 @@ +title: Product 1 title +items: + - name: Article1 + href: article1.md +base: product1 diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay1/_includes/inc.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay1/_includes/inc.md new file mode 100644 index 00000000..e9833920 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay1/_includes/inc.md @@ -0,0 +1,4 @@ +--- +sourcePath: product2/core/_includes/inc.md +--- +This is the core include. diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay1/article1.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay1/article1.md new file mode 100644 index 00000000..31e0dab3 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay1/article1.md @@ -0,0 +1,6 @@ +--- +sourcePath: product2/overlay1/product/article1.md +--- +This is the overlay content of Article 1 for product 2. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay2/_includes/inc.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay2/_includes/inc.md new file mode 100644 index 00000000..e9833920 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay2/_includes/inc.md @@ -0,0 +1,4 @@ +--- +sourcePath: product2/core/_includes/inc.md +--- +This is the core include. diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay2/article1.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay2/article1.md new file mode 100644 index 00000000..b2b2ad59 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay2/article1.md @@ -0,0 +1,6 @@ +--- +sourcePath: product2/overlay2/product/article1.md +--- +This is the overlay number #2 of Article 1 content for product 2. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay3/_includes/inc.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay3/_includes/inc.md new file mode 100644 index 00000000..e9833920 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay3/_includes/inc.md @@ -0,0 +1,4 @@ +--- +sourcePath: product2/core/_includes/inc.md +--- +This is the core include. diff --git a/tests/mocks/include-toc/test3/expected-output/product2/overlay3/article1.md b/tests/mocks/include-toc/test3/expected-output/product2/overlay3/article1.md new file mode 100644 index 00000000..08330732 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/overlay3/article1.md @@ -0,0 +1,6 @@ +--- +sourcePath: product2/core/article1.md +--- +This is the core content of Article 1. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/expected-output/product2/p2.md b/tests/mocks/include-toc/test3/expected-output/product2/p2.md new file mode 100644 index 00000000..94988cc4 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/p2.md @@ -0,0 +1,4 @@ +This is the product 2 specific article. + +Check here link to [Article1 overlay 1](overlay1/article1.md) +Check here link to [Article1 overlay 2](overlay2/article1.md) \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/expected-output/product2/toc.yaml b/tests/mocks/include-toc/test3/expected-output/product2/toc.yaml new file mode 100644 index 00000000..6ddaf1a2 --- /dev/null +++ b/tests/mocks/include-toc/test3/expected-output/product2/toc.yaml @@ -0,0 +1,17 @@ +title: Product 2 title +items: + - name: P2 Article + href: p2.md + - name: Overlay1 + items: + - name: Article1 + href: overlay1/article1.md + - name: Overlay 2 + items: + - name: Article1 + href: overlay2/article1.md + - name: Overlay 3 + items: + - name: Article1 + href: overlay3/article1.md +base: product2 diff --git a/tests/mocks/include-toc/test3/input/product1/core/_includes/inc.md b/tests/mocks/include-toc/test3/input/product1/core/_includes/inc.md new file mode 100644 index 00000000..2b6506d3 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product1/core/_includes/inc.md @@ -0,0 +1 @@ +This is the core include. \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product1/core/article1.md b/tests/mocks/include-toc/test3/input/product1/core/article1.md new file mode 100644 index 00000000..b906d9f4 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product1/core/article1.md @@ -0,0 +1,3 @@ +This is the core content of Article 1. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/input/product1/core/toc_m.yaml b/tests/mocks/include-toc/test3/input/product1/core/toc_m.yaml new file mode 100644 index 00000000..45cce729 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product1/core/toc_m.yaml @@ -0,0 +1,2 @@ +items: +- include: { mode: merge, path: product/toc_p.yaml } \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product1/product/toc_p.yaml b/tests/mocks/include-toc/test3/input/product1/product/toc_p.yaml new file mode 100644 index 00000000..784a27d8 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product1/product/toc_p.yaml @@ -0,0 +1,3 @@ +items: +- name: Article1 + href: article1.md \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product1/toc.yaml b/tests/mocks/include-toc/test3/input/product1/toc.yaml new file mode 100644 index 00000000..93c630bd --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product1/toc.yaml @@ -0,0 +1,3 @@ +title: Product 1 title +items: +- include: { mode: merge, path: core/toc_m.yaml } diff --git a/tests/mocks/include-toc/test3/input/product2/core/_includes/inc.md b/tests/mocks/include-toc/test3/input/product2/core/_includes/inc.md new file mode 100644 index 00000000..d330c30a --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/core/_includes/inc.md @@ -0,0 +1 @@ +This is the core include. diff --git a/tests/mocks/include-toc/test3/input/product2/core/article1.md b/tests/mocks/include-toc/test3/input/product2/core/article1.md new file mode 100644 index 00000000..b906d9f4 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/core/article1.md @@ -0,0 +1,3 @@ +This is the core content of Article 1. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/input/product2/core/toc_m.yaml b/tests/mocks/include-toc/test3/input/product2/core/toc_m.yaml new file mode 100644 index 00000000..45cce729 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/core/toc_m.yaml @@ -0,0 +1,2 @@ +items: +- include: { mode: merge, path: product/toc_p.yaml } \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay1/product/article1.md b/tests/mocks/include-toc/test3/input/product2/overlay1/product/article1.md new file mode 100644 index 00000000..ffc4b2b8 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay1/product/article1.md @@ -0,0 +1,3 @@ +This is the overlay content of Article 1 for product 2. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/input/product2/overlay1/product/toc_p.yaml b/tests/mocks/include-toc/test3/input/product2/overlay1/product/toc_p.yaml new file mode 100644 index 00000000..784a27d8 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay1/product/toc_p.yaml @@ -0,0 +1,3 @@ +items: +- name: Article1 + href: article1.md \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay1/toc.yaml b/tests/mocks/include-toc/test3/input/product2/overlay1/toc.yaml new file mode 100644 index 00000000..84d0b240 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay1/toc.yaml @@ -0,0 +1,2 @@ +items: +- include: { mode: merge, path: ../core/toc_m.yaml } \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay2/product/article1.md b/tests/mocks/include-toc/test3/input/product2/overlay2/product/article1.md new file mode 100644 index 00000000..7dac5ac4 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay2/product/article1.md @@ -0,0 +1,3 @@ +This is the overlay number #2 of Article 1 content for product 2. + +{% include [x](_includes/inc.md) %} diff --git a/tests/mocks/include-toc/test3/input/product2/overlay2/product/toc_p.yaml b/tests/mocks/include-toc/test3/input/product2/overlay2/product/toc_p.yaml new file mode 100644 index 00000000..784a27d8 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay2/product/toc_p.yaml @@ -0,0 +1,3 @@ +items: +- name: Article1 + href: article1.md \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay2/toc.yaml b/tests/mocks/include-toc/test3/input/product2/overlay2/toc.yaml new file mode 100644 index 00000000..84d0b240 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay2/toc.yaml @@ -0,0 +1,2 @@ +items: +- include: { mode: merge, path: ../core/toc_m.yaml } \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay3/product/toc_p.yaml b/tests/mocks/include-toc/test3/input/product2/overlay3/product/toc_p.yaml new file mode 100644 index 00000000..784a27d8 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay3/product/toc_p.yaml @@ -0,0 +1,3 @@ +items: +- name: Article1 + href: article1.md \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/overlay3/toc.yaml b/tests/mocks/include-toc/test3/input/product2/overlay3/toc.yaml new file mode 100644 index 00000000..84d0b240 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/overlay3/toc.yaml @@ -0,0 +1,2 @@ +items: +- include: { mode: merge, path: ../core/toc_m.yaml } \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/p2.md b/tests/mocks/include-toc/test3/input/product2/p2.md new file mode 100644 index 00000000..94988cc4 --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/p2.md @@ -0,0 +1,4 @@ +This is the product 2 specific article. + +Check here link to [Article1 overlay 1](overlay1/article1.md) +Check here link to [Article1 overlay 2](overlay2/article1.md) \ No newline at end of file diff --git a/tests/mocks/include-toc/test3/input/product2/toc.yaml b/tests/mocks/include-toc/test3/input/product2/toc.yaml new file mode 100644 index 00000000..160e4b0f --- /dev/null +++ b/tests/mocks/include-toc/test3/input/product2/toc.yaml @@ -0,0 +1,10 @@ +title: Product 2 title +items: +- name: P2 Article + href: p2.md +- name: Overlay1 + include: { mode: link, path: overlay1/toc.yaml } +- name: Overlay 2 + include: { mode: link, path: overlay2/toc.yaml } +- name: Overlay 3 + include: { mode: link, path: overlay3/toc.yaml } \ No newline at end of file