Skip to content

Commit

Permalink
Make config options snake case, and remove a few
Browse files Browse the repository at this point in the history
  • Loading branch information
irskep committed Aug 28, 2024
1 parent 84e5ac0 commit 468d5d0
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 97 deletions.
18 changes: 10 additions & 8 deletions docs/djockey.yaml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 9 additions & 9 deletions docs/src/basics/configuration.dj
Original file line number Diff line number Diff line change
Expand Up @@ -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']
```
10 changes: 5 additions & 5 deletions docs/src/getting_started.dj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 26 additions & 25 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
},
};
}
Expand All @@ -42,7 +42,7 @@ export function populateConfig(values: Partial<DjockeyConfig>): DjockeyConfig {
...defaults,
...values,
html: { ...defaults.html, ...(values.html || {}) },
outputDir: { ...defaults.outputDir, ...(values.outputDir || {}) },
output_dir: { ...defaults.output_dir, ...(values.output_dir || {}) },
};
}

Expand All @@ -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),
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/engine/executeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/autoTitlePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/linkRewritingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions src/plugins/tableOfContentsPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/versionDirectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/renderers/gfmRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -79,7 +79,7 @@ export class GFMRenderer implements DjockeyRenderer {
context: Record<string, unknown>;
}) {
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);

Expand Down
28 changes: 13 additions & 15 deletions src/renderers/htmlRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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_))
);
}

Expand All @@ -109,13 +107,13 @@ export class HTMLRenderer implements DjockeyRenderer {
context: Record<string, unknown>;
}) {
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<string, string> = {};
Expand All @@ -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_}`),
Expand Down
Loading

0 comments on commit 468d5d0

Please sign in to comment.