slweb

Једноставни генератор статичких веб страна
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување b7bea71dbf48a0868df099d5e26405b5aabede34
родитељ 1e48529e90859117773814a0ca404678f483b9d3
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Mon, 23 Nov 2020 20:41:12 +0100

Corrected a number of bugs related to <pre> (esp. in includes) and YAML-like variables

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MMakefile | 10++++++----
Mexamples/includes/examples.slw | 52++++++++++++++++++++++++++--------------------------
Mexamples/includes/footer.slw | 4++--
Aindex.css | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aindex.html | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aindex.slw | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mslweb.in | 39++++++++++++++++++++++++++-------------
измењених датотека: 7, додавања: 310(+), брисања: 45(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ -SLWVERSION = v0.2.1-beta -SLWDATE = 21 Nov 2020 +SLWVERSION = v0.2.2-beta +SLWDATE = 23 Nov 2020 BINDIR = /usr/local/bin MANDIR = /usr/local/share/man/man1 BROWSER = surf @@ -23,7 +23,7 @@ EXAMPLE_PAGES_HTML = $(EXAMPLE_PAGES:.slw=.html) cat $< | sed -e "s/%VERSION%/${SLWVERSION}/g" \ -e "s/%DATE%/${SLWDATE}/g" > $@ -all: in examples doc +all: in examples doc github-io in: slweb slweb.1 @@ -39,6 +39,8 @@ view: examples doc: slweb.pdf slweb.1.gz +github-io: index.html + install: all mkdir -p $(BINDIR) $(MANDIR) cp slweb $(BINDIR) @@ -49,7 +51,7 @@ uninstall: rm -f $(BINDIR)/slweb $(MANDIR)/slweb.1.gz 2>/dev/null clean: - rm -f slweb.1.gz slweb.pdf $(EXAMPLE_PAGES_HTML) slweb slweb.1 2>/dev/null + rm -f slweb.1.gz slweb.pdf index.html $(EXAMPLE_PAGES_HTML) slweb slweb.1 2>/dev/null .PHONY: in examples view doc install uninstall clean diff --git a/examples/includes/examples.slw b/examples/includes/examples.slw @@ -2,45 +2,45 @@ Given the file `index.slw` in the current directory: -<pre> -site-name: Test website -site-desc: My first website in slweb -\--- +``` +site-name: Test website +site-desc: My first website in slweb +--- \ -\{main} -\# Hello world +\{main} +\# Hello world \ -This is an \_example\_ of a statically generated HTML. +This is an \_example_ of a statically generated HTML. \ \{/main} -</pre> +``` after using the command: -<pre> +``` $ slweb index.slw > index.html -</pre> +``` file `index.html` contains: -<pre> -&lt;!DOCTYPE html&gt; -&lt;html lang="en"&gt; -&lt;head&gt; - &lt;title&gt;Test website&lt;/title&gt; - &lt;meta charset="utf8" /&gt; - &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt; - &lt;meta name="generator" content="slweb" /&gt; -&lt;/head&gt; -&lt;body&gt; +``` +&lt;!DOCTYPE html&gt; +&lt;html lang="en"&gt; +&lt;head&gt; + &lt;title&gt;Test website&lt;/title&gt; + &lt;meta charset="utf8" /&gt; + &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt; + &lt;meta name="generator" content="slweb" /&gt; +&lt;/head&gt; +&lt;body&gt; \ -&lt;main&gt; -&lt;h1&gt;Hello world&lt;/h1&gt; +&lt;main&gt; +&lt;h1&gt;Hello world&lt;/h1&gt; \ -&lt;p&gt;This is an &lt;em&gt;example&lt;/em&gt; of a statically generated HTML.&lt;/p&gt; +&lt;p&gt;This is an &lt;em&gt;example&lt;/em&gt; of a statically generated HTML.&lt;/p&gt; \ -&lt;/main&gt; -&lt;/body&gt; +&lt;/main&gt; +&lt;/body&gt; &lt;/html&gt; -</pre> +``` diff --git a/examples/includes/footer.slw b/examples/includes/footer.slw @@ -1,9 +1,9 @@ {footer} {.left} -slweb v0.2.1-beta +slweb v0.2.2-beta {/.left} {.center} -21 Nov 2020 +23 Nov 2020 {/.center} {.right} SLWEB(1) diff --git a/index.css b/index.css @@ -0,0 +1,61 @@ +html, +body +{ + font-family: "Noto Serif", "Times New Roman", serif; + font-size: 12pt; +} + +pre, +code +{ + font-family: "Noto Mono", "Courier New", "Courier", monospace; + background-color: #eef; +} + +code +{ + padding: .5em 1em; +} + +pre +{ + padding: 1em; + line-height: 1.2em; +} + +main +{ + margin: 0 auto; + max-width: 1024px; +} + +h1 +{ + font-size: 300%; + font-style: oblique; + color: #005; +} + +p +{ + line-height: 1.7em; + margin: 0; + margin-bottom: 1em; + padding: 0; +} + +#made-by +{ + font-size: 90%; + padding: .5em 2em; + text-align: center; + background-color: #eef; +} + +@media (max-width: 920px) +{ +main +{ + max-width: auto; +} +} diff --git a/index.html b/index.html @@ -0,0 +1,105 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>slweb - Simple static website generator. </title> + <meta charset="utf8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <meta name="generator" content="slweb" /> + <link rel="stylesheet" href="index.css" /> +</head> +<body> +<main> +<h1>slweb</h1> + +<p><strong>Slweb</strong> is a static website generator which aims at being simplistic. It uses +<strong>sed</strong>(1) to transform a custom Markdown-like syntax into HTML.</p> + +<h2>Install</h2> + +<pre> +$ git clone https://github.com/Strahinja/slweb.git<br /> +$ cd slweb<br /> +$ make && sudo make install +</pre> + + + +<h2>Examples</h2> + +<p>See the <code><a href="https://github.com/Strahinja/slweb/tree/master/examples">examples/</a></code> directory in this repository.</p> + +<p>GIven the file <code>index.slw</code> in the current directory:</p> + +<pre> +site-name: Test website +site-desc: My first website in slweb +--- + +{main} +# Hello world + +This is an _example_ of a statically generated HTML. + +{/main} +</pre> + + + +<p>after using the command:</p> + +<pre> +$ slweb index.slw > index.html +</pre> + + + +<p>file <code>index.html</code> contains:</p> + +<pre> +&lt;!DOCTYPE html&gt; +&lt;html lang="en"&gt; +&lt;head&gt; + &lt;title&gt;Test website&lt;/title&gt; + &lt;meta charset="utf8" /&gt; + &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt; + &lt;meta name="generator" content="slweb" /&gt; +&lt;/head&gt; +&lt;body&gt; + +&lt;main&gt; +&lt;h1&gt;Hello world&lt;/h1&gt; + +&lt;p&gt;This is an &lt;em&gt;example&lt;/em&gt; of a statically generated HTML.&lt;/p&gt; + +&lt;/main&gt; +&lt;/body&gt; +&lt;/html&gt; +</pre> + + + +<h2>License</h2> + +<p>slweb - Simple static website generator.<br /> +Copyright (C) 2020 Страхиња Радић </p> + +<p>This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. </p> + +<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. </p> + +<p>You should have received a copy of the GNU General Public License along with +this program. If not, see &lt;https://www.gnu.org/licenses/&gt;. </p> + +<div id="made-by"> +Generated by <a href="https://github.com/Strahinja/slweb">slweb</a> +© 2020 Strahinya Radich. +</div><!--made-by--> + +</main> +</body> +</html> diff --git a/index.slw b/index.slw @@ -0,0 +1,84 @@ +site-name: slweb - Simple static website generator. +--- +{main} +# slweb + +**Slweb** is a static website generator which aims at being simplistic. It uses +**sed**(1) to transform a custom Markdown-like syntax into HTML. + +## Install + +``` +$ git clone https://github.com/Strahinja/slweb.git +$ cd slweb +$ make && sudo make install +``` + +## Examples + +See the `[examples/](https://github.com/Strahinja/slweb/tree/master/examples)` directory in this repository. + +GIven the file `index.slw` in the current directory: + +``` +site-name: Test website +site-desc: My first website in slweb +--- +\ +\{main} +\# Hello world +\ +This is an \_example_ of a statically generated HTML. +\ +\{/main} +``` + +after using the command: + +``` +$ slweb index.slw > index.html +``` + +file `index.html` contains: + +``` +&lt;!DOCTYPE html&gt; +&lt;html lang="en"&gt; +&lt;head&gt; + &lt;title&gt;Test website&lt;/title&gt; + &lt;meta charset="utf8" /&gt; + &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt; + &lt;meta name="generator" content="slweb" /&gt; +&lt;/head&gt; +&lt;body&gt; +\ +&lt;main&gt; +&lt;h1&gt;Hello world&lt;/h1&gt; +\ +&lt;p&gt;This is an &lt;em&gt;example&lt;/em&gt; of a statically generated HTML.&lt;/p&gt; +\ +&lt;/main&gt; +&lt;/body&gt; +&lt;/html&gt; +``` + +## License + +slweb - Simple static website generator. +Copyright (C) 2020 Страхиња Радић + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see &lt;https://www.gnu.org/licenses/&gt;. + +{made-by} +{/main} + diff --git a/slweb.in b/slweb.in @@ -88,6 +88,8 @@ function body() -e's/^### \([^\n]*\)$/<h3>\1<\/h3>/g' \ -e's/^## \([^\n]*\)$/<h2>\1<\/h2>/g' \ -e's/^# \([^\n]*\)$/<h1>\1<\/h1>/g' | \ + sed -e '1h;2,$H;$!d;g;s/\n\+\n```[^\n]*\n/\n\n<pre>\n/g' | \ + sed -e 's/^```$/<\/pre>\n\n/g' | \ sed -e '1h;2,$H;$!d;g;s/\n\n\([^<{\n]\+\)/\n\n<p>\1/g' | \ sed -e '1h;2,$H;$!d;g;s/\([^>}\n]\)\n\n/\1<\/p>\n\n/g' | \ sed -e '1h;2,$H;$!d;g;s/\([^>}\n]\)$/\1<\/p>\n\n/g' | \ @@ -100,8 +102,7 @@ function body() -e 's/\([^\\]\)_\([^_]\+\)_/\1<em>\2<\/em>/g' \ -e 's/\\_/_/g' \ -e 's/\\#/#/g' \ - -e 's/\\---/---/g' \ - -e 's/\\$/<br \/>/g' \ + -e 's/\\$//g' \ -e 's/`\(.*\)`/<code>\1<\/code>/g' \ -e 's/\\`/`/g' \ -e 's/^{\.\(.*\)}/<div class="\1">/' \ @@ -126,6 +127,9 @@ function body() -e 's/\([^\\]\){\/\([a-z-]\+\)}/\1<\/\2>/g' \ -e 's/\\\({\/[a-z-]\+}\)/\1/g' \ -e 's/ $/<br \/>/g' \ + -e "s/^\\[\\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/<a href=\"\\2\">\\1<\\/a>/" \ + -e "s/\\([^\\\\]\\)\\[\\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/\\1<a href=\"\\3\">\\2<\\/a>/" \ + -e 's/\\\(\[[^]]\+\]([a-z]\+:\/\/[^)]\+)\)/\1/g' \ -e "s/^\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\2\">\\1<\\/a>/" \ -e "s/\\([^\\\\]\\)\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/\\1<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\3\">\\2<\\/a>/" \ -e 's/\\\(\[[^]]\+\]([^)]\+)\)/\1/g') @@ -135,9 +139,10 @@ function body() sed 1q) while [ -n "$INCLUDE" ]; do - INCLUDE_BODY=$($0 -b -d $(dirname $INFILE) "$(dirname $INFILE)/$INCLUDE.slw") + INCLUDE_BODY=$($0 -b -d $(dirname $INFILE) "$(dirname $INFILE)/$INCLUDE.slw" | \ + sed -z -e's/\//\\\//g' -e's/&/\\\&/g' -e's/\n/\\n/g') BODY=$(echo "$BODY" | \ - sed -e"s/^{include \\\"$(echo $INCLUDE | sed -e's/\//\\\//g' -e's/&/\\\&/g')\\\"}/$(echo $INCLUDE_BODY | sed -e's/\//\\\//g' -e's/&/\\\&/g')/") + sed -e"s/^{include \\\"$(echo $INCLUDE | sed -e's/\//\\\//g' -e's/&/\\\&/g')\\\"}/$INCLUDE_BODY/") INCLUDE=$(echo "$BODY" | \ sed -e'/^{include/s/.*{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \ sed 1q) @@ -180,18 +185,26 @@ done [ -f $INFILE ] || throw "$INFILE not present" declare -A VARS -VAR_KEYS=$(grep '\([a-z-]\+\): \(.*\)' $INFILE | \ - sed -e's/\([a-z-]\+\): \(.*\)/\1/g') -for key in $VAR_KEYS; do - VARS[$key]=$(grep "$key:" $INFILE | \ - sed -e "s/$key: \(.*\)/\1/g") -done + +if [ $BODY_ONLY -eq 0 ]; then + VAR_KEYS=$(sed '/^---/,$d' $INFILE | \ + sed -e's/^\([a-z-]\+\):.*$/\1/g') + for key in $VAR_KEYS; do + VARS[$key]=$(sed '/^---/,$d' $INFILE | grep -e "^$key:" | \ + sed -e "s/^$key: \(.*\)$/\1/g") + done +fi + #echo -n Generating ${VARS[site-name]}: ${VARS[site-desc]}... -grep -- '^---' $INFILE 2>&1 >/dev/null \ - && DOC=$(sed '0,/^---/d' $INFILE) \ - || DOC=$(cat $INFILE) +if [ $BODY_ONLY -eq 0 ]; then + grep -- '^---' $INFILE 2>&1 >/dev/null \ + && DOC=$(sed '0,/^---/d' $INFILE) \ + || DOC=$(cat $INFILE) +else + DOC=$(cat $INFILE) +fi CSSHREF=$CSSFILE INDIR=$(dirname $INFILE 2>/dev/null)