diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index c60b55323..000000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": ["@diplodoc/eslint-config"], - "env": { - "node": true - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..ccda1b82e --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,11 @@ +module.exports = { + "extends": ["@diplodoc/eslint-config"], + "root": true, + parserOptions: { + tsconfigRootDir: __dirname, + project: ['./tsconfig.json'], + }, + "env": { + "node": true + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bccfd327..65c3a2d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [4.9.0](https://github.com/diplodoc-platform/cli/compare/v4.8.0...v4.9.0) (2024-01-09) + + +### Features + +* Add updatedAt field in metadata ([#628](https://github.com/diplodoc-platform/cli/issues/628)) ([63f6f5e](https://github.com/diplodoc-platform/cli/commit/63f6f5e1300e4a233e1c547860252562b1fe9772)) + + +### Bug Fixes + +* Update latex extension ([0cd0a5d](https://github.com/diplodoc-platform/cli/commit/0cd0a5dded9b632be0b4a1c097ad0efaf8859d1c)) + ## [4.8.0](https://github.com/diplodoc-platform/cli/compare/v4.7.0...v4.8.0) (2023-12-28) diff --git a/package-lock.json b/package-lock.json index 5824d1e4c..e14c660ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "@diplodoc/cli", - "version": "4.8.0", + "version": "4.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@diplodoc/cli", - "version": "4.8.0", + "version": "4.9.0", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.369.0", "@diplodoc/client": "^2.0.0", - "@diplodoc/latex-extension": "^1.0.2", + "@diplodoc/latex-extension": "^1.0.3", "@diplodoc/markdown-translation": "^1.0.4", "@diplodoc/mermaid-extension": "^1.2.1", "@diplodoc/openapi-extension": "^1.4.10", @@ -1577,10 +1577,11 @@ } }, "node_modules/@diplodoc/latex-extension": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@diplodoc/latex-extension/-/latex-extension-1.0.2.tgz", - "integrity": "sha512-SVXRgkKE3pEBZzHnzNG8hrSE5jrm0aUx3XPfz6g3lODl2EQFl6F5K4FiGHg2rj14vlDB+3XvL8N2yyaq/N+lxw==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@diplodoc/latex-extension/-/latex-extension-1.0.3.tgz", + "integrity": "sha512-KadOWvyeEqKjtWQhkHsUXsbYjUaYQ9He0KPiMxAWXUM/lP2Qm0PHk0jpdsNtwJjuT3tRyrxt+u6vyvfh9TGm5g==", "peerDependencies": { + "katex": "^0.16.9", "markdown-it": "^13.0.0", "react": "^18.2.0" }, @@ -7162,6 +7163,31 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/katex": { + "version": "0.16.9", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.9.tgz", + "integrity": "sha512-fsSYjWS0EEOwvy81j3vRA8TEAhQhKiqO+FQaKWp0m39qwOzHVBgAUBIXWj1pB+O2W3fIpNa6Y9KSKCVbfPhyAQ==", + "funding": [ + "https://opencollective.com/katex", + "https://github.com/sponsors/katex" + ], + "peer": true, + "dependencies": { + "commander": "^8.3.0" + }, + "bin": { + "katex": "cli.js" + } + }, + "node_modules/katex/node_modules/commander": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", + "integrity": "sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==", + "peer": true, + "engines": { + "node": ">= 12" + } + }, "node_modules/keyv": { "version": "4.5.4", "dev": true, diff --git a/package.json b/package.json index 76ab5f66f..6be72af30 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "author": "Yandex Data UI Team ", "description": "Make documentation using yfm-docs in Markdown and HTML formats", "license": "MIT", - "version": "4.8.0", + "version": "4.9.0", "repository": { "type": "git", "url": "git@github.com:diplodoc-platform/cli.git" @@ -32,7 +32,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.369.0", "@diplodoc/client": "^2.0.0", - "@diplodoc/latex-extension": "^1.0.2", + "@diplodoc/latex-extension": "^1.0.3", "@diplodoc/markdown-translation": "^1.0.4", "@diplodoc/mermaid-extension": "^1.2.1", "@diplodoc/openapi-extension": "^1.4.10", diff --git a/src/cmd/build/index.ts b/src/cmd/build/index.ts index d34321cf0..48d466270 100644 --- a/src/cmd/build/index.ts +++ b/src/cmd/build/index.ts @@ -197,8 +197,13 @@ async function handler(args: Arguments) { addMapFile, allowCustomResources, resources, + metadata, } = ArgvService.getConfig(); + if (typeof metadata !== 'undefined' && !Array.isArray(metadata)) { + ArgvService.patch('metadata', [metadata]); + } + preparingTemporaryFolders(userOutputFolder); await processServiceFiles(); @@ -242,9 +247,9 @@ async function handler(args: Arguments) { // collect paths of all resources Object.keys(resources).forEach( (type) => - resources[type as keyof Resources]?.forEach((path: string) => - resourcePaths.push(path), - ), + resources[type as keyof Resources]?.forEach((path) => { + resourcePaths.push(path); + }), ); //copy resources diff --git a/src/models.ts b/src/models.ts index 4f8877da2..915089332 100644 --- a/src/models.ts +++ b/src/models.ts @@ -19,6 +19,7 @@ export type NestedContributorsForPathFunction = ( ) => void; export type UserByLoginFunction = (login: string) => Promise; export type CollectionOfPluginsFunction = (output: string, options: PluginOptions) => string; +export type GetModifiedTimeByPathFunction = (filepath: string) => number | undefined; interface YfmConfig { varsPreset: VarsPreset; @@ -40,6 +41,7 @@ interface YfmConfig { buildDisabled: boolean; lintConfig: LintConfig; resources?: Resources; + metadata?: Record[]; yandexCloudTranslateFolderId: string; yandexCloudTranslateGlossaryPairs: YandexCloudTranslateGlossaryPair[]; } @@ -240,7 +242,7 @@ export interface PathData { } export type Resources = { - [key in ResourceType]?: string[]; + [type in ResourceType]?: string[]; }; export type YandexCloudTranslateGlossaryPair = { diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index ed75c2ad0..43c994198 100644 --- a/src/resolvers/md2html.ts +++ b/src/resolvers/md2html.ts @@ -43,7 +43,7 @@ export async function resolveMd2HTML(options: ResolverOptions): Promise { const {inputPath, outputPath, metadata} = options; - const {input, output} = ArgvService.getConfig(); + const {input, output, metadata: yfmMetadata} = ArgvService.getConfig(); const resolvedInputPath = resolve(input, inputPath); const vars = getVarsPerFile(inputPath); @@ -21,6 +21,7 @@ export async function resolveMd2Md(options: ResolveMd2MdOptions): Promise readFileSync(resolvedInputPath, 'utf8'), metadata, vars.__system, + yfmMetadata, ); const {result, changelogs} = transformMd2Md(content, { diff --git a/src/services/argv.ts b/src/services/argv.ts index 4941a6157..35dce0312 100644 --- a/src/services/argv.ts +++ b/src/services/argv.ts @@ -31,8 +31,13 @@ function set(argv: YfmArgv) { _argv = argv; } +function patch(field: Key, value: YfmArgv[Key]) { + _argv[field] = value; +} + export default { getConfig, init, set, + patch, }; diff --git a/src/services/contributors.ts b/src/services/contributors.ts index 7e2244d78..6d4c2303c 100644 --- a/src/services/contributors.ts +++ b/src/services/contributors.ts @@ -94,7 +94,10 @@ async function getContributorsForNestedFiles( return Object.assign({}, ...includesContributors); } -function getRelativeIncludeFilePaths(fileData: FileData, includeContents: string[]): Set { +function getRelativeIncludeFilePaths( + fileData: Pick, + includeContents: string[], +): Set { const {tmpInputFilePath} = fileData; const relativeIncludeFilePaths: Set = new Set(); @@ -115,4 +118,45 @@ function getRelativeIncludeFilePaths(fileData: FileData, includeContents: string return relativeIncludeFilePaths; } -export {getFileContributorsMetadata, getFileContributorsString}; +async function getFileIncludes( + fileData: Pick, +) { + const {fileContent, tmpInputFilePath, inputFolderPathLength} = fileData; + + const results = new Set(); + + const includeContents = fileContent.match(REGEXP_INCLUDE_CONTENTS); + if (!includeContents || includeContents.length === 0) { + return []; + } + const relativeIncludeFilePaths: Set = getRelativeIncludeFilePaths( + {tmpInputFilePath}, + includeContents, + ); + for (const relativeIncludeFilePath of relativeIncludeFilePaths.values()) { + const relativeFilePath = relativeIncludeFilePath.substring(inputFolderPathLength + 1); + if (results.has(relativeFilePath)) continue; + results.add(relativeFilePath); + + let contentIncludeFile: string; + try { + contentIncludeFile = await readFile(relativeIncludeFilePath, 'utf8'); + } catch (err) { + if (err.code === 'ENOENT') { + continue; + } + throw err; + } + + const includedPaths = await getFileIncludes({ + inputFolderPathLength, + fileContent: contentIncludeFile, + tmpInputFilePath: relativeIncludeFilePath, + }); + includedPaths.forEach((path) => results.add(path)); + } + + return Array.from(results.values()); +} + +export {getFileContributorsMetadata, getFileContributorsString, getFileIncludes}; diff --git a/src/services/metadata.ts b/src/services/metadata.ts index 56a5dcc51..dde5fb472 100644 --- a/src/services/metadata.ts +++ b/src/services/metadata.ts @@ -1,4 +1,4 @@ -import {dump} from 'js-yaml'; +import {dump, load} from 'js-yaml'; import {VCSConnector} from '../vcs-connector/connector-models'; import {MetaDataOptions, Metadata, Resources} from '../models'; @@ -7,17 +7,22 @@ import { updateAuthorMetadataStringByAuthorLogin, updateAuthorMetadataStringByFilePath, } from './authors'; -import {getFileContributorsMetadata, getFileContributorsString} from './contributors'; +import { + getFileContributorsMetadata, + getFileContributorsString, + getFileIncludes, +} from './contributors'; import {isObject} from './utils'; import {сarriage} from '../utils'; import {REGEXP_AUTHOR, metadataBorder} from '../constants'; import {dirname, relative, resolve} from 'path'; -import {ArgvService} from './index'; +import {ArgvService, TocService} from './index'; async function getContentWithUpdatedMetadata( fileContent: string, options?: MetaDataOptions, systemVars?: unknown, + yfmMetadata?: Record[], ): Promise { let result; @@ -28,7 +33,9 @@ async function getContentWithUpdatedMetadata( addSourcePath: options?.addSourcePath, resources: options?.resources, systemVars, + yfmMetadata, }); + result = await getContentWithUpdatedDynamicMetadata(result, options); return result; @@ -41,6 +48,7 @@ function getContentWithUpdatedStaticMetadata({ addSourcePath, resources, systemVars, + yfmMetadata = [], }: { fileContent: string; sourcePath?: string; @@ -48,10 +56,16 @@ function getContentWithUpdatedStaticMetadata({ addSourcePath?: boolean; resources?: Resources; systemVars?: unknown; + yfmMetadata?: Record[]; }): string { const newMetadatas: string[] = []; - if ((!addSystemMeta || !systemVars) && !addSourcePath && !resources) { + if ( + (!addSystemMeta || !systemVars) && + !addSourcePath && + !resources && + yfmMetadata.length === 0 + ) { return fileContent; } @@ -72,8 +86,21 @@ function getContentWithUpdatedStaticMetadata({ if (matches && matches.length > 0) { const [, fileMetadata, , fileMainContent] = matches; + const parsed = load(fileMetadata) as any; + + if (Array.isArray(parsed.metadata)) { + parsed.metadata = [...yfmMetadata, ...parsed.metadata]; + } else if (parsed.metadata) { + parsed.metadata = [...yfmMetadata, parsed.metadata]; + } + + const patchedMetada = dump(parsed); + + return `${getUpdatedMetadataString(newMetadatas, patchedMetada)}${fileMainContent}`; + } - return `${getUpdatedMetadataString(newMetadatas, fileMetadata)}${fileMainContent}`; + if (yfmMetadata.length) { + newMetadatas.push(dump({metadata: yfmMetadata})); } return `${getUpdatedMetadataString(newMetadatas)}${fileContent}`; @@ -105,6 +132,11 @@ async function getContentWithUpdatedDynamicMetadata( newMetadatas.push(contributorsMetaData); } + const mtimeMetadata = await getModifiedTimeMetadataString(options, fileContent); + if (mtimeMetadata) { + newMetadatas.push(mtimeMetadata); + } + let authorMetadata = ''; if (fileMetadata) { const matchAuthor = fileMetadata.match(REGEXP_AUTHOR); @@ -188,6 +220,37 @@ async function getContributorsMetadataString( return undefined; } +async function getModifiedTimeMetadataString(options: MetaDataOptions, fileContent: string) { + const {isContributorsEnabled, vcsConnector, fileData} = options; + + const {tmpInputFilePath, inputFolderPathLength} = fileData; + + const relativeFilePath = tmpInputFilePath.substring(inputFolderPathLength + 1); + + if (!isContributorsEnabled || !vcsConnector) { + return undefined; + } + + const includedFiles = await getFileIncludes({...fileData, fileContent}); + includedFiles.push(relativeFilePath); + + const tocCopyFileMap = TocService.getCopyFileMap(); + + const mtimeList = includedFiles + .map((path) => { + const mappedPath = tocCopyFileMap.get(path) || path; + return vcsConnector.getModifiedTimeByPath(mappedPath); + }) + .filter((v) => typeof v === 'number') as number[]; + + if (mtimeList.length) { + const mtime = Math.max(...mtimeList); + return `updatedAt: ${new Date(mtime * 1000).toISOString()}`; + } + + return undefined; +} + function getUpdatedMetadataString(newMetadatas: string[], defaultMetadata = ''): string { const newMetadata = newMetadatas.join(сarriage) + (newMetadatas.length ? сarriage : ''); const preparedDefaultMetadata = defaultMetadata.trimRight(); diff --git a/src/services/tocs.ts b/src/services/tocs.ts index 61d5fb25a..470443dfa 100644 --- a/src/services/tocs.ts +++ b/src/services/tocs.ts @@ -24,6 +24,7 @@ export interface TocServiceData { const storage: TocServiceData['storage'] = new Map(); let navigationPaths: TocServiceData['navigationPaths'] = []; const includedTocPaths: TocServiceData['includedTocPaths'] = new Set(); +const tocFileCopyMap = new Map(); async function add(path: string) { const { @@ -207,6 +208,10 @@ function _copyTocDir(tocPath: string, destDir: string) { } else { shell.cp(from, to); } + + const relFrom = relative(inputFolderPath, from); + const relTo = relative(inputFolderPath, to); + tocFileCopyMap.set(relTo, relFrom); }); } @@ -396,6 +401,10 @@ function setNavigationPaths(paths: TocServiceData['navigationPaths']) { navigationPaths = paths; } +function getCopyFileMap() { + return tocFileCopyMap; +} + export default { add, getForPath, @@ -403,4 +412,5 @@ export default { getTocDir, getIncludedTocPaths, setNavigationPaths, + getCopyFileMap, }; diff --git a/src/utils/markup.ts b/src/utils/markup.ts index da1781b7b..abdaa76a6 100644 --- a/src/utils/markup.ts +++ b/src/utils/markup.ts @@ -1,8 +1,8 @@ import {join} from 'path'; import {platform} from 'process'; -import {CUSTOM_STYLE, Platforms, ResourceType} from '../constants'; -import {Resources, SinglePageResult} from '../models'; +import {CUSTOM_STYLE, Platforms} from '../constants'; +import {LeadingPage, Resources, SinglePageResult, TextItems} from '../models'; import {ArgvService, PluginService} from '../services'; import {preprocessPageHtmlForSinglePage} from './singlePage'; @@ -10,25 +10,31 @@ import {DocInnerProps, DocPageData, render} from '@diplodoc/client/ssr'; import manifest from '@diplodoc/client/manifest'; const dst = (bundlePath: string) => (target: string) => join(bundlePath, target); +export const сarriage = platform === Platforms.WINDOWS ? '\r\n' : '\n'; export interface TitleMeta { title?: string; } -export type Meta = TitleMeta & Resources; +type YfmMetadata = { + metadata: Record[]; +}; + +export type Meta = TitleMeta & Resources & YfmMetadata; export function generateStaticMarkup( props: DocInnerProps, pathToBundle: string, ): string { - const {title: metaTitle, style, script} = (props.data.meta as Meta) || {}; + const {style, script, metadata, ...restYamlConfigMeta} = (props.data.meta as Meta) || {}; const {title: tocTitle} = props.data.toc; const {title: pageTitle} = props.data; const title = getTitle({ - metaTitle, + metaTitle: props.data.meta.title, tocTitle: tocTitle as string, pageTitle, }); + const resources = getResources({style, script}); const {staticContent} = ArgvService.getConfig(); @@ -40,7 +46,7 @@ export function generateStaticMarkup( - ${getMetadata(props.data.meta as Record)} + ${getMetadata(metadata, restYamlConfigMeta)} ${title} + + + + +
+
+ + + + + + +`; + +exports[`Allow load custom resources md2html with metadata 3`] = ` + + + + + + + + + + Documentation + + + + + + +
+
+ + + + + + +`; + +exports[`Allow load custom resources md2html with metadata 4`] = ` + + + + + + + + + + Documentation + + + + + + +
+
+ + + + + + +`; + +exports[`Allow load custom resources md2md with metadata 1`] = `"[".yfm","index.yaml","page.md","project/config.md","toc.yaml"]"`; + +exports[`Allow load custom resources md2md with metadata 2`] = ` +"metadata: + - name: test-yfm + value: inline test + - name: yfm-config + value: config test +" +`; + +exports[`Allow load custom resources md2md with metadata 3`] = ` +"title: Documentation +description: '' +meta: + title: Documentation + noIndex: true +links: + - title: Getting started with Documentation + description: This guide will show you the basics of working with Documentation + href: page.md +" +`; + +exports[`Allow load custom resources md2md with metadata 4`] = ` +"--- +metadata: + - name: test-yfm + value: inline test + - name: yfm-config + value: config test + - name: yfm + value: builder in page +--- + +Lorem" +`; + +exports[`Allow load custom resources md2md with metadata 5`] = ` +"--- +metadata: + - name: test-yfm + value: inline test + - name: yfm-config + value: config test + - name: yfm + value: builder in config +--- + +Lorem" +`; + +exports[`Allow load custom resources md2md with metadata 6`] = ` +"title: Documentation +href: index.yaml +items: + - name: Documentation + href: page.md + - name: Config + href: project/config.md +base: . +" +`; diff --git a/tests/e2e/metadata.spec.ts b/tests/e2e/metadata.spec.ts new file mode 100644 index 000000000..b941ae27e --- /dev/null +++ b/tests/e2e/metadata.spec.ts @@ -0,0 +1,15 @@ +import {getTestPaths, runYfmDocs, compareDirectories} from '../utils'; + +const geretateMapTestTemplate = (testTitle: string, testRootPath: string, {md2md = true, md2html = true}) => { + test(testTitle, () => { + const {inputPath, outputPath} = getTestPaths(testRootPath); + runYfmDocs(inputPath, outputPath, {md2md, md2html}); + compareDirectories(outputPath); + }); +} + +describe('Allow load custom resources', () => { + geretateMapTestTemplate('md2md with metadata', 'mocks/metadata/md2md-with-metadata', {md2html: false}) + + geretateMapTestTemplate('md2html with metadata', 'mocks/metadata/md2html-with-metadata', {md2md: false}) +}); diff --git a/tests/integrations/services/metadataAuthors.test.ts b/tests/integrations/services/metadataAuthors.test.ts index 674beeae6..5f87da158 100644 --- a/tests/integrations/services/metadataAuthors.test.ts +++ b/tests/integrations/services/metadataAuthors.test.ts @@ -11,6 +11,7 @@ const simpleMetadataFilePath = 'mocks/fileContent/metadata/simpleMetadata.md'; jest.mock('services/contributors', () => ({ getFileContributorsMetadata: () => Promise.resolve(''), + getFileIncludes: () => Promise.resolve([]), })); describe('getContentWithUpdatedMetadata (Authors)', () => { @@ -27,6 +28,7 @@ describe('getContentWithUpdatedMetadata (Authors)', () => { getContributorsByPath: () => Promise.resolve(null), getUserByLogin: () => Promise.resolve(expectedAuthorData), getExternalAuthorByPath: () => expectedAuthorData, + getModifiedTimeByPath: () => undefined, }; describe('should return file content with updated author in metadata', () => { diff --git a/tests/integrations/services/metadataContributors.test.ts b/tests/integrations/services/metadataContributors.test.ts index faaa34642..84e046e4e 100644 --- a/tests/integrations/services/metadataContributors.test.ts +++ b/tests/integrations/services/metadataContributors.test.ts @@ -26,6 +26,7 @@ describe('getContentWithUpdatedMetadata (Contributors)', () => { getContributorsByPath: () => Promise.resolve(null), getUserByLogin: () => Promise.resolve(null), getExternalAuthorByPath: () => null, + getModifiedTimeByPath: () => undefined, }; describe('should return file content with updated contributors in metadata ' + diff --git a/tests/mocks/load-custom-resources/md2html-with-resources/input/page.md b/tests/mocks/load-custom-resources/md2html-with-resources/input/page.md index 0f927d5c4..119b34481 100644 --- a/tests/mocks/load-custom-resources/md2html-with-resources/input/page.md +++ b/tests/mocks/load-custom-resources/md2html-with-resources/input/page.md @@ -1,5 +1,7 @@ --- -meta: some meta +metadata: + - name: yfm + value: builder --- -Lorem \ No newline at end of file +Lorem diff --git a/tests/mocks/load-custom-resources/md2md-with-resources/input/page.md b/tests/mocks/load-custom-resources/md2md-with-resources/input/page.md index 0f927d5c4..119b34481 100644 --- a/tests/mocks/load-custom-resources/md2md-with-resources/input/page.md +++ b/tests/mocks/load-custom-resources/md2md-with-resources/input/page.md @@ -1,5 +1,7 @@ --- -meta: some meta +metadata: + - name: yfm + value: builder --- -Lorem \ No newline at end of file +Lorem diff --git a/tests/mocks/load-custom-resources/single-page-with-resources/input/page.md b/tests/mocks/load-custom-resources/single-page-with-resources/input/page.md index 0f927d5c4..119b34481 100644 --- a/tests/mocks/load-custom-resources/single-page-with-resources/input/page.md +++ b/tests/mocks/load-custom-resources/single-page-with-resources/input/page.md @@ -1,5 +1,7 @@ --- -meta: some meta +metadata: + - name: yfm + value: builder --- -Lorem \ No newline at end of file +Lorem diff --git a/tests/mocks/metadata/md2html-with-metadata/input/.yfm b/tests/mocks/metadata/md2html-with-metadata/input/.yfm new file mode 100644 index 000000000..632e8cf45 --- /dev/null +++ b/tests/mocks/metadata/md2html-with-metadata/input/.yfm @@ -0,0 +1,5 @@ +metadata: + - name: test-yfm + value: inline test + - name: yfm-config + value: config test diff --git a/tests/mocks/metadata/md2html-with-metadata/input/index.yaml b/tests/mocks/metadata/md2html-with-metadata/input/index.yaml new file mode 100644 index 000000000..60f350c8d --- /dev/null +++ b/tests/mocks/metadata/md2html-with-metadata/input/index.yaml @@ -0,0 +1,9 @@ +title: Documentation +description: "" +meta: + title: Documentation + noIndex: true +links: + - title: Getting started with Documentation + description: This guide will show you the basics of working with Documentation + href: page.md diff --git a/tests/mocks/metadata/md2html-with-metadata/input/page.md b/tests/mocks/metadata/md2html-with-metadata/input/page.md new file mode 100644 index 000000000..d5a9a94c4 --- /dev/null +++ b/tests/mocks/metadata/md2html-with-metadata/input/page.md @@ -0,0 +1,7 @@ +--- +metadata: + - name: yfm + value: builder in page +--- + +Lorem \ No newline at end of file diff --git a/tests/mocks/metadata/md2html-with-metadata/input/project/config.md b/tests/mocks/metadata/md2html-with-metadata/input/project/config.md new file mode 100644 index 000000000..2e1519666 --- /dev/null +++ b/tests/mocks/metadata/md2html-with-metadata/input/project/config.md @@ -0,0 +1,7 @@ +--- +metadata: + - name: yfm + value: builder in config +--- + +Lorem \ No newline at end of file diff --git a/tests/mocks/metadata/md2html-with-metadata/input/toc.yaml b/tests/mocks/metadata/md2html-with-metadata/input/toc.yaml new file mode 100644 index 000000000..35f2b4c6c --- /dev/null +++ b/tests/mocks/metadata/md2html-with-metadata/input/toc.yaml @@ -0,0 +1,7 @@ +title: Documentation +href: index.yaml +items: + - name: Documentation + href: page.md + - name: Config + href: project/config.md \ No newline at end of file diff --git a/tests/mocks/metadata/md2md-with-metadata/input/.yfm b/tests/mocks/metadata/md2md-with-metadata/input/.yfm new file mode 100644 index 000000000..632e8cf45 --- /dev/null +++ b/tests/mocks/metadata/md2md-with-metadata/input/.yfm @@ -0,0 +1,5 @@ +metadata: + - name: test-yfm + value: inline test + - name: yfm-config + value: config test diff --git a/tests/mocks/metadata/md2md-with-metadata/input/index.yaml b/tests/mocks/metadata/md2md-with-metadata/input/index.yaml new file mode 100644 index 000000000..60f350c8d --- /dev/null +++ b/tests/mocks/metadata/md2md-with-metadata/input/index.yaml @@ -0,0 +1,9 @@ +title: Documentation +description: "" +meta: + title: Documentation + noIndex: true +links: + - title: Getting started with Documentation + description: This guide will show you the basics of working with Documentation + href: page.md diff --git a/tests/mocks/metadata/md2md-with-metadata/input/page.md b/tests/mocks/metadata/md2md-with-metadata/input/page.md new file mode 100644 index 000000000..d5a9a94c4 --- /dev/null +++ b/tests/mocks/metadata/md2md-with-metadata/input/page.md @@ -0,0 +1,7 @@ +--- +metadata: + - name: yfm + value: builder in page +--- + +Lorem \ No newline at end of file diff --git a/tests/mocks/metadata/md2md-with-metadata/input/project/config.md b/tests/mocks/metadata/md2md-with-metadata/input/project/config.md new file mode 100644 index 000000000..2e1519666 --- /dev/null +++ b/tests/mocks/metadata/md2md-with-metadata/input/project/config.md @@ -0,0 +1,7 @@ +--- +metadata: + - name: yfm + value: builder in config +--- + +Lorem \ No newline at end of file diff --git a/tests/mocks/metadata/md2md-with-metadata/input/toc.yaml b/tests/mocks/metadata/md2md-with-metadata/input/toc.yaml new file mode 100644 index 000000000..35f2b4c6c --- /dev/null +++ b/tests/mocks/metadata/md2md-with-metadata/input/toc.yaml @@ -0,0 +1,7 @@ +title: Documentation +href: index.yaml +items: + - name: Documentation + href: page.md + - name: Config + href: project/config.md \ No newline at end of file diff --git a/tests/units/services/authors.test.ts b/tests/units/services/authors.test.ts index 796fddfba..2a2240a75 100644 --- a/tests/units/services/authors.test.ts +++ b/tests/units/services/authors.test.ts @@ -20,10 +20,11 @@ const author = { const authorByPath: Map = new Map(); const defaultVCSConnector: VCSConnector = { - addNestedContributorsForPath: () => {}, + addNestedContributorsForPath: () => { }, getContributorsByPath: () => Promise.resolve(null), getUserByLogin: () => Promise.resolve(author), getExternalAuthorByPath: (path) => authorByPath.get(path), + getModifiedTimeByPath: () => undefined, }; describe('getAuthorDetails returns author details', () => { diff --git a/tests/units/services/metadata.test.ts b/tests/units/services/metadata.test.ts index ae64e7704..36b2464ef 100644 --- a/tests/units/services/metadata.test.ts +++ b/tests/units/services/metadata.test.ts @@ -25,6 +25,7 @@ const contributorsString: string = replaceDoubleToSingleQuotes(JSON.stringify(co jest.mock('services/contributors', () => ({ getFileContributorsString: () => Promise.resolve(contributorsString), + getFileIncludes: () => Promise.resolve([]), })); const authorString: string = replaceDoubleToSingleQuotes(JSON.stringify(contributorSecond)); @@ -38,6 +39,7 @@ const defaultVCSConnector: VCSConnector = { getContributorsByPath: () => Promise.resolve(null), getUserByLogin: () => Promise.resolve(null), getExternalAuthorByPath: () => null, + getModifiedTimeByPath: () => undefined, }; describe('getUpdatedMetadata', () => { diff --git a/tsconfig.json b/tsconfig.json index 4572080e5..9f6569773 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "extends": "@diplodoc/tsconfig", "compilerOptions": { + "lib": ["ES2019"], "target": "es6", - "moduleResolution": "NodeNext", - "outDir": "build" + "outDir": "build", + "module": "CommonJS" }, "include": ["src"], "exclude": ["node_modules"],