round of cleaning

This commit is contained in:
Talon Poole 2021-01-29 06:15:23 +00:00
parent 541c6345e4
commit 34ed5cf36c
7 changed files with 40 additions and 21 deletions

View file

@ -6,18 +6,17 @@ format:
./node_modules/prettier/bin-prettier.js --write gmi.css ./node_modules/prettier/bin-prettier.js --write gmi.css
./node_modules/prettier/bin-prettier.js --write *.js !*.min.js ./node_modules/prettier/bin-prettier.js --write *.js !*.min.js
gmi.min.css: gmi.css
cat $< | ./node_modules/minify/bin/minify.js --css > $@
gmi-web.1: gmi-web.1.scd gmi-web.1: gmi-web.1.scd
scdoc < $< > $@ scdoc < $< > $@
install: gmi-web.1 install: gmi.min.css gmi-web.1
sudo npm link sudo npm link
install -Dm644 gmi-web.1 $(MANDIR)/man1/gmi-web.1 install -Dm644 gmi-web.1 $(MANDIR)/man1/gmi-web.1
minify:
cat gmi.css | ./node_modules/minify/bin/minify.js --css > gmi.min.css
cat gmi.js | ./node_modules/minify/bin/minify.js --js > gmi.min.js
clean: clean:
rm -rf gmi.min.* gmi-web.1 rm -rf gmi.min.* gmi-web.1
.PHONY: install .PHONY: install clean

9
cli.js
View file

@ -8,7 +8,7 @@ const toHTML = require("./to-html");
require("yargs") require("yargs")
.scriptName("gmi-web") .scriptName("gmi-web")
.command( .command(
"$0 [--css] [files..]", "$0 [--css] <files..>",
"Convert .gmi to .html. See gmi-web(1) for more details.", "Convert .gmi to .html. See gmi-web(1) for more details.",
(yargs) => (yargs) =>
yargs yargs
@ -31,6 +31,12 @@ require("yargs")
default: false, default: false,
description: "Include video", description: "Include video",
}) })
.option("silent", {
alias: "s",
type: "boolean",
default: false,
description: "No logging to stdout",
})
.option("css", { .option("css", {
type: "boolean", type: "boolean",
default: true, default: true,
@ -48,6 +54,7 @@ require("yargs")
audio: argv.audio, audio: argv.audio,
video: argv.video, video: argv.video,
}, },
silent: argv.silent,
}) })
) )
) )

View file

@ -1,4 +1,4 @@
gmi-web(1) "1.0.0" gmi-web(1) "0.1.0"
# NAME # NAME
@ -6,11 +6,11 @@ gmi-web - A bridge between Gemini and HTML
# SYNOPSIS # SYNOPSIS
*gmi-web* [--images] [--audio] [--video] [--no-css] _files_ *gmi-web* [_OPTIONS_...] [_FILES_...]
# DESCRIPTION # DESCRIPTION
Convert your Gemini files to semantic HTML styled in a readable, predictable Convert your Gemini _FILES_ to semantic HTML styled in a readable, predictable
and mobile-friendly fashion! and mobile-friendly fashion!
# OPTIONS # OPTIONS
@ -21,6 +21,9 @@ and mobile-friendly fashion!
*--no-css* *--no-css*
Do not include gmi.css in the rendered HTML markup. Do not include gmi.css in the rendered HTML markup.
*--silent*
Do not log anything to stdout
# EXAMPLES # EXAMPLES
The following example will create .html converted files next to their .gmi counterparts on the filesystem. The following example will create .html converted files next to their .gmi counterparts on the filesystem.

15
gmi.css
View file

@ -3,13 +3,18 @@
--background: white; --background: white;
--p-size: 1.25rem; --p-size: 1.25rem;
--p-indent: 0rem; --p-indent: 0rem;
--p-line-height: 1.5;
--a-size: var(--p-size); --a-size: var(--p-size);
--pre-size: 1rem; --pre-size: 1rem;
--pre-line-height: 1;
--h1-size: 3rem; --h1-size: 3rem;
--h2-size: 2.25rem; --h2-size: 2.25rem;
--h3-size: 1.5rem; --h3-size: 1.5rem;
--heading-line-height: 1.25;
--ul-size: var(--p-size); --ul-size: var(--p-size);
--ul-line-height: 1.25;
--blockquote-size: var(--p-size); --blockquote-size: var(--p-size);
--blockquote-line-height: 1.25;
--mono: Consolas, monaco, monospace; --mono: Consolas, monaco, monospace;
--serif: georgia, times, serif; --serif: georgia, times, serif;
--sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir, --sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir,
@ -45,14 +50,14 @@ h1,
h2, h2,
h3 { h3 {
font-family: var(--sans-serif); font-family: var(--sans-serif);
line-height: 1.25; line-height: var(--heading-line-height);
} }
p { p {
font-size: var(--p-size); font-size: var(--p-size);
font-family: var(--serif); font-family: var(--serif);
text-indent: var(--p-indent); text-indent: var(--p-indent);
line-height: 1.5; line-height: var(--p-line-height);
} }
a::before { a::before {
@ -72,7 +77,7 @@ a {
pre { pre {
font-size: var(--pre-size); font-size: var(--pre-size);
font-family: var(--mono); font-family: var(--mono);
line-height: 1; line-height: var(--pre-line-height);
padding: 1.25rem; padding: 1.25rem;
overflow-y: auto; overflow-y: auto;
} }
@ -92,7 +97,7 @@ h3 {
ul { ul {
font-size: var(--p-size); font-size: var(--p-size);
font-family: var(--serif); font-family: var(--serif);
line-height: 1.25; line-height: var(--ul-line-height);
list-style-type: none; list-style-type: none;
} }
@ -107,7 +112,7 @@ li::before {
blockquote { blockquote {
font-size: var(--p-size); font-size: var(--p-size);
font-family: var(--serif); font-family: var(--serif);
line-height: 1.5; line-height: var(--blockquote-line-height);
padding-left: 0.75rem; padding-left: 0.75rem;
} }

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "gmi-web", "name": "gmi-web",
"version": "1.0.0", "version": "0.1.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View file

@ -1,6 +1,6 @@
{ {
"name": "gmi-web", "name": "gmi-web",
"version": "1.0.0", "version": "0.1.0",
"description": "A bridge between the HTML and Gemini", "description": "A bridge between the HTML and Gemini",
"main": "gmi.css", "main": "gmi.css",
"bin": { "bin": {

View file

@ -1,3 +1,5 @@
const fs = require("fs");
const path = require("path");
const TOKENS_EXT = /\.tokens\.json$/; const TOKENS_EXT = /\.tokens\.json$/;
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats // https://developer.mozilla.org/en-US/docs/Web/Media/Formats
const IMG_EXT = /\.(apng|avif|gif|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp)$/; const IMG_EXT = /\.(apng|avif|gif|jpg|jpeg|jfif|pjpeg|pjp|png|svg|webp)$/;
@ -5,15 +7,18 @@ const AUDIO_EXT = /\.(mp3|wav|aac|aacp|mpeg|off|flac)$/;
const VIDEO_EXT = /\.(mp4|webm)$/; const VIDEO_EXT = /\.(mp4|webm)$/;
module.exports = (options) => (file, cb) => { module.exports = (options) => (file, cb) => {
if (!TOKENS_EXT.test(file.path)) return cb(null, file); if (!TOKENS_EXT.test(file.path)) return cb(null);
// TODO: meta: author, copyright, keywords, content-type, language, description, canonical // TODO: meta: language, description, canonical
file.contents = Buffer.from(`<!DOCTYPE html> file.contents = Buffer.from(`<!DOCTYPE html>
<html> <html>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">${ <meta name="viewport" content="width=device-width,initial-scale=1">${
options.css options.css
? '\n<meta name="color-scheme" content="dark light">\n<link rel="stylesheet" href="/gmi.min.css">' ? `\n<meta name="color-scheme" content="dark light">\n<style>${fs.readFileSync(
path.resolve(__dirname, "./gmi.min.css"),
"utf8"
)}</style>`
: "" : ""
} }
<body> <body>
@ -23,6 +28,7 @@ ${toHTML(JSON.parse(file.contents.toString("utf8")), options)}
`); `);
file.path = file.path.replace(TOKENS_EXT, ".html"); file.path = file.path.replace(TOKENS_EXT, ".html");
if (!options.silent) console.log(file.path);
return cb(null, file); return cb(null, file);
}; };
@ -56,7 +62,6 @@ function line(
{ text, href, title, pre, alt, h1, h2, h3, li, quote }, { text, href, title, pre, alt, h1, h2, h3, li, quote },
{ inline } { inline }
) { ) {
console.log(inline)
if (text) return `<p>${text}</p>`; if (text) return `<p>${text}</p>`;
if (href) { if (href) {
if (inline.images && IMG_EXT.test(href)) if (inline.images && IMG_EXT.test(href))