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
gmi-web.1: gmi-web.1.scd
scdoc < $< > $@
gmi.css.5: gmi.css.5.scd
scdoc < $< > $@
example/test.html: example/test.gmi
./test.sh

16
cli.js
View file

@ -40,7 +40,8 @@ const cli = yargs(process.argv.slice(2))
requiresArg: true,
},
descriptions: {
type: "boolean",
type: "number",
default: 0,
},
css: {
default: "full",
@ -69,13 +70,15 @@ const cli = yargs(process.argv.slice(2))
hidden: true,
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);
Object.keys(CSS_VARS).map((key) => {
cli.option(key, { default: CSS_VARS[key] });
cli.option(key, "core");
cli.option(key, "none");
cli.conflicts(key, "core");
cli.conflicts(key, "none");
return key;
});
cli.group(Object.keys(CSS_VARS), "CSS:");
@ -84,9 +87,6 @@ const argv = cli
.conflicts("author", "body")
.conflicts("descriptions", "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", "lang")
.showHelpOnFail(true)

View file

@ -13,9 +13,9 @@ gmi-web - a bridge between Gemini and HTML
.P
.SH SYNOPSIS
.P
\fBgmi-web\fR [--html \fILANG\fR|--body] <\fIOPTIONS\fR> < [\fIFILE\fR]
\fBgmi-web\fR \fIOPTIONS\fR < \fIFILE\fR
.P
\fBgmi-web\fR [--html \fILANG\fR|--body] <\fIOPTIONS\fR> [\fIFILES\fR]
\fBgmi-web\fR \fIOPTIONS\fR \fIFILES\fR
.P
.SH DESCRIPTION
.P
@ -36,8 +36,7 @@ to adjust the document text direction from "ltr" to "rtl".
.P
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
with an ellipsis at that number of characters, otherwise the whole line will
be used.
with an ellipsis at that number of characters.
.P
Use \fB--author\fR \fINAME\fR to set the author <meta> tag on every file.
.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.
.P
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
.RE
\fB[--image|--audio|--video]\fR \fIEXTENSIONS\fR
@ -80,7 +79,7 @@ gmi-web --html en \\
.fi
.RE
.P
\fB--config\fR [\fIJSON\fR]
\fB--config\fR \fIJSON\fR
.RS 4
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.

View file

@ -6,9 +6,9 @@ gmi-web - a bridge between Gemini and HTML
# SYNOPSIS
*gmi-web* [--html _LANG_|--body] <_OPTIONS_> < [_FILE_]
*gmi-web* _OPTIONS_ < _FILE_
*gmi-web* [--html _LANG_|--body] <_OPTIONS_> [_FILES_]
*gmi-web* _OPTIONS_ _FILES_
# DESCRIPTION
@ -26,8 +26,7 @@ mobile-friendly fashion!
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
with an ellipsis at that number of characters, otherwise the whole line will
be used.
with an ellipsis at that number of characters.
Use *--author* _NAME_ to set the author <meta> tag on every file.
@ -46,7 +45,7 @@ gmi-web --html en \\
will use those styles.
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_
Include media extensions inline. You can provide multiple extensions per flag
@ -59,7 +58,7 @@ gmi-web --html en \\
--audio mp3 ogg < doc.gmi
```
*--config* [_JSON_]
*--config* _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.

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/>

20
html.js
View file

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