configurable --descriptions truncation

This commit is contained in:
Talon Poole 2021-02-15 22:56:53 +00:00
parent e5bb1fa77c
commit 965195afe3
7 changed files with 30 additions and 224 deletions

View file

@ -1,12 +1,9 @@
build: gmi-web.1 gmi.css.5 build: gmi-web.1
npm install npm install
gmi-web.1: gmi-web.1.scd gmi-web.1: gmi-web.1.scd
scdoc < $< > $@ scdoc < $< > $@
gmi.css.5: gmi.css.5.scd
scdoc < $< > $@
example/test.html: example/test.gmi example/test.html: example/test.gmi
./test.sh ./test.sh

16
cli.js
View file

@ -40,7 +40,8 @@ const cli = yargs(process.argv.slice(2))
requiresArg: true, requiresArg: true,
}, },
descriptions: { descriptions: {
type: "boolean", type: "number",
default: 0,
}, },
css: { css: {
default: "full", default: "full",
@ -69,13 +70,15 @@ const cli = yargs(process.argv.slice(2))
hidden: true, hidden: true,
default: false, default: false,
}, },
}); })
.group(["html", "body"], "Core:")
.group(["author", "descriptions", "css", "mode", "dir"], "HTML:")
.group(["image", "audio", "video"], "Inline Media:");
const CSS_VARS = CSS.rootVariables(CSS.FULL); const CSS_VARS = CSS.rootVariables(CSS.FULL);
Object.keys(CSS_VARS).map((key) => { Object.keys(CSS_VARS).map((key) => {
cli.option(key, { default: CSS_VARS[key] }); cli.option(key, { default: CSS_VARS[key] });
cli.option(key, "core"); cli.conflicts(key, "core");
cli.option(key, "none"); cli.conflicts(key, "none");
return key; return key;
}); });
cli.group(Object.keys(CSS_VARS), "CSS:"); cli.group(Object.keys(CSS_VARS), "CSS:");
@ -84,9 +87,6 @@ const argv = cli
.conflicts("author", "body") .conflicts("author", "body")
.conflicts("descriptions", "body") .conflicts("descriptions", "body")
.conflicts("html", "body") .conflicts("html", "body")
.group(["html", "body"], "Core:")
.group(["author", "descriptions", "css", "mode", "dir"], "HTML:")
.group(["image", "audio", "video"], "Inline Media:")
.alias("html", "language") .alias("html", "language")
.alias("html", "lang") .alias("html", "lang")
.showHelpOnFail(true) .showHelpOnFail(true)

View file

@ -13,9 +13,9 @@ gmi-web - a bridge between Gemini and HTML
.P .P
.SH SYNOPSIS .SH SYNOPSIS
.P .P
\fBgmi-web\fR [--html \fILANG\fR|--body] <\fIOPTIONS\fR> < [\fIFILE\fR] \fBgmi-web\fR \fIOPTIONS\fR < \fIFILE\fR
.P .P
\fBgmi-web\fR [--html \fILANG\fR|--body] <\fIOPTIONS\fR> [\fIFILES\fR] \fBgmi-web\fR \fIOPTIONS\fR \fIFILES\fR
.P .P
.SH DESCRIPTION .SH DESCRIPTION
.P .P
@ -36,8 +36,7 @@ to adjust the document text direction from "ltr" to "rtl".
.P .P
Use \fB--descriptions\fR \fILIMIT\fR to apply the first non-empty text line of each Use \fB--descriptions\fR \fILIMIT\fR to apply the first non-empty text line of each
file as the description <meta> tag. \fILIMIT\fR will be used to truncate the text file as the description <meta> tag. \fILIMIT\fR will be used to truncate the text
with an ellipsis at that number of characters, otherwise the whole line will with an ellipsis at that number of characters.
be used.
.P .P
Use \fB--author\fR \fINAME\fR to set the author <meta> tag on every file. Use \fB--author\fR \fINAME\fR to set the author <meta> tag on every file.
.P .P
@ -62,7 +61,7 @@ with CSS 2.1's Normal Flow and inline elements. Pointing to a .css \fIFILE\fR
will use those styles. will use those styles.
.P .P
Choosing \fBnone\fR will not include any style information including when paired Choosing \fBnone\fR will not include any style information including when paired
with \fB--body\fR where it will NOT apply the core inline styles. with \fB--body\fR where it will not apply the core inline styles.
.P .P
.RE .RE
\fB[--image|--audio|--video]\fR \fIEXTENSIONS\fR \fB[--image|--audio|--video]\fR \fIEXTENSIONS\fR
@ -80,7 +79,7 @@ gmi-web --html en \\
.fi .fi
.RE .RE
.P .P
\fB--config\fR [\fIJSON\fR] \fB--config\fR \fIJSON\fR
.RS 4 .RS 4
All the options documented here and by \fB--help\fR may be captured in a .json All the options documented here and by \fB--help\fR may be captured in a .json
file and passed to \fB--config\fR instead of as flags on the command-line. file and passed to \fB--config\fR instead of as flags on the command-line.

View file

@ -6,9 +6,9 @@ gmi-web - a bridge between Gemini and HTML
# SYNOPSIS # SYNOPSIS
*gmi-web* [--html _LANG_|--body] <_OPTIONS_> < [_FILE_] *gmi-web* _OPTIONS_ < _FILE_
*gmi-web* [--html _LANG_|--body] <_OPTIONS_> [_FILES_] *gmi-web* _OPTIONS_ _FILES_
# DESCRIPTION # DESCRIPTION
@ -26,8 +26,7 @@ mobile-friendly fashion!
Use *--descriptions* _LIMIT_ to apply the first non-empty text line of each Use *--descriptions* _LIMIT_ to apply the first non-empty text line of each
file as the description <meta> tag. _LIMIT_ will be used to truncate the text file as the description <meta> tag. _LIMIT_ will be used to truncate the text
with an ellipsis at that number of characters, otherwise the whole line will with an ellipsis at that number of characters.
be used.
Use *--author* _NAME_ to set the author <meta> tag on every file. Use *--author* _NAME_ to set the author <meta> tag on every file.
@ -46,7 +45,7 @@ gmi-web --html en \\
will use those styles. will use those styles.
Choosing *none* will not include any style information including when paired Choosing *none* will not include any style information including when paired
with *--body* where it will NOT apply the core inline styles. with *--body* where it will not apply the core inline styles.
*[--image|--audio|--video]* _EXTENSIONS_ *[--image|--audio|--video]* _EXTENSIONS_
Include media extensions inline. You can provide multiple extensions per flag Include media extensions inline. You can provide multiple extensions per flag
@ -59,7 +58,7 @@ gmi-web --html en \\
--audio mp3 ogg < doc.gmi --audio mp3 ogg < doc.gmi
``` ```
*--config* [_JSON_] *--config* _JSON_
All the options documented here and by *--help* may be captured in a .json All the options documented here and by *--help* may be captured in a .json
file and passed to *--config* instead of as flags on the command-line. file and passed to *--config* instead of as flags on the command-line.

102
gmi.css.5
View file

@ -1,102 +0,0 @@
.\" Generated by scdoc 1.10.1
.\" Complete documentation for this program is not available as a GNU info page
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.nh
.ad l
.\" Begin generated content:
.TH "gmi.css" "5" "2021-02-12" "1.0.0-rc.2"
.P
.SH NAME
.P
\fBgmi.css\fR - stylesheet for Gemini generated HTML.
.P
.SH VARIABLES
.P
.nf
.RS 4
--body-width: 48rem;
--foreground: black;
--background: white;
--p-size: 1\&.25rem;
--p-indent: 0rem;
--p-line-height: 1\&.5;
--a-size: var(--p-size);
--pre-size: 1rem;
--pre-line-height: 1;
--h1-size: 3rem;
--h2-size: 2\&.25rem;
--h3-size: 1\&.5rem;
--heading-line-height: 1\&.25;
--ul-size: var(--p-size);
--ul-line-height: 1\&.25;
--blockquote-size: var(--p-size);
--blockquote-line-height: 1\&.25;
--mono: Consolas, monaco, monospace;
--serif: georgia, times, serif;
--sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir,
helvetica, "helvetica neue", ubuntu, roboto, noto, "segoe ui", arial,
sans-serif;
.fi
.RE
.P
Any of the variables can be customized by adding a style attribute to the
<html> element.
.P
.nf
.RS 4
<html style="--foreground:#555555; --background:#9EEBCF;">
.fi
.RE
.P
The \fB--foreground\fR and \fB--background\fR variables will be inverted when
\fBprefers-color-scheme\fR is "dark".
https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
.P
.SH USAGE
.P
The simplest way to use gmi.css is to include a link to it in the <head> of
your <html> document.
.P
.nf
.RS 4
<link rel="stylesheet" type="text/css" href="gmi\&.css">
.fi
.RE
.P
It could also be minimized and/or included directly in a <style> tag.
.P
.SH SEE ALSO
.P
\fBgmi-web\fR(1)
.P
.SH AUTHORS
.P
Maintained by Talon Poole <code@talon.computer>. Up-to-date sources can be
found at https://codeberg.org/talon/gmi-web
.P
.SH COPYRIGHT
This is free and unencumbered software released into the public domain.
.P
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
.P
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
.P
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
.P
For more information, please refer to <http://unlicense.org/>

View file

@ -1,89 +0,0 @@
gmi.css(5) "1.0.0-rc.2"
# NAME
*gmi.css* - stylesheet for Gemini generated HTML.
# VARIABLES
```
--body-width: 48rem;
--foreground: black;
--background: white;
--p-size: 1.25rem;
--p-indent: 0rem;
--p-line-height: 1.5;
--a-size: var(--p-size);
--pre-size: 1rem;
--pre-line-height: 1;
--h1-size: 3rem;
--h2-size: 2.25rem;
--h3-size: 1.5rem;
--heading-line-height: 1.25;
--ul-size: var(--p-size);
--ul-line-height: 1.25;
--blockquote-size: var(--p-size);
--blockquote-line-height: 1.25;
--mono: Consolas, monaco, monospace;
--serif: georgia, times, serif;
--sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir,
helvetica, "helvetica neue", ubuntu, roboto, noto, "segoe ui", arial,
sans-serif;
```
Any of the variables can be customized by adding a style attribute to the
<html> element.
```
<html style="--foreground:#555555; --background:#9EEBCF;">
```
The *--foreground* and *--background* variables will be inverted when
*prefers-color-scheme* is "dark".
https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
# USAGE
The simplest way to use gmi.css is to include a link to it in the <head> of
your <html> document.
```
<link rel="stylesheet" type="text/css" href="gmi.css">
```
It could also be minimized and/or included directly in a <style> tag.
# SEE ALSO
*gmi-web*(1)
# AUTHORS
Maintained by Talon Poole <code@talon.computer>. Up-to-date sources can be
found at https://codeberg.org/talon/gmi-web
# COPYRIGHT
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

12
html.js
View file

@ -11,7 +11,8 @@ const truncate = (text, limit) =>
export function toHTML(gemtext, options) { export function toHTML(gemtext, options) {
const tokens = gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups); const tokens = gemtext.split("\n").map((line) => GMI_REGEX.exec(line).groups);
let description = options.descriptions let description =
options.descriptions > 0
? tokens.find((token) => { ? tokens.find((token) => {
return token.text && token.text !== ""; return token.text && token.text !== "";
}) })
@ -24,7 +25,8 @@ export function toHTML(gemtext, options) {
<head>${head( <head>${head(
Object.assign(options, { Object.assign(options, {
title: tokens[0].h1, title: tokens[0].h1,
description: description && truncate(description.text, 200), description:
description && truncate(description.text, options.descriptions),
}) })
)}</head> )}</head>
<body> <body>
@ -44,15 +46,15 @@ ${
: "" : ""
}${style(options.css)} }${style(options.css)}
<title>${options.title}</title>${ <title>${options.title}</title>${
!options.author ? "" : `<meta name="author" content="${options.author}">` !options.author ? "" : `\n<meta name="author" content="${options.author}">`
}${ }${
!options.description !options.description
? "" ? ""
: `<meta name="description" content="${escape(options.description)}">` : `\n<meta name="description" content="${escape(options.description)}">`
}${ }${
!options.canonical !options.canonical
? "" ? ""
: `<link rel="canonical" href="${options.canonical}">` : `\n<link rel="canonical" href="${options.canonical}">`
} }
`; `;
} }