чување 62730a5defeb06e7512b23597a4cc6337eb68e5e
родитељ 8064ec3e4e4beff77c2b1c90b02ae7c9e76df8cd
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Tue, 1 Dec 2020 09:36:56 +0100
Added macros; added macro-form of links; added handling of site-desc; updated documentation
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 6, додавања: 74(+), брисања: 16(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
-SLWVERSION = v0.2.3-beta
-SLWDATE = 25 Nov 2020
+SLWVERSION = v0.2.4-beta
+SLWDATE = 1 Dec 2020
BINDIR = /usr/local/bin
MANDIR = /usr/local/share/man/man1
BROWSER = surf
@@ -53,5 +53,7 @@ uninstall:
clean:
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
+rebuild: clean all
+
+.PHONY: in examples view doc install uninstall clean rebuild
diff --git a/examples/includes/index.slw b/examples/includes/index.slw
@@ -1,5 +1,6 @@
site-name: Includes
site-description: Demonstration of the includes
+stylesheet: index.css
---
{include "header"}
diff --git a/index.html b/index.html
@@ -3,6 +3,7 @@
<head>
<title>slweb - Simple static website generator. </title>
<meta charset="utf8" />
+ <meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="slweb" />
<link rel="stylesheet" href="index.css" />
@@ -61,6 +62,7 @@ $ slweb index.slw > index.html
<head>
<title>Test website</title>
<meta charset="utf8" />
+ <meta name="description" content="My first website in slweb" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="slweb" />
</head>
diff --git a/index.slw b/index.slw
@@ -1,4 +1,5 @@
site-name: slweb - Simple static website generator.
+stylesheet: index.css
---
{main}
# slweb
@@ -47,6 +48,7 @@ file `index.html` contains:
<head>
<title>Test website</title>
<meta charset="utf8" />
+ <meta name="description" content="My first website in slweb" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="slweb" />
</head>
diff --git a/slweb.1.in b/slweb.1.in
@@ -93,6 +93,12 @@ line, both backticks need to be on the same line).
.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.
+
+Special case is the form \fC[=somemacro Link title](https://anything)\fR which
+prepends the body of a macro
+.I somemacro
+into the \fC<a></a>\fR tag. See
+.BR Macros .
.
.IP \[bu]
.BR "Line breaks" .
@@ -138,6 +144,15 @@ include the resulting
.SM HTML.
Directive needs to start at the beginning of the line.
.
+.IP \[bu] 4
+.BR Macros .
+Macros can be declared using the directive \fC{=macroname}{/=macroname}\fR,
+where
+.I macroname
+is the name of the macro. Anything between those two tags will then become the
+body of a macro. Whenever \fC{=macroname}\fR is subsequently encountered in the
+file, it will be replaced by the macro body.
+.
.IP \[bu]
.BR "Previous Git commit information" .
Directive \fC{git\-log}\fR is converted into a div with the id \fCgit\-log\fR
@@ -151,6 +166,21 @@ containing the \[lq]watermark\[rq] text and a link to the
.B slweb
home page.
.
+.PP
+.B Special YAML variables
+supported by slweb are:
+.
+.IP \[bu] 4
+.BR site-name .
+The contents of this variable will be inserted inside the \fC<title></title>\fR
+tags.
+.
+.IP \[bu] 4
+.BR site-desc .
+Ths contents of this variable will be inserted as the value of the
+.I content
+attribute of the \fC<meta name="description">\fR tag.
+.
.SH "SEE ALSO"
.BR sed (1)
.
@@ -191,6 +221,7 @@ file \fCindex.html\fR contains:
<head>
<title>Test website</title>
<meta charset="utf8" />
+ <meta name="description" content="My first website in slweb" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="slweb" />
</head>
diff --git a/slweb.in b/slweb.in
@@ -1,7 +1,6 @@
#!/bin/bash
BODY_ONLY=0
-CSSFILE=index.css
INFILE=index.slw
OUTFILE=index.html
VERSION=%VERSION%
@@ -55,6 +54,7 @@ function head()
cat <<EOT
<title>${VARS[site-name]}</title>
<meta charset="utf8" />
+ <meta name="description" content="${VARS[site-desc]}" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="slweb" />
EOT
@@ -117,7 +117,7 @@ function body()
-e 's/^{#\([a-z0-9-]\+\)\.\([a-z 0-9-]\+\)}/<div id="\1" class="\2">/g' \
-e 's/\([^\\]\){#\([a-z0-9-]\+\)\.\([a-z 0-9-]\+\)}/\1<div id="\2" class="\3">/g' \
-e 's/\\\({#[a-z0-9-]\+\.[a-z0-9-]\+}\)/\1/g' \
- -e 's/^{\.\([a-z 0-9-]\+\)}/<div class="\1"/g' \
+ -e 's/^{\.\([a-z 0-9-]\+\)}/<div class="\1">/g' \
-e 's/\([^\\]\){\.\([a-z0-9-]\+\)}/\1<div class="\2">/g' \
-e 's/\\\({\.[a-z0-9-]\+}\)/\1/g' \
-e 's/^{#\([a-z0-9-]\+\)}/<div id="\1">/g' \
@@ -148,9 +148,13 @@ function body()
-e 's/\([^\\]\){\/#\([a-z0-9-]\+\)}/\1<\/div><!--#\2-->/g' \
-e 's/\\\({\/#[a-z0-9-]\+}\)/\1/g' \
-e 's/ $/<br \/>/g' \
+ -e "s/^\\[=\\(\\S\\+\\) \\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/<a href=\"\\3\">\\{=\\1\\}\\2<\\/a>/g" \
+ -e "s/\\([^\\\\]\\)\\[=\\(\\S\\+\\) \\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/\\1<a href=\"\\4\">\\{=\\2\\}\\3<\\/a>/g" \
-e "s/^\\[\\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/<a href=\"\\2\">\\1<\\/a>/g" \
-e "s/\\([^\\\\]\\)\\[\\([^]]\\+\\)\\](\\([a-z]\+:\/\/[^)]\\+\\))/\\1<a href=\"\\3\">\\2<\\/a>/g" \
-e 's/\\\(\[[^]]\+\]([a-z]\+:\/\/[^)]\+)\)/\1/g' \
+ -e "s/^\\[=\\(\\S\\+\\) \\([^]]\\+\\)\\](\\([^)]\\+\\))/<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\3\">\\{=\\1\\}\\2<\\/a>/g" \
+ -e "s/\\([^\\\\]\\)\\[=\\(\\S\\+\\) \\([^]]\\+\\)\\](\\([^)]\\+\\))/\\1<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\4\">\\{=\\2\\}\\3<\\/a>/g" \
-e "s/^\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\2\">\\1<\\/a>/g" \
-e "s/\\([^\\\\]\\)\\[\\([^]]\\+\\)\\](\\([^)]\\+\\))/\\1<a href=\"$(realpath --relative-to=$BASEDIR $(dirname $INFILE) | sed -e's/\//\\\//g' -e's/&/\\\&/g')\/\\3\">\\2<\\/a>/g" \
-e 's/\\\(\[[^]]\+\]([^)]\+)\)/\1/g')
@@ -161,13 +165,20 @@ function body()
while [ -n "$INCLUDE" ]; do
INCLUDE_BODY=$($0 -b -d $(dirname $INFILE) "$(dirname $INFILE)/$INCLUDE.slw" | \
- sed -z -e's/\//\\\//g' -e's/&/\\\&/g' -e's/\n/\\n/g')
+ sed -z -e's/\//\\\//g' -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')\\\"}/$INCLUDE_BODY/")
INCLUDE=$(echo "$BODY" | \
sed -e'/^{include/s/.*{include \"\([.\/a-z0-9_ -]\+\)\"}.*/\1/;t;d' | \
sed 1q)
done
+
+ for macro_name in $MACRO_NAMES; do
+ MACRO_BODY=$(echo "${MACROS[$macro_name]}" | \
+ sed -z -e's/\//\\\//g' -e's/"/\\"/g' -e's/&/\\\&/g' -e's/\n/\\n/g')
+ BODY=$(echo "$BODY" | \
+ sed -e "s/{=$macro_name}/$MACRO_BODY/g")
+ done
echo "$BODY"
}
@@ -216,16 +227,18 @@ done
declare -A VARS
if [ $BODY_ONLY -eq 0 ]; then
- VAR_KEYS=$(sed '/^---/,$d' $INFILE | \
+ YAML=$(sed '/^---/,$d' $INFILE)
+ VAR_KEYS=$(echo "$YAML" | \
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
+ CSSFILES=$(echo "$YAML" | \
+ grep ^stylesheet | \
+ sed -e 's/stylesheet: \(.*\)/\1/g')
fi
-
-
-#echo -n Generating ${VARS[site-name]}: ${VARS[site-desc]}...
+INDIR=$(dirname $INFILE 2>/dev/null)
if [ $BODY_ONLY -eq 0 ]; then
grep -- '^---' $INFILE 2>&1 >/dev/null \
@@ -235,16 +248,24 @@ else
DOC=$(cat $INFILE)
fi
-CSSHREF=$CSSFILE
-INDIR=$(dirname $INFILE 2>/dev/null)
-[ "$INDIR" != "." ] && CSSHREF=$CSSFILE
-#echo CSSHREF=$CSSHREF >&2
+declare -A MACROS
+MACRO_NAMES=$(sed -e 's/{=\(\S\+\)}/\1/g;t;d' $INFILE)
+for macro_name in $MACRO_NAMES; do
+ MACROS[$macro_name]=$(echo "$DOC" | \
+ grep -zo "{=$macro_name}\\(.*\\){\\/=$macro_name}" | tr -d '\0' | \
+ sed -ze "s/{=$macro_name}\\(.*\\){\\/=$macro_name}/\\1/g")
+ DOC=$(echo "$DOC" | \
+ sed -ze "s/\s*{=$macro_name}\\(.*\\){\\/=$macro_name}\s*//g")
+done
if [ $BODY_ONLY -eq 0 ]; then
begin_html
begin_head
head
- [ -f $INDIR/$CSSFILE ] && add_css $CSSHREF
+ for CSSFILE in $CSSFILES; do
+ [ -f $INDIR/$CSSFILE ] && add_css $CSSFILE \
+ || echo "$INDIR/$CSSFILE not found"
+ done
end_head
begin_body
fi
@@ -254,4 +275,3 @@ if [ $BODY_ONLY -eq 0 ]; then
end_html
fi
-#echo done.