From 1432dbfeb7d079eea2bdcc303d69bb6c8415cda9 Mon Sep 17 00:00:00 2001 From: Nova Date: Thu, 24 Jun 2021 13:08:43 -0300 Subject: [PATCH] More or less the same , but XD --- .gitignore | 4 + LICENSE | 15 ++ README.md | 62 +++++++ TODO | 1 + generate.sh | 301 ++++++++++++++++++++++++++++++++++ output/print.css | 22 +++ output/style.css | 67 ++++++++ pages/001-html-example.html | 1 + pages/001-html-example.sh | 13 ++ pages/002-markdown-example.md | 61 +++++++ pages/002-markdown-example.sh | 14 ++ 11 files changed, 561 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 TODO create mode 100755 generate.sh create mode 100644 output/print.css create mode 100644 output/style.css create mode 100644 pages/001-html-example.html create mode 100755 pages/001-html-example.sh create mode 100644 pages/002-markdown-example.md create mode 100755 pages/002-markdown-example.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1e2e14 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin +output/*.xml +output/*.html +output/urllist.txt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bc60bd7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2011-2016 Hiltjo Posthuma + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4fc1b1c --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +static site scripts +=================== + + +Description +----- + +This is a fork of the [original project](http://git.codemadness.org/static-site-scripts/log.html) enabling XHTML 1.1 support made by Nova. + +Default values were left blank on this variant. + +Usage +----- + +sh generate.sh + + +Features +-------- + +- Small and simple to understand (I hope). +- Small amount of dependencies, requires a POSIX shell and basic Linux/Unix + utilities[1][2]. +- Markdown supported by default[0], easily extendable to add your + \. +- RSS and Atom output support. +- Sitemap support (sitemap.xml and urllist.txt). + + +Pages +----- + +Pages are defined as shellscripts containing the metadata, for example +the file pages/html-example.sh. +The content filename is the basename of the shellscript with the type of +markup file appended to it (.html or .md), for example the file +pages/html-example.html. + +Markdown is supported. By default "smu"[0] is set as a Markdown processor, +to change this set $markdown to your favorite Markdown-to-HTML converter in +the file generate.sh. + + +Dependencies +------------ + +cat, cut, date, mkdir, printf, read, sed, sh (POSIX), test, tr + + +License +------- + +ISC, see LICENSE file. + + +References +---------- + +[0] smu - markdown processor: https://github.com/Gottox/smu +[1] sbase - http://git.suckless.org/sbase/ + ubase - http://git.suckless.org/ubase/ +[2] busybox - http://www.busybox.net/ diff --git a/TODO b/TODO new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/TODO @@ -0,0 +1 @@ + diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..5577dd1 --- /dev/null +++ b/generate.sh @@ -0,0 +1,301 @@ +#!/bin/sh +# site title (part of ${pagetitle} probably). +sitetitle="" +# site language. +sitelang="en" +# main site domain. +sitedomain="" +# relative site url, can be "/blog" or something. +siteurlrel="" +# full site url. +siteurlfull="${sitedomain}${siteurlrel}" +# site keywords (global default), don't use too many. +sitekeywords="" +# site description (global default). +sitedescription="" +# site mail used for contact "mail link". +sitemail="" +# site author (global). +siteauthor="" +# site last updated (default use date when script was run). +siteupdated=$(date "+%Y-%m-%dT%H:%M:%SZ") +# site owner's projects url (can be github or anything) +siteprojects="" +# directories containing content and metadata. +# NOTE: it's recommended to use absolute paths here, use "." for current directory. +pagesdir="pages" +# Output dir. +outputdir="output" +# Markdown processor: default: is "smu". +markdown="smu" + +#gnudate(fmt,date) +gnudate() { + date "+$1" -d "$2" +} + +#bsddate(fmt,date) +bsddate() { + date -j "+$1" "$(printf '%s' "$2" | tr -Cd '[:digit:]')" +} + +# added for compatibility with GNU and BSD date. +alias formatdate='gnudate' +if ! gnudate '%Y' '2015-01-01 00:00' 2>/dev/null; then + alias formatdate='bsddate' +fi + +#makeid(title), format "Some title" to "some-title". +makeid() { + printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | \ + sed -e 's@[^[:alnum:]]\{1,\}@-@g' -e 's@-*$@@g' -e 's@^-*@@g' +} + +# initial values for page variables, use some site vars as global defaults. +pagereset() { + id="" + title="" + url="" + description="${sitedescription}" + keywords="${sitekeywords}" + author="${siteauthor}" + content="" + tags="" + categories="" + timecreated="" + datecreated="" + timeupdated="" + dateupdated="" +} + +pageread() { + meta="$1" + . "${meta}" # source page metadata. + basename=$(basename "${meta}" ".sh") + datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10) + dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10) + + # if ${id} is empty and title is set: create id based on title. + if test -z "${id}" && test -n "${title}"; then + id=$(makeid "${title}") + fi + if test -z "${id}"; then + printf 'Warning: $id or $title not set in "%s", skipping...\n' "${meta}" >&2 + return 1 + fi + if test -z "${url}"; then + url="${id}.html" + fi + outfile="${id}.html" + urlfull="${siteurlfull}/${outfile}" + filename="" + # ${content} not set; try data from filetypes. + if test -z "${content}"; then + if test -f "${pagesdir}/${basename}.html"; then + filename="${pagesdir}/${basename}.html" + content=$(cat "${filename}") + elif test -f "${pagesdir}/${basename}.md"; then + filename="${pagesdir}/${basename}.md" + content=$("${markdown}" "${filename}") + fi + fi + created="Created on: ${datecreated}
" + if test "${datecreated}" != "${dateupdated}"; then + created="${created}Last update on: ${dateupdated}
" + fi +} + +pageheader() { + # prefix page title with site title, make sure its neatly formatted. + if test -z "${title}"; then + pagetitle="${sitetitle}" + else + pagetitle="${title} - ${sitetitle}" + fi + cat < + + + ${pagetitle} + + + + + + + + + + + + + + + +
+
+!__EOF__ +} + +pagecontent() { + pageheader + cat <${title} + ${created} + ${content} +!__EOF__ + pagefooter +} + +pagefooter() { + cat < +
+ + +!__EOF__ +} + +if ! test -d "${pagesdir}"; then + printf 'Error: pages directory "%s" not found.\n' "${pagesdir}" >&2 + exit 1 +fi + +# process single page as argument (handy for testing a single page). +if test -n "$1"; then + pagereset + pageread "$1" || exit 1 + pagecontent + exit 0 +fi + +# try to make output dir. +mkdir -p "${outputdir}" + +# truncate urllist.txt (sitemap). +> "${outputdir}/urllist.txt" +# content for RSS, Atom sitemap and index, this is appended as a string. +contentindex="" +contentrss="" +contentatom="" +contentsitemap="" +while read -r meta; do + pagereset + pageread "${meta}" || continue + pagecontent > "${outputdir}/${outfile}" + + # index / posts item: append. + contentindex="${contentindex}$(cat <${dateupdated} + ${title} +!__EOF__ +)" + + # RSS item: append. + # NOTE: GMT timezone is hard-coded because %z is not consistent, + # change accordingly. + contentrsspubdate=$(formatdate "%a, %d %b %Y %H:%M:%S GMT" "${timeupdated}") + contentrss="${contentrss}$( + cat < + ${title} + ${urlfull} + ${contentrsspubdate} + ${author} + ${urlfull} + + +!__EOF__ +)" + + # Atom item: append. + contentatomupdated=$(formatdate "%Y-%m-%dT%H:%M:%SZ" "${timeupdated}") + contentatompublished=$(formatdate "%Y-%m-%dT%H:%M:%SZ" "${timecreated}") + contentatom="${contentatom}$( + cat < + <![CDATA[${title}]]> + + ${urlfull} + ${contentatomupdated} + ${contentatompublished} + + ${author} + ${siteurlfull} + + + +!__EOF__ +)" + + # sitemap: sitemap.xml, append item. + contentsitemap="${contentsitemap}${urlfull}" + + # sitemap: urllist.txt, append item, write directly to file, because + # this is just a plain-text list. + printf '%s\n' "${urlfull}" >> "${outputdir}/urllist.txt" +done <${title} + + ${contentindex} +
+!__EOF__ +pagefooter) > "${outputdir}/index.html" + +# RSS feed (rss.xml). +cat < "${outputdir}/rss.xml" + + + + ${sitetitle} + ${siteurlfull} + ${sitedescription} + ${sitelang} + ${contentrss} + + +!__EOF__ + +# Atom feed (atom.xml). +cat < "${outputdir}/atom.xml" + + + ${sitetitle} + ${sitedescription} + ${siteupdated} + + ${siteurlfull}/atom.xml + + ${contentatom} + +!__EOF__ + +# sitemap (sitemap.xml). +cat < "${outputdir}/sitemap.xml" +${contentsitemap} +!__EOF__ diff --git a/output/print.css b/output/print.css new file mode 100644 index 0000000..4ddcb45 --- /dev/null +++ b/output/print.css @@ -0,0 +1,22 @@ +table { + border: 0; +} +h1, h1 a, h1 a:visited, +h2, h2 a, h2 a:visited, +h3, h3 a, h3 a:visited, +h1 a:hover, h2 a:hover, h3 a:hover { + color: inherit; + text-decoration: none; +} +table tr td { + padding: 2px 10px 2px 0px; +} +pre { + border: 1px dashed #777; + padding: 5px; + overflow-x: auto; +} +#menuwrap, +.hidden { + display: none; +} diff --git a/output/style.css b/output/style.css new file mode 100644 index 0000000..049739e --- /dev/null +++ b/output/style.css @@ -0,0 +1,67 @@ +body { + font-family: sans-serif, monospace; + text-align: center; + overflow-y: scroll; + color: #333; + background-color: #fff; + margin: 0; + padding: 0; +} +table { + border: 0; +} +hr { + height: 1px; + color: #ccc; + background-color: #ccc; + border: 0; +} +h1 { + font-size: 140%; +} +h2 { + font-size: 120%; +} +h3 { + font-size: 100%; +} +h1, h1 a, h1 a:visited, +h2, h2 a, h2 a:visited, +h3, h3 a, h3 a:visited, +h1 a:hover, h2 a:hover, h3 a:hover { + color: inherit; + text-decoration: none; +} +table tr td { + padding: 2px 10px 2px 0px; +} +pre { + border: 1px dashed #777; + background-color: #eee; + padding: 5px; + overflow-x: auto; +} +#menuwrap { + background-color: #eee; + padding: 1ex; + border-bottom: 1px solid #ccc; +} +#main { + padding: 1ex; +} +#menu, +#main { + margin: 0px auto; + text-align: left; + max-width: 80ex; +} +#menu a { + font-weight: bold; + vertical-align: middle; +} +#links-contact { + float: right; +} +.hidden { + display: none; +} diff --git a/pages/001-html-example.html b/pages/001-html-example.html new file mode 100644 index 0000000..2d5e25b --- /dev/null +++ b/pages/001-html-example.html @@ -0,0 +1 @@ +

This is an example page :)

diff --git a/pages/001-html-example.sh b/pages/001-html-example.sh new file mode 100755 index 0000000..b0fed9e --- /dev/null +++ b/pages/001-html-example.sh @@ -0,0 +1,13 @@ +#!/bin/sh +title="HTML example" +description="description here" +timecreated="2013-01-01 00:00" +timeupdated="2013-01-01 00:00" +#id="html-example" +#url="${id}.html" +#tags="tags, comma, separated" +#keywords="keywords, comma, separated" +#categories="Category name" +#timestamp="2013-01-01" +#author="author" +#content="custom stuff" diff --git a/pages/002-markdown-example.md b/pages/002-markdown-example.md new file mode 100644 index 0000000..cdda1db --- /dev/null +++ b/pages/002-markdown-example.md @@ -0,0 +1,61 @@ +simple tests +------------ + +first paragraph. +testing surround: _emph_ then **strong** and `code`. + +`\`escaped backticks\``. + +`x = *y * 6;` + +horizontal rule: + +- - - + + +blocks and entities +------------------- + +preformatted block: + .'''' .'.'. | | + '''. | ' | | | + '''' ' ' "" + +quoted text: +> When in doubt, +> use brute force. + +list: +* Make each program do one thing well. +* Expect the output of every program to become the input to another, +as yet unknown, program. +* Design and build software, even operating systems, to be tried early, +ideally within weeks. +* Use tools in preference to unskilled help to lighten a programming task. + +list in list: +* a + * b + 1. c + 2. d + * e +* f + +entity: &, <, > + +code: + int powerof2(unsigned int n) { + return !((n - 1) & n) && n > 0; + } + +links +----- + +[suckless](http://suckless.org) + +inline html +----------- + +
+ ABC +
diff --git a/pages/002-markdown-example.sh b/pages/002-markdown-example.sh new file mode 100755 index 0000000..6f6ebb8 --- /dev/null +++ b/pages/002-markdown-example.sh @@ -0,0 +1,14 @@ +#!/bin/sh +title="Markdown example" +description="description here" +timecreated="2013-01-01 00:00" +timeupdated="2013-01-01 00:00" +author="Bob" +#id="markdown-example" +#url="${id}.html" +#tags="tags, comma, separated" +#keywords="keywords, comma, separated" +#categories="Category name" +#timestamp="2013-01-02" +#author="author" +#content="custom stuff"