title and language meta
This commit is contained in:
parent
24d40581d5
commit
8ea7873403
15
cli.js
15
cli.js
|
@ -39,6 +39,12 @@ require("yargs")
|
|||
describe: "The *.gmi files to convert",
|
||||
})
|
||||
.required("files", true)
|
||||
.option("language", {
|
||||
alias: "lang",
|
||||
required: true,
|
||||
type: "string",
|
||||
describe: "Set the document meta language tag",
|
||||
})
|
||||
.option("images", {
|
||||
type: "boolean",
|
||||
default: false,
|
||||
|
@ -61,6 +67,7 @@ require("yargs")
|
|||
"gmi.css is included by default. Use --no-css to for the bare-minimum <style>",
|
||||
}),
|
||||
(argv) => {
|
||||
console.log(argv)
|
||||
const override = GMI_CSS_VARS.reduce((style, key) => {
|
||||
if (argv[key]) {
|
||||
style += `--${key}: ${argv[key]};`;
|
||||
|
@ -72,13 +79,7 @@ require("yargs")
|
|||
.pipe(
|
||||
map(
|
||||
toHTML({
|
||||
css: argv.css,
|
||||
inline: {
|
||||
images: argv.images,
|
||||
audio: argv.audio,
|
||||
video: argv.video,
|
||||
},
|
||||
verbose: argv.verbose,
|
||||
...argv,
|
||||
override,
|
||||
})
|
||||
)
|
||||
|
|
|
@ -15,6 +15,9 @@ and mobile-friendly fashion!
|
|||
|
||||
# OPTIONS
|
||||
|
||||
*--languge*
|
||||
Required for <meta languge="">
|
||||
|
||||
*CSS Variables*
|
||||
Any variable documented in *gmi.css*(5) can be set via _OPTIONS_ of the same
|
||||
name.
|
||||
|
|
29
to-html.js
29
to-html.js
|
@ -8,14 +8,19 @@ const VIDEO_EXT = (exports.VIDEO_EXT = /\.(mp4|webm)$/);
|
|||
const BASE_STYLE = (exports.baseStyle =
|
||||
"<style>p,a,pre,h1,h2,h3,ul,blockquote,img,audio,video{display:block;max-width:100%;margin:0;padding:0;overflow-wrap:anywhere;}</style>");
|
||||
|
||||
const toHTML = (exports.toHTML = (file, options) => `<!DOCTYPE html>
|
||||
const toHTML = (exports.toHTML = (file, options) => {
|
||||
const tokens = JSON.parse(file.contents.toString("utf8"));
|
||||
const title = tokens[0].h1;
|
||||
return `<!DOCTYPE html>
|
||||
<html style="${options.override}">
|
||||
${head(file.path, options)}
|
||||
${head(file.path, title, options)}
|
||||
<body>
|
||||
${gemtext(JSON.parse(file.contents.toString("utf8")), options)}
|
||||
${gemtext(tokens, options)}
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
`;
|
||||
});
|
||||
|
||||
module.exports = (options) => (file, cb) => {
|
||||
if (!TOKENS_EXT.test(file.path)) return cb(null);
|
||||
file.contents = Buffer.from(toHTML(file, options));
|
||||
|
@ -25,9 +30,10 @@ module.exports = (options) => (file, cb) => {
|
|||
};
|
||||
|
||||
// TODO: meta: language, description, canonical
|
||||
function head(file, options) {
|
||||
function head(file, title, options) {
|
||||
return `<head>
|
||||
<meta charset="utf-8">
|
||||
<meta language="${options.language}">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">${
|
||||
!options.css
|
||||
? BASE_STYLE
|
||||
|
@ -35,7 +41,12 @@ function head(file, options) {
|
|||
path.resolve(__dirname, "./gmi.min.css"),
|
||||
"utf8"
|
||||
)}</style>`
|
||||
}${
|
||||
!options.canonical
|
||||
? ""
|
||||
: `<link rel="canonical" href="gemini://${options.canonical}/${file.replace(TOKENS_EXT, ".gmi")}">`
|
||||
}
|
||||
<title>${title}</title>
|
||||
</head>
|
||||
`;
|
||||
}
|
||||
|
@ -68,15 +79,15 @@ function gemtext(tokens, options) {
|
|||
|
||||
function line(
|
||||
{ text, href, title, pre, alt, h1, h2, h3, li, quote },
|
||||
{ inline }
|
||||
{ images, audio, video }
|
||||
) {
|
||||
if (text) return `<p>${text}</p>`;
|
||||
if (href) {
|
||||
if (inline.images && IMG_EXT.test(href))
|
||||
if (images && IMG_EXT.test(href))
|
||||
return `<img src="${href}" title="${title}"/>`;
|
||||
if (inline.audio && AUDIO_EXT.test(href))
|
||||
if (audio && AUDIO_EXT.test(href))
|
||||
return `<audio controls src="${href}" title="${title}"></audio>`;
|
||||
if (inline.video && VIDEO_EXT.test(href))
|
||||
if (video && VIDEO_EXT.test(href))
|
||||
return `<video controls src="${href}" title="${title}"/></video>`;
|
||||
|
||||
return `<a href="${href}">${title || href}</a>`;
|
||||
|
|
Loading…
Reference in a new issue