From c3c0bdc1997438be54939815392b578dc1449d40 Mon Sep 17 00:00:00 2001 From: Felix Khafizov Date: Fri, 8 Sep 2023 14:58:08 +0300 Subject: [PATCH 1/4] Install `yaml` --- package.json | 3 ++- pnpm-lock.yaml | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 54fc875..0eb9304 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "dependencies": { "github-slugger": "^2.0.0", "typedoc": "0.25.0", - "typedoc-plugin-markdown": "4.0.0-next.20" + "typedoc-plugin-markdown": "4.0.0-next.20", + "yaml": "^2.3.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a0679a0..a090d60 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: typedoc-plugin-markdown: specifier: 4.0.0-next.20 version: 4.0.0-next.20(typedoc@0.25.0) + yaml: + specifier: ^2.3.2 + version: 2.3.2 devDependencies: '@logux/eslint-config': specifier: ^52.0.1 @@ -4607,6 +4610,11 @@ packages: /yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} + /yaml@2.3.2: + resolution: {integrity: sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==} + engines: {node: '>= 14'} + dev: false + /yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} From f8212c09781c9873e6b21ecd1cc8bd99f04e0a39 Mon Sep 17 00:00:00 2001 From: Felix Khafizov Date: Fri, 8 Sep 2023 16:31:09 +0300 Subject: [PATCH 2/4] Add configurable frontmatter for markdown output --- index.js | 21 ++++++++++++++------- test/website-nanostores/astro.config.mjs | 15 +++++++++------ test/website-types/astro.config.mjs | 15 +++++++++------ 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 02d03cb..263a84e 100644 --- a/index.js +++ b/index.js @@ -2,10 +2,11 @@ import { writeFile } from 'node:fs/promises' import { dirname, resolve, sep } from 'node:path' import { fileURLToPath } from 'node:url' import { Application, PageEvent, TSConfigReader } from 'typedoc' +import yaml from 'yaml' const __dirname = dirname(fileURLToPath(import.meta.url)) -const onRendererPageEnd = event => { +const onRendererPageEnd = frontmatter => event => { if (!event.contents) { return } else if (/README\.md$/.test(event.url)) { @@ -13,14 +14,14 @@ const onRendererPageEnd = event => { return } - let frontmatter = `--- + let prepended = `--- title: '${event.model.name}' -layout: '../../../layouts/DocLayout.astro' +${yaml.stringify(frontmatter)} --- ` - event.contents = frontmatter + event.contents + event.contents = prepended + event.contents } const getNavigationFromProject = (baseUrl = '', project) => { @@ -79,11 +80,17 @@ export const initAstroTypedoc = async ({ }) app.options.addReader(new TSConfigReader()) - app.renderer.on(PageEvent.END, event => onRendererPageEnd(event)) let getReflections = async () => await app.convert() - let generateDocs = async (project, pagesDirectory = 'src/pages/docs') => - await app.generateDocs(project, pagesDirectory) + let generateDocs = async ({ + frontmatter, + outputFolder = 'src/pages/docs', + project + }) => { + app.renderer.on(PageEvent.END, onRendererPageEnd(frontmatter)) + + await app.generateDocs(project, outputFolder) + } let generateNavigationJSON = async (project, outputFolder) => { let navigation = getNavigationFromProject(baseUrl, project) diff --git a/test/website-nanostores/astro.config.mjs b/test/website-nanostores/astro.config.mjs index 4f4ca52..eb2ad4f 100644 --- a/test/website-nanostores/astro.config.mjs +++ b/test/website-nanostores/astro.config.mjs @@ -12,13 +12,16 @@ const astroTypedoc = await initAstroTypedoc({ tsconfig: resolve(__dirname, '../../../nanostores/tsconfig.json') }) -const reflections = await astroTypedoc.getReflections() +const project = await astroTypedoc.getReflections() -await astroTypedoc.generateDocs(reflections, 'src/pages/docs') -await astroTypedoc.generateNavigationJSON( - reflections, - resolve(__dirname, './src/') -) +await astroTypedoc.generateDocs({ + frontmatter: { + layout: resolve(__dirname, './src/layouts/DocLayout.astro') + }, + outputFolder: 'src/pages/docs', + project +}) +await astroTypedoc.generateNavigationJSON(project, resolve(__dirname, './src/')) // https://astro.build/config export default defineConfig({}) diff --git a/test/website-types/astro.config.mjs b/test/website-types/astro.config.mjs index 06092a3..e0c99d6 100644 --- a/test/website-types/astro.config.mjs +++ b/test/website-types/astro.config.mjs @@ -12,13 +12,16 @@ const astroTypedoc = await initAstroTypedoc({ tsconfig: resolve(__dirname, '../types/tsconfig.json') }) -const reflections = await astroTypedoc.getReflections() +const project = await astroTypedoc.getReflections() -await astroTypedoc.generateDocs(reflections, 'src/pages/docs') -await astroTypedoc.generateNavigationJSON( - reflections, - resolve(__dirname, './src/') -) +await astroTypedoc.generateDocs({ + frontmatter: { + layout: resolve(__dirname, './src/layouts/DocLayout.astro') + }, + outputFolder: 'src/pages/docs', + project +}) +await astroTypedoc.generateNavigationJSON(project, resolve(__dirname, './src/')) // https://astro.build/config export default defineConfig({}) From ab2a41e00d9139ca5b329a3c8942c4389124bbe4 Mon Sep 17 00:00:00 2001 From: Felix Khafizov Date: Fri, 8 Sep 2023 17:23:11 +0300 Subject: [PATCH 3/4] Rename variable: prepended -> prependix --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 263a84e..6a40071 100644 --- a/index.js +++ b/index.js @@ -14,14 +14,14 @@ const onRendererPageEnd = frontmatter => event => { return } - let prepended = `--- + let prependix = `--- title: '${event.model.name}' ${yaml.stringify(frontmatter)} --- ` - event.contents = prepended + event.contents + event.contents = prependix + event.contents } const getNavigationFromProject = (baseUrl = '', project) => { From 002446fce796d068943f0edf57c77a1ae03b8616 Mon Sep 17 00:00:00 2001 From: Felix Khafizov Date: Mon, 11 Sep 2023 14:04:10 +0300 Subject: [PATCH 4/4] Remove `yaml` dependency --- index.js | 9 ++++++--- package.json | 3 +-- pnpm-lock.yaml | 8 -------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 6a40071..c10192b 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,14 @@ import { writeFile } from 'node:fs/promises' import { dirname, resolve, sep } from 'node:path' import { fileURLToPath } from 'node:url' import { Application, PageEvent, TSConfigReader } from 'typedoc' -import yaml from 'yaml' const __dirname = dirname(fileURLToPath(import.meta.url)) +const objectToFrontmatter = (object = {}) => + Object.entries(object) + .map(([key, value]) => `${key}: ${value}`) + .join('\n') -const onRendererPageEnd = frontmatter => event => { +const onRendererPageEnd = frontmatterObject => event => { if (!event.contents) { return } else if (/README\.md$/.test(event.url)) { @@ -16,7 +19,7 @@ const onRendererPageEnd = frontmatter => event => { let prependix = `--- title: '${event.model.name}' -${yaml.stringify(frontmatter)} +${objectToFrontmatter(frontmatterObject)} --- ` diff --git a/package.json b/package.json index 50d6a2b..a9b4ea4 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "dependencies": { "github-slugger": "^2.0.0", "typedoc": "0.25.0", - "typedoc-plugin-markdown": "4.0.0-next.20", - "yaml": "^2.3.2" + "typedoc-plugin-markdown": "4.0.0-next.20" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd72f8c..8e6fe8a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ importers: typedoc-plugin-markdown: specifier: 4.0.0-next.20 version: 4.0.0-next.20(typedoc@0.25.0) - yaml: - specifier: ^2.3.2 - version: 2.3.2 devDependencies: '@logux/eslint-config': specifier: ^52.0.1 @@ -4552,11 +4549,6 @@ packages: /yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - /yaml@2.3.2: - resolution: {integrity: sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==} - engines: {node: '>= 14'} - dev: false - /yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'}