diff --git a/docs/djockey.yaml b/docs/djockey.yaml index 37fcde2..a18c445 100644 --- a/docs/djockey.yaml +++ b/docs/djockey.yaml @@ -1,13 +1,15 @@ -inputDir: src -outputDir: +site_name: "Djockey" +url_root: https://steveasleep.com/djockey + +input_dir: src +output_dir: html: out/html gfm: out/gfm -siteName: "Djockey" -urlRoot: https://steveasleep.com/djockey -projectInfo: + +project_info: version: 0.0.2 - githubURL: https://github.com/irskep/djockey + github_url: https://github.com/irskep/djockey html: - cssIgnorePatterns: ["api/**/*.css"] # ignore TypeDoc CSS - footerText: "©2024 Steve Landey" + ignore_css: ["api/**/*.css"] # ignore TypeDoc CSS + footer_text: "©2024 Steve Landey" diff --git a/docs/src/basics/configuration.dj b/docs/src/basics/configuration.dj index 3e085ca..a9d85d1 100644 --- a/docs/src/basics/configuration.dj +++ b/docs/src/basics/configuration.dj @@ -11,24 +11,24 @@ Djockey is pre-alpha and config options _will_ change. ```yaml # djockey.yaml -siteName: "Your name here" -urlRoot: "https://your-docs-site-here" -projectInfo: +site_name: "Your name here" +url_root: "https://your-docs-site-here" +project_info: version: 0.0.1 - githubURL: https://github.com/your/project -inputDir: "path to your docs" -outputDir: + github_url: https://github.com/your/project +input_dir: "path to your docs" +output_dir: html: "path to your HTML output" gfm: "path to your GitHub Flavored Markdown output" -numPasses: 1 # only touch this if your custom plugin creates new AST nodes +num_passes: 1 # only touch this if your custom plugin creates new AST nodes plugins: ["my-plugin.js"] # Output-specific options html: - footerText: "©2024 You" + footer_text: "©2024 You" # If you use TypeDoc, you'd want to set this to # path/to/typedoc/**/*.css - cssIgnorePatterns: ['some/css/you/dont/want.css'] + ignore_css: ['some/css/you/dont/want.css'] ``` \ No newline at end of file diff --git a/docs/src/getting_started.dj b/docs/src/getting_started.dj index 6ca874b..9a2e63f 100644 --- a/docs/src/getting_started.dj +++ b/docs/src/getting_started.dj @@ -6,15 +6,15 @@ order: 1 Once you've [installed Djockey](#Installation), create a file called `djockey.yaml`{.language-sh} that looks like this: ```yaml -inputDir: path-to-your-docs -outputDir: +input_dir: path-to-your-docs +output_dir: html: docs_out/html gfm: docs_out/gfm -siteName: "Your Name Here" -urlRoot: https://where-docs-will-be-deployed +site_name: "Your Name Here" +url_root: https://where-docs-will-be-deployed html: - footerText: "©2024 You" + footer_text: "©2024 You" ``` Now try running `npx djockey --local`{.language-sh}. Maybe it'll just work! If not, it should tell you what's wrong. diff --git a/src/config.ts b/src/config.ts index 8ea5ff4..c21a712 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,33 +5,33 @@ import url from "url"; import fastGlob from "fast-glob"; import yaml from "js-yaml"; -import { getIsPandocInstalled } from "./pandoc.js"; import { + ALL_INPUT_FORMATS, DjockeyConfig, DjockeyConfigResolved, DjockeyInputFormat, } from "./types.js"; import { getExtensionForInputFormat } from "./input/fileExtensions.js"; +import { getIsPandocInstalled } from "./pandoc.js"; + +export function getNeedsPandoc(fmt: DjockeyInputFormat): boolean { + return fmt !== "djot"; +} export function getConfigDefaults(): DjockeyConfig { - const isPandocInstalled = getIsPandocInstalled(); return { - inputDir: "docs", - outputDir: { + input_dir: "docs", + output_dir: { html: "out/html", gfm: "out/gfm", }, - inputFormats: { - djot: true, - gfm: isPandocInstalled, - }, - numPasses: 1, - siteName: "", + num_passes: 1, + site_name: "", plugins: [], html: { - footerText: "", + footer_text: "", }, }; } @@ -42,7 +42,7 @@ export function populateConfig(values: Partial): DjockeyConfig { ...defaults, ...values, html: { ...defaults.html, ...(values.html || {}) }, - outputDir: { ...defaults.outputDir, ...(values.outputDir || {}) }, + output_dir: { ...defaults.output_dir, ...(values.output_dir || {}) }, }; } @@ -63,10 +63,9 @@ export function resolveConfig( useFileURLRoot: boolean ): DjockeyConfigResolved { let inputExtensions: string[] = []; - for (const format of Object.keys( - config.inputFormats - ) as DjockeyInputFormat[]) { - if (!config.inputFormats[format]) continue; + const isPandocInstalled = getIsPandocInstalled(); + for (const format of ALL_INPUT_FORMATS) { + if (getNeedsPandoc(format) && !isPandocInstalled) continue; inputExtensions = [ ...inputExtensions, ...getExtensionForInputFormat(format), @@ -75,28 +74,30 @@ export function resolveConfig( const result = { ...config, rootPath, - inputDir: absify(rootPath, config.inputDir), - outputDir: { - html: absify(rootPath, config.outputDir.html), - gfm: absify(rootPath, config.outputDir.gfm), + input_dir: absify(rootPath, config.input_dir), + output_dir: { + html: absify(rootPath, config.output_dir.html), + gfm: absify(rootPath, config.output_dir.gfm), }, fileList: fastGlob.sync( - `${absify(rootPath, config.inputDir)}/**/*.(${inputExtensions.join("|")})` + `${absify(rootPath, config.input_dir)}/**/*.(${inputExtensions.join( + "|" + )})` ), }; - const configURLRoot = config.urlRoot; - const fileURLRoot = url.pathToFileURL(result.outputDir.html).toString(); + const configURLRoot = config.url_root; + const fileURLRoot = url.pathToFileURL(result.output_dir.html).toString(); if (useFileURLRoot) { - return { ...result, urlRoot: fileURLRoot }; + return { ...result, url_root: fileURLRoot }; } else if (!configURLRoot) { console.error( `urlRoot is mandatory, though you can pass --local to use file URLs for local testing.` ); throw Error(); } - return { ...result, urlRoot: configURLRoot }; + return { ...result, url_root: configURLRoot }; } export function resolveConfigFromDirectory( diff --git a/src/engine/executeConfig.ts b/src/engine/executeConfig.ts index b6dab23..d3ebdf2 100644 --- a/src/engine/executeConfig.ts +++ b/src/engine/executeConfig.ts @@ -48,9 +48,9 @@ export async function executeConfig( ) { const docSet = await readDocSet(config); console.log( - `Applying transforms (${pluralize(config.numPasses, "pass", "passes")})` + `Applying transforms (${pluralize(config.num_passes, "pass", "passes")})` ); - for (let i = 0; i < config.numPasses; i++) { + for (let i = 0; i < config.num_passes; i++) { await docSet.runPasses(); } docSet.tree = loadDocTree(docSet.docs); @@ -63,7 +63,7 @@ export async function readDocSet( const docs = config.fileList .map((path_) => { console.log("Parsing", path_); - const result = parseDjot(config.inputDir, path_); + const result = parseDjot(config.input_dir, path_); return result; }) .filter((doc) => !!doc); diff --git a/src/plugins/autoTitlePlugin.test.ts b/src/plugins/autoTitlePlugin.test.ts index a765e12..546bda7 100644 --- a/src/plugins/autoTitlePlugin.test.ts +++ b/src/plugins/autoTitlePlugin.test.ts @@ -31,12 +31,11 @@ test("Title is set to first heading by default", () => { const config: DjockeyConfigResolved = { ...getConfigDefaults(), - inputDir: ".", + input_dir: ".", rootPath: ".", - outputDir: { html: "./dist/html", gfm: "./dist/gfm" }, + output_dir: { html: "./dist/html", gfm: "./dist/gfm" }, fileList: ["Test Doc.dj"], - urlRoot: "URL_ROOT", - inputFormats: { djot: true }, + url_root: "URL_ROOT", }; const docSet = new DocSet(config, [new AutoTitlePlugin()], [doc]); docSet.runPasses(); @@ -71,11 +70,11 @@ test("Title is set to frontMatter.title if present", () => { const config: DjockeyConfigResolved = { ...getConfigDefaults(), - inputDir: ".", + input_dir: ".", rootPath: ".", - outputDir: { html: "./dist/html", gfm: "./dist/gfm" }, + output_dir: { html: "./dist/html", gfm: "./dist/gfm" }, fileList: ["Test Doc.dj"], - urlRoot: "URL_ROOT", + url_root: "URL_ROOT", }; const docSet = new DocSet(config, [new AutoTitlePlugin()], [doc]); docSet.runPasses(); diff --git a/src/plugins/linkRewritingPlugin.ts b/src/plugins/linkRewritingPlugin.ts index c9976e9..112ce96 100644 --- a/src/plugins/linkRewritingPlugin.ts +++ b/src/plugins/linkRewritingPlugin.ts @@ -52,7 +52,7 @@ export class LinkRewritingPlugin implements DjockeyPlugin { if (!node.destination) return; const newDestination = this.transformNodeDestination( doc.relativePath, - config.inputDir, + config.input_dir, node.destination, { config: this.config, diff --git a/src/plugins/tableOfContentsPlugin.test.ts b/src/plugins/tableOfContentsPlugin.test.ts index 1b7c956..250aa62 100644 --- a/src/plugins/tableOfContentsPlugin.test.ts +++ b/src/plugins/tableOfContentsPlugin.test.ts @@ -85,13 +85,12 @@ test("Works end-to-end with LinkRewritingPlugin", () => { const config: DjockeyConfigResolved = { ...getConfigDefaults(), - inputDir: ".", - outputDir: { html: "./dist/html", gfm: "./dist/gfm" }, + input_dir: ".", + output_dir: { html: "./dist/html", gfm: "./dist/gfm" }, fileList: ["Test Doc.dj"], - urlRoot: "URL_ROOT", - inputFormats: { djot: true }, + url_root: "URL_ROOT", rootPath: ".", - html: { footerText: "" }, + html: { footer_text: "" }, }; const docSet = new DocSet( config, diff --git a/src/plugins/versionDirectives.ts b/src/plugins/versionDirectives.ts index 337f6fd..6c41b78 100644 --- a/src/plugins/versionDirectives.ts +++ b/src/plugins/versionDirectives.ts @@ -47,7 +47,7 @@ export class VersionDirectivesPlugin implements DjockeyPlugin { constructor(public config: DjockeyConfig) {} onPass_write(doc: DjockeyDoc) { - const projectVersion = this.config.projectInfo?.version; + const projectVersion = this.config.project_info?.version; applyFilter(doc.docs.content, () => ({ div: (node) => { const keyAndValue = getAnyAttribute( diff --git a/src/renderers/gfmRenderer.ts b/src/renderers/gfmRenderer.ts index 3277618..97f272b 100644 --- a/src/renderers/gfmRenderer.ts +++ b/src/renderers/gfmRenderer.ts @@ -55,17 +55,17 @@ export class GFMRenderer implements DjockeyRenderer { config: DjockeyConfigResolved, docs: DjockeyDoc[] ) { - const ignorePatterns = config.static?.copyIgnorePatterns ?? []; + const ignorePatterns = config.static?.ignore ?? []; copyFilesMatchingPattern({ base: templateDir, - dest: config.outputDir.gfm, + dest: config.output_dir.gfm, pattern: "static/**/*", excludePaths: [], excludePatterns: ignorePatterns, }); copyFilesMatchingPattern({ - base: config.inputDir, - dest: config.outputDir.gfm, + base: config.input_dir, + dest: config.output_dir.gfm, pattern: "**/*", excludePaths: docs.map((d) => d.absolutePath), excludePatterns: ignorePatterns, @@ -79,7 +79,7 @@ export class GFMRenderer implements DjockeyRenderer { context: Record; }) { const { config, nj, doc } = args; - const outputPath = `${config.outputDir.gfm}/${doc.relativePath}.md`; + const outputPath = `${config.output_dir.gfm}/${doc.relativePath}.md`; console.log("Rendering", outputPath); ensureParentDirectoriesExist(outputPath); diff --git a/src/renderers/htmlRenderer.ts b/src/renderers/htmlRenderer.ts index 347d971..e1d6712 100644 --- a/src/renderers/htmlRenderer.ts +++ b/src/renderers/htmlRenderer.ts @@ -49,7 +49,7 @@ export class HTMLRenderer implements DjockeyRenderer { const prefix = this.options.relativeLinks ? makePathBackToRoot(sourcePath, { sameDirectoryValue: "" }) - : `${config.urlRoot}/`; + : `${config.url_root}/`; const ext = isLinkToStaticFile ? "" : ".html"; @@ -65,40 +65,38 @@ export class HTMLRenderer implements DjockeyRenderer { config: DjockeyConfigResolved, docs: DjockeyDoc[] ) { - const ignorePatterns = config.static?.copyIgnorePatterns ?? []; + const ignorePatterns = config.static?.ignore ?? []; copyFilesMatchingPattern({ base: templateDir, - dest: config.outputDir.html, + dest: config.output_dir.html, pattern: "static/**/*", excludePaths: [], excludePatterns: ignorePatterns, }); copyFilesMatchingPattern({ - base: config.inputDir, - dest: config.outputDir.html, + base: config.input_dir, + dest: config.output_dir.html, pattern: "**/*", excludePaths: docs.map((d) => d.absolutePath), excludePatterns: ignorePatterns, }); const templateCSSFiles = fastGlob.sync(`${templateDir}/**/*.css`); - const inputCSSFiles = fastGlob.sync(`${config.inputDir}/**/*.css`, { - ignore: (config.html.cssIgnorePatterns ?? []).map( - (pattern) => `**/${pattern}` - ), + const inputCSSFiles = fastGlob.sync(`${config.input_dir}/**/*.css`, { + ignore: (config.html.ignore_css ?? []).map((pattern) => `**/${pattern}`), }); this.cssURLsRelativeToBase = templateCSSFiles .map((path_) => path.relative(templateDir, path_)) .concat( - inputCSSFiles.map((path_) => path.relative(config.inputDir, path_)) + inputCSSFiles.map((path_) => path.relative(config.input_dir, path_)) ); const templateJSFiles = fastGlob.sync(`${templateDir}/**/*.js`); - const inputJSFiles = fastGlob.sync(`${config.inputDir}/**/*.js`); + const inputJSFiles = fastGlob.sync(`${config.input_dir}/**/*.js`); this.jsURLsRelativeToBase = templateJSFiles .map((path_) => path.relative(templateDir, path_)) .concat( - inputJSFiles.map((path_) => path.relative(config.inputDir, path_)) + inputJSFiles.map((path_) => path.relative(config.input_dir, path_)) ); } @@ -109,13 +107,13 @@ export class HTMLRenderer implements DjockeyRenderer { context: Record; }) { const { config, nj, doc } = args; - const outputPath = `${config.outputDir.html}/${doc.relativePath}.html`; + const outputPath = `${config.output_dir.html}/${doc.relativePath}.html`; console.log("Rendering", outputPath); ensureParentDirectoriesExist(outputPath); const baseURL = this.options.relativeLinks ? makePathBackToRoot(doc.relativePath, { sameDirectoryValue: "" }) - : `${config.urlRoot}/`; + : `${config.url_root}/`; const isFileURL = baseURL.startsWith("file://"); const renderedDocs: Record = {}; @@ -130,7 +128,7 @@ export class HTMLRenderer implements DjockeyRenderer { docs: renderedDocs, baseURL, github: { - path: parseGitHubPath(config.projectInfo?.githubURL), + path: parseGitHubPath(config.project_info?.github_url), }, urls: { css: this.cssURLsRelativeToBase.map((path_) => `${baseURL}${path_}`), diff --git a/src/types.ts b/src/types.ts index da52198..0e342ad 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,34 +2,34 @@ import { Doc, Inline } from "@djot/djot"; import { Environment } from "nunjucks"; export type DjockeyConfig = { - inputDir: string; - outputDir: Record; - urlRoot?: string; - inputFormats: Partial>; - numPasses: number; - siteName: string; - - projectInfo?: { + input_dir: string; + output_dir: Record; + url_root?: string; + site_name: string; + + project_info?: { version?: string; - githubURL?: string; + github_url?: string; }; static?: { - copyIgnorePatterns?: string[]; + ignore?: string[]; }; + num_passes: number; + plugins: string[]; html: { - footerText: string; - cssIgnorePatterns?: string[]; + footer_text: string; + ignore_css?: string[]; }; }; export type DjockeyConfigResolved = DjockeyConfig & { rootPath: string; fileList: string[]; - urlRoot: string; + url_root: string; }; export type DjockeyDoc = {