From 9cea2bd9c3e7d0abd97d7f60d2236e579919ac29 Mon Sep 17 00:00:00 2001 From: Steve Landey Date: Tue, 27 Aug 2024 08:40:19 -0700 Subject: [PATCH] Fix #3 --- docs/djockey.yaml | 4 ---- docs/src/basics/configuration.djot | 9 --------- docs/src/basics/djockey_command.djot | 18 ++++++++++++++++++ docs/src/getting_started.djot | 4 ---- src/cli.ts | 19 ++++++++++++++++--- src/config.ts | 8 -------- src/engine/executeConfig.ts | 17 +++++++++++------ src/plugins/autoTitlePlugin.test.ts | 1 - src/plugins/tableOfContentsPlugin.test.ts | 1 - src/types.ts | 1 - 10 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 docs/src/basics/djockey_command.djot diff --git a/docs/djockey.yaml b/docs/djockey.yaml index 22086ab..62be5b7 100644 --- a/docs/djockey.yaml +++ b/docs/djockey.yaml @@ -8,10 +8,6 @@ projectInfo: version: 0.0.1 githubURL: https://github.com/irskep/djockey -outputFormats: - html: true - gfm: false - html: cssIgnorePatterns: ["api/**/*.css"] # ignore TypeDoc CSS footerText: "©2024 Steve Landey" diff --git a/docs/src/basics/configuration.djot b/docs/src/basics/configuration.djot index 7e3f998..c625b0f 100644 --- a/docs/src/basics/configuration.djot +++ b/docs/src/basics/configuration.djot @@ -20,15 +20,6 @@ outputDir: html: "path to your HTML output" gfm: "path to your GitHub Flavored Markdown output" -# Formats all default to 'true' as long as their prerequisites -# are installed (i.e. Pandoc). -inputFormats - djot: true # or false - gfm: true # or false; requires Pandoc -outputFormats: - html: true # or false - gfm: true # or false; requires Pandoc - fileList: ["allowlist of files to include"] # you probably don't need this numPasses: 1 # only touch this if your custom plugin creates new AST nodes diff --git a/docs/src/basics/djockey_command.djot b/docs/src/basics/djockey_command.djot new file mode 100644 index 0000000..373566f --- /dev/null +++ b/docs/src/basics/djockey_command.djot @@ -0,0 +1,18 @@ +--- +order: 0 +--- +# The `djockey` command + +`djockey build ` will output HTML by default. To output GitHub Flavored Markdown instead, pass `--output-format=gfm`. + +```text +usage: djockey build [-h] [--local] [-f {html,gfm}] input + +positional arguments: + input + +optional arguments: + -h, --help show this help message and exit + --local + -f {html,gfm}, --output-format {html,gfm} +``` \ No newline at end of file diff --git a/docs/src/getting_started.djot b/docs/src/getting_started.djot index 3503c51..6ca874b 100644 --- a/docs/src/getting_started.djot +++ b/docs/src/getting_started.djot @@ -13,10 +13,6 @@ outputDir: siteName: "Your Name Here" urlRoot: https://where-docs-will-be-deployed -outputFormats: - html: true - gfm: false # set this to true if you want Markdown output for GitHub - html: footerText: "©2024 You" ``` diff --git a/src/cli.ts b/src/cli.ts index 3484ce0..1e6f633 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -7,6 +7,7 @@ import { resolveConfigFromSingleFile, } from "./config"; import { executeConfig } from "./engine/executeConfig"; +import { ALL_OUTPUT_FORMATS, DjockeyOutputFormat } from "./types"; export function makeArgumentParser() { const p = new ArgumentParser(); @@ -14,6 +15,11 @@ export function makeArgumentParser() { const buildParser = subparsers.add_parser("build"); buildParser.set_defaults({ action: "build" }); buildParser.add_argument("--local", { default: false, action: "store_true" }); + buildParser.add_argument("-f", "--output-format", { + default: [], + choices: ALL_OUTPUT_FORMATS, + action: "append", + }); buildParser.add_argument("input"); return p; @@ -24,14 +30,18 @@ export async function main() { switch (args.action) { case "build": - doBuild(args.input, args.local); + doBuild(args.input, args.local, args.output_format); break; default: throw new Error("Invalid action"); } } -export async function doBuild(inputPath: string, isLocal: boolean) { +export async function doBuild( + inputPath: string, + isLocal: boolean, + outputFormats: DjockeyOutputFormat[] +) { if (!fs.existsSync(inputPath)) { throw new Error("File does not exist: " + inputPath); } @@ -39,7 +49,10 @@ export async function doBuild(inputPath: string, isLocal: boolean) { ? resolveConfigFromDirectory(inputPath, isLocal) : resolveConfigFromSingleFile(inputPath); if (config) { - await executeConfig(config); + await executeConfig( + config, + outputFormats.length ? outputFormats : ["html"] + ); } else { console.error("Couldn't find a config file in", inputPath); } diff --git a/src/config.ts b/src/config.ts index 79c9b8f..10757a0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -25,10 +25,6 @@ export function getConfigDefaults(): DjockeyConfig { djot: true, gfm: isPandocInstalled, }, - outputFormats: { - html: true, - gfm: isPandocInstalled, - }, numPasses: 1, siteName: "", @@ -135,10 +131,6 @@ export function resolveConfigFromSingleFile( djot: true, gfm: getIsPandocInstalled(), }, - outputFormats: { - gfm: false, - html: true, - }, numPasses: 1, siteName: "", diff --git a/src/engine/executeConfig.ts b/src/engine/executeConfig.ts index f91a5b1..1ff8394 100644 --- a/src/engine/executeConfig.ts +++ b/src/engine/executeConfig.ts @@ -10,6 +10,7 @@ import { ALL_OUTPUT_FORMATS, DjockeyConfigResolved, DjockeyDoc, + DjockeyOutputFormat, DjockeyPlugin, DjockeyPluginModule, DjockeyRenderer, @@ -36,7 +37,10 @@ function makeBuiltinPlugins(config: DjockeyConfigResolved): DjockeyPlugin[] { ]; } -export async function executeConfig(config: DjockeyConfigResolved) { +export async function executeConfig( + config: DjockeyConfigResolved, + outputFormats: DjockeyOutputFormat[] +) { const docSet = await readDocSet(config); console.log( `Applying transforms (${pluralize(config.numPasses, "pass", "passes")})` @@ -45,7 +49,7 @@ export async function executeConfig(config: DjockeyConfigResolved) { await docSet.runPasses(); } docSet.tree = loadDocTree(docSet.docs); - writeDocSet(docSet); + writeDocSet(docSet, outputFormats); } export async function readDocSet( @@ -87,10 +91,11 @@ export async function readDocSet( return new DocSet(config, plugins, docs); } -export function writeDocSet(docSet: DocSet) { - for (const format of ALL_OUTPUT_FORMATS) { - if (!docSet.config.outputFormats[format]) continue; - +export function writeDocSet( + docSet: DocSet, + outputFormats: DjockeyOutputFormat[] +) { + for (const format of new Set(outputFormats)) { const templateDir = path.resolve( path.join(__dirname, "..", "..", "templates", format) ); diff --git a/src/plugins/autoTitlePlugin.test.ts b/src/plugins/autoTitlePlugin.test.ts index 42c8562..982fd03 100644 --- a/src/plugins/autoTitlePlugin.test.ts +++ b/src/plugins/autoTitlePlugin.test.ts @@ -36,7 +36,6 @@ test("Title is set to first heading by default", () => { fileList: ["Test Doc.djot"], urlRoot: "URL_ROOT", inputFormats: { djot: true }, - outputFormats: { html: true }, }; const docSet = new DocSet(config, [new AutoTitlePlugin()], [doc]); docSet.runPasses(); diff --git a/src/plugins/tableOfContentsPlugin.test.ts b/src/plugins/tableOfContentsPlugin.test.ts index 1a85a71..3346fa3 100644 --- a/src/plugins/tableOfContentsPlugin.test.ts +++ b/src/plugins/tableOfContentsPlugin.test.ts @@ -88,7 +88,6 @@ test("Works end-to-end with LinkRewritingPlugin", () => { fileList: ["Test Doc.djot"], urlRoot: "URL_ROOT", inputFormats: { djot: true }, - outputFormats: { html: true }, rootPath: ".", html: { footerText: "", linkCSSToInputInsteadOfOutput: false }, }; diff --git a/src/types.ts b/src/types.ts index cc10ee5..7b04648 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,7 +7,6 @@ export type DjockeyConfig = { fileList?: string[]; urlRoot?: string; inputFormats: Partial>; - outputFormats: Partial>; numPasses: number; siteName: string;