Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
irskep committed Aug 27, 2024
1 parent 4c58f14 commit 9cea2bd
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
4 changes: 0 additions & 4 deletions docs/djockey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 0 additions & 9 deletions docs/src/basics/configuration.djot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions docs/src/basics/djockey_command.djot
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
order: 0
---
# The `djockey` command

`djockey build <path-to-docs>` 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}
```
4 changes: 0 additions & 4 deletions docs/src/getting_started.djot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
Expand Down
19 changes: 16 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {
resolveConfigFromSingleFile,
} from "./config";
import { executeConfig } from "./engine/executeConfig";
import { ALL_OUTPUT_FORMATS, DjockeyOutputFormat } from "./types";

export function makeArgumentParser() {
const p = new ArgumentParser();
const subparsers = p.add_subparsers({ required: true });
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;
Expand All @@ -24,22 +30,29 @@ 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);
}
const config = fs.statSync(inputPath).isDirectory()
? 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);
}
Expand Down
8 changes: 0 additions & 8 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export function getConfigDefaults(): DjockeyConfig {
djot: true,
gfm: isPandocInstalled,
},
outputFormats: {
html: true,
gfm: isPandocInstalled,
},
numPasses: 1,
siteName: "",

Expand Down Expand Up @@ -135,10 +131,6 @@ export function resolveConfigFromSingleFile(
djot: true,
gfm: getIsPandocInstalled(),
},
outputFormats: {
gfm: false,
html: true,
},
numPasses: 1,
siteName: "",

Expand Down
17 changes: 11 additions & 6 deletions src/engine/executeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ALL_OUTPUT_FORMATS,
DjockeyConfigResolved,
DjockeyDoc,
DjockeyOutputFormat,
DjockeyPlugin,
DjockeyPluginModule,
DjockeyRenderer,
Expand All @@ -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")})`
Expand All @@ -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(
Expand Down Expand Up @@ -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)
);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/autoTitlePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/plugins/tableOfContentsPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type DjockeyConfig = {
fileList?: string[];
urlRoot?: string;
inputFormats: Partial<Record<DjockeyInputFormat, boolean>>;
outputFormats: Partial<Record<DjockeyOutputFormat, boolean>>;
numPasses: number;
siteName: string;

Expand Down

0 comments on commit 9cea2bd

Please sign in to comment.