slweb

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

чување 1e48529e90859117773814a0ca404678f483b9d3
родитељ 2d571dba1bec06dd485f340d7f750a0b49ab85fc
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sat, 21 Nov 2020 21:44:25 +0100

Modified examples/includes to contain the slweb manpage; many fixes

Diffstat:
MMakefile | 27+++++++++++++++------------
Aexamples/includes/bugs.slw | 5+++++
Aexamples/includes/description.slw | 6++++++
Aexamples/includes/examples.slw | 46++++++++++++++++++++++++++++++++++++++++++++++
Mexamples/includes/footer.slw | 10+++++++++-
Mexamples/includes/header.slw | 10+++++++++-
Mexamples/includes/index.css | 18++++--------------
Mexamples/includes/index.slw | 15+++++++++------
Aexamples/includes/options.slw | 21+++++++++++++++++++++
Aexamples/includes/reference.slw | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dexamples/includes/section01.slw | 4----
Dexamples/includes/section02.slw | 4----
Dexamples/includes/section03.slw | 4----
Aexamples/includes/seealso.slw | 4++++
Mslweb.1.in | 12+++++++++---
Mslweb.in | 72+++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
измењених датотека: 16, додавања: 260(+), брисања: 72(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,5 @@ -VERSION = v0.2-beta +SLWVERSION = v0.2.1-beta +SLWDATE = 21 Nov 2020 BINDIR = /usr/local/bin MANDIR = /usr/local/share/man/man1 BROWSER = surf @@ -10,7 +11,7 @@ EXAMPLE_PAGES_HTML = $(EXAMPLE_PAGES:.slw=.html) ./slweb $^ > $@ %.gz: % - gzip -kf $< + gzip -kf $< %.ps: %.1 groff -mandoc -t -T ps $< > $@ @@ -19,34 +20,36 @@ EXAMPLE_PAGES_HTML = $(EXAMPLE_PAGES:.slw=.html) groff -mandoc -t -T pdf $< > $@ %: %.in - cat $< | sed -e "s/%VERSION%/${VERSION}/g" > $@ + cat $< | sed -e "s/%VERSION%/${SLWVERSION}/g" \ + -e "s/%DATE%/${SLWDATE}/g" > $@ all: in examples doc in: slweb slweb.1 slweb: slweb.in - cat $< | sed -e "s/%VERSION%/${VERSION}/g" > $@ - chmod 0755 slweb + cat $< | sed -e "s/%VERSION%/${SLWVERSION}/g" \ + -e "s/%DATE%/${SLWDATE}/g" > $@ + chmod 0755 slweb examples: ${EXAMPLE_PAGES_HTML} view: examples - $(BROWSER) examples/basic/index.html + $(BROWSER) examples/basic/index.html doc: slweb.pdf slweb.1.gz install: all - mkdir -p $(BINDIR) $(MANDIR) - cp slweb $(BINDIR) - chmod 0755 $(BINDIR)/slweb - cp slweb.1.gz $(MANDIR) + mkdir -p $(BINDIR) $(MANDIR) + cp slweb $(BINDIR) + chmod 0755 $(BINDIR)/slweb + cp slweb.1.gz $(MANDIR) uninstall: - rm -f $(BINDIR)/slweb $(MANDIR)/slweb.1.gz 2>/dev/null + 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 $(EXAMPLE_PAGES_HTML) slweb slweb.1 2>/dev/null .PHONY: in examples view doc install uninstall clean diff --git a/examples/includes/bugs.slw b/examples/includes/bugs.slw @@ -0,0 +1,5 @@ +## BUGS + +Bugs can be reported using the Github issue tracker at: +[https://github.com/Strahinja/slweb/issues](https://github.com/Strahinja/slweb/issues) + diff --git a/examples/includes/description.slw b/examples/includes/description.slw @@ -0,0 +1,6 @@ +## DESCRIPTION + +**Slweb** is a static website generator which aims at being simplistic. It uses +**sed** (1) to transform a custom Markdown-like syntax into +{abbr}HTML{/abbr}. + diff --git a/examples/includes/examples.slw b/examples/includes/examples.slw @@ -0,0 +1,46 @@ +## EXAMPLES + +Given the file `index.slw` in the current directory: + +<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> + +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;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> + diff --git a/examples/includes/footer.slw b/examples/includes/footer.slw @@ -1,4 +1,12 @@ {footer} -Page footer +{.left} +slweb v0.2.1-beta +{/.left} +{.center} +21 Nov 2020 +{/.center} +{.right} +SLWEB(1) +{/.right} {/footer} diff --git a/examples/includes/header.slw b/examples/includes/header.slw @@ -1,4 +1,12 @@ {header} -Page header +{.left} +SLWEB(1) +{/.left} +{.center} +General Commands Manual +{/.center} +{.right} +SLWEB(1) +{/.right} {/header} diff --git a/examples/includes/index.css b/examples/includes/index.css @@ -1,18 +1,8 @@ -header -{ - background: #ffa; - padding: 1em; -} - -main -{ - background: #ccf; - padding: 1em; -} - +header, footer { - background: #faa; - padding: 1em; + display: flex; + flex-direction: row; + justify-content: space-between; } diff --git a/examples/includes/index.slw b/examples/includes/index.slw @@ -1,17 +1,20 @@ site-name: Includes -site-desc: Includes demo +site-description: Demonstration of the includes --- - {include "header"} {main} -# Document index +{include "description"} + +{include "options"} + +{include "reference"} -{include "section01"} +{include "seealso"} -{include "section02"} +{include "examples"} -{include "section03"} +{include "bugs"} {/main} {include "footer"} diff --git a/examples/includes/options.slw b/examples/includes/options.slw @@ -0,0 +1,21 @@ +## OPTIONS + +**-b** +**--body-only** +Only add the contents of the `&lt;body&gt;` tag, skipping +`&lt;html&gt;` and +`&lt;head&gt;`. + +**-d** +**--basedir &lt;_directory_&gt;** +Set the base directory as a reference point to normalize paths in local links +(the argument to **--relative-to** option for the **realpath** (1) command). + +**-h** +**--help** +Print this usage information screen. + +**-v** +**--version** +Print program version and exit. + diff --git a/examples/includes/reference.slw b/examples/includes/reference.slw @@ -0,0 +1,74 @@ +## REFERENCE + +Files processed by **slweb** are using a minimal subset of Markdown with added +directives. Supported **Markdown features** are: + +<ul> +<li> +**Paragraphs.** +Text surrounded by newlines will be put inside `&lt;p&gt;&lt;/p&gt;` tags. +</li> +<li> +**Headings.** +A line starting with `#` followed by space will be put inside +`&lt;h?&gt;&lt;/h?&gt;`, where +`?` stands for 1-4, depending on the number of +hashtags. +</li> +<li> +**Bold/italic (limited).** +Text inside `\*asterisks\*` or +`\_underlines\_` will be put inside +`&lt;em&gt;&lt;/em&gt;`. Text inside +`\*\*double asterisks\*\*` will be put inside +`&lt;strong&gt;&lt;/strong&gt;`. +</li> +<li> +**Backticks.** +Text inside `\`backticks\`` will be put inside +`&lt;code&gt;&lt;/code&gt;` (one per line, both backticks need to be on the same line). +</li> +<li> +**Links (limited).** +The construct `\[A link](https://example.com)` will be converted into +`&lt;a href="https://example.com"&gt;A link&lt;/a&gt;`. +</li> +<li> +**Line breaks.** +Space followed by a newline will be turned into `&lt;br /&gt;`. +</li> +</ul> + + +**Directives** include: + +<ul> +<li> +**Class divs.** +Directive `\{.myclass}\{/.myclass}` will be transformed into +`&lt;div class="myclass"&gt;&lt;/div&gt;`. +</li> +<li> +**Id divs.** +Directive `\{#myid}\{/#myid}` will be transformed into +`&lt;div id="myid"&gt;&lt;/div&gt;`. +</li> +<li> +**General tags.** +Directive `\{sometag}\{/sometag}` will be transformed into +`&lt;sometag&gt;&lt;/sometag&gt;`. +</li> +<li> +**Includes.** +Directive `\{include "somefile"}` will run +`slweb -b` on _somefile.slw_ (related +to the directory containing the file containing the directive) and include the +resulting {abbr}HTML{/abbr}. Directive needs to start at the beginning of the line. +</li> +<li> +**Brand &ldquo;watermark&rdquo;.** +Directive `\{made-by}` is converted into a div containing the +&ldquo;watermark&rdquo; text and a link to the **slweb** home page. +</li> +</ul> + diff --git a/examples/includes/section01.slw b/examples/includes/section01.slw @@ -1,4 +0,0 @@ -## First section - -This is a first section, added through an `include` directive. - diff --git a/examples/includes/section02.slw b/examples/includes/section02.slw @@ -1,4 +0,0 @@ -## Second section - -This is a second section. - diff --git a/examples/includes/section03.slw b/examples/includes/section03.slw @@ -1,4 +0,0 @@ -## Third section - -This is a third section. - diff --git a/examples/includes/seealso.slw b/examples/includes/seealso.slw @@ -0,0 +1,4 @@ +## SEE ALSO + +**sed**(1) + diff --git a/slweb.1.in b/slweb.1.in @@ -3,7 +3,7 @@ . .mso an-ext.tmac . -.TH SLWEB "1" "11 Nov 2020" "slweb %VERSION%" "General Commands Manual" +.TH SLWEB "1" "%DATE%" "slweb %VERSION%" "General Commands Manual" .SH NAME slweb \- Simple static website generator . @@ -85,13 +85,19 @@ Text inside \fC*asterisks*\fR or \fC_underlines_\fR will be put inside . .IP \[bu] .BR Backticks . -Text inside \fC`backticks`\fR will be put inside \fC<code></code>\fR. +Text inside \fC`backticks`\fR will be put inside \fC<code></code>\fR (one per +line, both backticks need to be on the same line). + . .IP \[bu] .BR "Links (limited)" . The construct \fC[A link](https://example.com)\fR will be converted into \fC<a href="https://example.com">A link</a>\fR. . +.IP \[bu] +.BR "Line breaks" . +Space followed by a newline will be turned into \fC<br />\fR. +. .PP .BR "Directives " include: . @@ -116,7 +122,7 @@ Directive \fC{include "somefile"}\fR will run \fCslweb -b\fR on .I somefile.slw (related to the directory containing the file containing the directive) and include the resulting -.SM HTML. +.SM HTML. Directive needs to start at the beginning of the line. . .IP \[bu] .BR "Brand \[lq]watermark\[rq]" . diff --git a/slweb.in b/slweb.in @@ -84,36 +84,62 @@ EOT function body() { BODY=$(echo "$1" | \ - sed -e's/#### \([^\n]*\)$/<h4>\1<\/h4>/g' \ - -e's/### \([^\n]*\)$/<h3>\1<\/h3>/g' \ - -e's/## \([^\n]*\)$/<h2>\1<\/h2>/g' \ - -e's/# \([^\n]*\)$/<h1>\1<\/h1>/g' \ - -e 's/\*\*\([^*]\+\)\*\*/<strong>\1<\/strong>/g' \ - -e 's/\*\([^*]\+\)\*/<em>\1<\/em>/g' \ - -e 's/_\([^_]\+\)_/<em>\1<\/em>/g' \ - -e 's/`\([^`]\+\)`/<code>\1<\/code>/g' \ - -e 's/{\.\(.*\)}/<div class="\1">/' \ - -e 's/{\/\.\(.*\)}/<\/div><!--\1-->/' \ - -e 's/{#\(.*\)}/<div id="\1">/' \ - -e 's/{\/#\(.*\)}/<\/div><!--\1-->/' \ - -e "s/{made-by}/$MADEBY/g" \ - -e 's/{\([a-z-]\+\)}/<\1>/g' \ - -e 's/{\/\([a-z-]\+\)}/<\/\1>/g' \ - -e "s/\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g')\/\\2\">\\1<\\/a>/" | \ + sed -e's/^#### \([^\n]*\)$/<h4>\1<\/h4>/g' \ + -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<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') + sed -e '1h;2,$H;$!d;g;s/\([^>}\n]\)$/\1<\/p>\n\n/g' | \ + sed -e 's/^\*\*\([^*]*\)\*\*/<strong>\1<\/strong>/g' \ + -e 's/\([^\\]\)\*\*\([^*]*\)\*\*/\1<strong>\2<\/strong>/g' \ + -e 's/^\*\([^*]*\)\*/<em>\1<\/em>/g' \ + -e 's/\([^\\]\)\*\([^*]*\)\*/\1<em>\2<\/em>/g' \ + -e 's/\\\*/\*/g' \ + -e 's/^_\([^_]\+\)_/<em>\1<\/em>/g' \ + -e 's/\([^\\]\)_\([^_]\+\)_/\1<em>\2<\/em>/g' \ + -e 's/\\_/_/g' \ + -e 's/\\#/#/g' \ + -e 's/\\---/---/g' \ + -e 's/\\$/<br \/>/g' \ + -e 's/`\(.*\)`/<code>\1<\/code>/g' \ + -e 's/\\`/`/g' \ + -e 's/^{\.\(.*\)}/<div class="\1">/' \ + -e 's/\([^\\]\){\.\(.*\)}/\1<div class="\2">/' \ + -e 's/\\\({\..*}\)/\1/' \ + -e 's/^{\/\.\(.*\)}/<\/div><!--\1-->/' \ + -e 's/\([^\\]\){\/\.\(.*\)}/\1<\/div><!--\2-->/' \ + -e 's/\\\({\/\..*}\)/\1/' \ + -e 's/^{#\(.*\)}/<div id="\1">/' \ + -e 's/\([^\\]\){#\(.*\)}/\1<div id="\2">/' \ + -e 's/\\\({#.*}\)/\1/' \ + -e 's/^{\/#\(.*\)}/<\/div><!--\1-->/' \ + -e 's/\([^\\]\){\/#\(.*\)}/\1<\/div><!--\2-->/' \ + -e 's/\\\({\/#.*}\)/\1/' \ + -e "s/^{made-by}/$MADEBY/g" \ + -e "s/\([^\\]\){made-by}/\1$MADEBY/g" \ + -e 's/\\\({made-by}\)/\1/g' \ + -e 's/^{\([a-z-]\+\)}/<\1>/g' \ + -e 's/\([^\\]\){\([a-z-]\+\)}/\1<\2>/g' \ + -e 's/\\\({[a-z-]\+}\)/\1/g' \ + -e 's/^{\/\([a-z-]\+\)}/<\/\1>/g' \ + -e 's/\([^\\]\){\/\([a-z-]\+\)}/\1<\/\2>/g' \ + -e 's/\\\({\/[a-z-]\+}\)/\1/g' \ + -e 's/ $/<br \/>/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') INCLUDE=$(echo "$BODY" | \ - sed -e'/{include/s/.*{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \ + sed -e'/^{include/s/{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \ sed 1q) - while [ ! -z "$INCLUDE" ]; do + while [ -n "$INCLUDE" ]; do INCLUDE_BODY=$($0 -b -d $(dirname $INFILE) "$(dirname $INFILE)/$INCLUDE.slw") BODY=$(echo "$BODY" | \ - sed -e"s/{include \\\"$(echo $INCLUDE | sed -e's/\//\\\//g')\\\"}/$(echo $INCLUDE_BODY | sed -e's/\//\\\//g')/") + sed -e"s/^{include \\\"$(echo $INCLUDE | sed -e's/\//\\\//g' -e's/&/\\\&/g')\\\"}/$(echo $INCLUDE_BODY | sed -e's/\//\\\//g' -e's/&/\\\&/g')/") INCLUDE=$(echo "$BODY" | \ - sed -e'/{include/s/.*{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \ + sed -e'/^{include/s/.*{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \ sed 1q) done echo "$BODY" @@ -163,8 +189,8 @@ done #echo -n Generating ${VARS[site-name]}: ${VARS[site-desc]}... -grep -- '---' $INFILE 2>&1 >/dev/null \ - && DOC=$(sed '0,/---/d' $INFILE) \ +grep -- '^---' $INFILE 2>&1 >/dev/null \ + && DOC=$(sed '0,/^---/d' $INFILE) \ || DOC=$(cat $INFILE) CSSHREF=$CSSFILE