2021-01-28 06:16:46 +00:00
|
|
|
#!/usr/bin/env node
|
2021-01-28 21:03:30 +00:00
|
|
|
const path = require("path");
|
|
|
|
const fs = require("vinyl-fs");
|
|
|
|
const map = require("map-stream");
|
|
|
|
const tokenize = require("./tokenize");
|
2021-01-28 23:07:57 +00:00
|
|
|
const toHTML = require("./to-html");
|
|
|
|
|
2021-01-29 22:32:30 +00:00
|
|
|
// TODO: automatically pull these in from gmi.css (also for gmi.css(5))
|
|
|
|
const GMI_CSS_VARS = [
|
|
|
|
"foreground",
|
|
|
|
"background",
|
|
|
|
"p-size",
|
|
|
|
"p-indent",
|
|
|
|
"p-line-height",
|
|
|
|
"a-size",
|
|
|
|
"pre-size",
|
|
|
|
"pre-line-height",
|
|
|
|
"h1-size",
|
|
|
|
"h2-size",
|
|
|
|
"h3-size",
|
|
|
|
"heading-line-height",
|
|
|
|
"ul-size",
|
|
|
|
"ul-line-height",
|
|
|
|
"blockquote-size",
|
|
|
|
"blockquote-line-height",
|
|
|
|
"mono",
|
|
|
|
"serif",
|
|
|
|
"sans-serif",
|
|
|
|
];
|
|
|
|
|
2021-01-28 06:16:46 +00:00
|
|
|
require("yargs")
|
|
|
|
.scriptName("gmi-web")
|
2021-01-29 23:59:12 +00:00
|
|
|
.config()
|
2021-01-28 06:16:46 +00:00
|
|
|
.command(
|
2021-01-29 23:59:12 +00:00
|
|
|
"$0 [files..]",
|
2021-01-28 23:07:57 +00:00
|
|
|
"Convert .gmi to .html. See gmi-web(1) for more details.",
|
2021-01-28 17:56:02 +00:00
|
|
|
(yargs) =>
|
|
|
|
yargs
|
|
|
|
.positional("files", {
|
2021-01-29 00:24:22 +00:00
|
|
|
describe: "The *.gmi files to convert",
|
2021-01-28 17:56:02 +00:00
|
|
|
})
|
|
|
|
.required("files", true)
|
2021-01-29 23:17:25 +00:00
|
|
|
.option("language", {
|
|
|
|
alias: "lang",
|
|
|
|
required: true,
|
|
|
|
type: "string",
|
|
|
|
describe: "Set the document meta language tag",
|
|
|
|
})
|
2021-01-29 00:24:22 +00:00
|
|
|
.option("images", {
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
2021-01-29 22:32:30 +00:00
|
|
|
describe: "Include images",
|
2021-01-29 00:24:22 +00:00
|
|
|
})
|
|
|
|
.option("audio", {
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
2021-01-29 22:32:30 +00:00
|
|
|
describe: "Include audio",
|
2021-01-29 00:24:22 +00:00
|
|
|
})
|
|
|
|
.option("video", {
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
2021-01-29 22:32:30 +00:00
|
|
|
describe: "Include video",
|
2021-01-29 06:15:23 +00:00
|
|
|
})
|
2021-01-28 23:07:57 +00:00
|
|
|
.option("css", {
|
2021-01-28 17:56:02 +00:00
|
|
|
type: "boolean",
|
2021-01-28 23:07:57 +00:00
|
|
|
default: true,
|
2021-01-29 22:32:30 +00:00
|
|
|
describe:
|
|
|
|
"gmi.css is included by default. Use --no-css to for the bare-minimum <style>",
|
2021-01-28 17:56:02 +00:00
|
|
|
}),
|
2021-01-28 06:16:46 +00:00
|
|
|
(argv) => {
|
2021-01-29 22:32:30 +00:00
|
|
|
const override = GMI_CSS_VARS.reduce((style, key) => {
|
|
|
|
if (argv[key]) {
|
|
|
|
style += `--${key}: ${argv[key]};`;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}, "");
|
2021-01-28 23:07:57 +00:00
|
|
|
fs.src(argv.files)
|
|
|
|
.pipe(map(tokenize))
|
2021-01-29 00:24:22 +00:00
|
|
|
.pipe(
|
|
|
|
map(
|
|
|
|
toHTML({
|
2021-01-29 23:17:25 +00:00
|
|
|
...argv,
|
2021-01-29 22:32:30 +00:00
|
|
|
override,
|
2021-01-29 00:24:22 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2021-01-28 23:07:57 +00:00
|
|
|
.pipe(fs.dest((file) => path.dirname(file.path)));
|
2021-01-28 06:16:46 +00:00
|
|
|
}
|
|
|
|
)
|
2021-01-29 22:32:30 +00:00
|
|
|
.showHelpOnFail(true, "Specify --help for available options")
|
2021-01-28 06:16:46 +00:00
|
|
|
.help().argv;
|