чување a4239c8ebcdba060879516a3d5b2556b8295f305
родитељ 453e4547988e6ae1840181b8e748899ea5ea8c04
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 7 Dec 2020 18:14:14 +0100
Added lsdirs (blogging) directive and updated manpage
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | Makefile | | | 4 | ++-- |
| M | index.html | | | 3 | ++- |
| M | slweb.1.in | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
| M | slweb.in | | | 102 | ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- |
измењених датотека: 4, додавања: 108(+), брисања: 43(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
-SLWVERSION = v0.2.5-beta
-SLWDATE = 3 Dec 2020
+SLWVERSION = v0.2.6-beta
+SLWDATE = 7 Dec 2020
BINDIR = /usr/local/bin
MANDIR = /usr/local/share/man/man1
BROWSER = surf
diff --git a/index.html b/index.html
@@ -9,6 +9,7 @@
<link rel="stylesheet" href="index.css" />
</head>
<body>
+
<main>
<h1>slweb</h1>
@@ -99,7 +100,7 @@ this program. If not, see <https://www.gnu.org/licenses/>. </p>
<div id="git-log">
Previous commit:
-index.slw 62730a5 2020-12-01 09:36:56 +0100 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD)
+index.slw 03a4ff6 2020-12-03 19:57:22 +0100 (Страхиња Радић) (tag: v0.2.5-beta)
</div><!--git-log-->
diff --git a/slweb.1.in b/slweb.1.in
@@ -171,6 +171,48 @@ 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] 4
+.BR "Subdirectory inclusion (blogging directive)" .
+The command \fC{lsdirs \fInum\fC =\fImacroname\fC}\fR
+.RI ( num
+and
+.I macroname
+are optional) will be expanded as follows:
+.
+.RS
+.IP 1. 4
+A \fC<ul class="dir">\fR tag will be inserted into the document instead of the
+directive.
+.
+.IP 2. 4
+For every subdirectory of the directory containing the input file, up to
+.I num
+(if present) or 5 (if omitted) total subdirectories, a \fC<li>\fR
+tag will be inserted into the \fC<ul class="dir">\fR tag.
+.
+.IP 3. 4
+A \fC<details>\fR tag will be inserted into each \fC<li>\fR tag.
+.
+.IP 4. 4
+Inside the \fC<details>\fR tag, a \fC<summary>\fR tag will be inserted with the
+name of the subdirectory. If
+.I macroname
+is present, the name of the subdirectory will be prepended with the body of a
+macro
+.IR macroname .
+.
+.IP 5. 4
+After the \fC<summary>\fR tag a \fC<div>\fR tag will be inserted into
+\fC<details>\fR, containing the concatenated contents of each
+.I .slw
+file inside that subdirectory in reverse lexicographical order (\fCsort -r\fR).
+For each file included in this manner, a \fC<h1>\fR tag will be prepended,
+containing the contents of that file's \fCtitle:\fR
+.SM YAML
+variable.
+.
+.RE
+.
.IP \[bu]
.BR "Previous Git commit information" .
Directive \fC{git\-log}\fR is converted into a div with the id \fCgit\-log\fR
diff --git a/slweb.in b/slweb.in
@@ -5,6 +5,7 @@ BODY_ONLY=0
INFILE=index.slw
OUTFILE=index.html
VERSION=%VERSION%
+LSDIRS_MAX_SUBDIRS=5
function throw()
{
@@ -232,9 +233,10 @@ done
declare -A VARS
HAS_YAML=$(grep -- '^---' "$INFILE" 2>/dev/null)
-if [ $BODY_ONLY -eq 0 -a -n "$HAS_YAML" ]; then
+if [ -n "$HAS_YAML" ]; then
YAML=$(sed '/^---/,$d' $INFILE)
VAR_KEYS=$(echo "$YAML" | \
+ grep '^[a-z-]\+:.*' | \
sed -e's/^\([a-z-]\+\):.*$/\1/g')
for key in $VAR_KEYS; do
VARS[$key]=$(sed '/^---/,$d' $INFILE | grep -e "^$key:" | \
@@ -246,13 +248,66 @@ if [ $BODY_ONLY -eq 0 -a -n "$HAS_YAML" ]; then
fi
INDIR=$(dirname $INFILE 2>/dev/null)
-if [ $BODY_ONLY -eq 0 ]; then
+#if [ $BODY_ONLY -eq 0 ]; then
grep -- '^---' $INFILE 2>&1 >/dev/null \
- && DOC=$(sed '0,/^---/d' $INFILE) \
+ && DOC="$(echo; sed '0,/^---/d' $INFILE)" \
|| DOC=$(cat $INFILE)
-else
- DOC=$(cat $INFILE)
-fi
+#else
+ #DOC=$(cat $INFILE)
+#fi
+
+lsdirs_commands=$(echo "$DOC" | \
+ grep -e '{lsdirs\( [0-9]\+\)\?}' \
+ -e '{lsdirs\( [0-9]\+\)\? =[^}]\+}')
+shopt -s extglob
+#shopt -s nullglob
+lsdirs_subdir_count=$(echo "$lsdirs_commands" | \
+ sed -e 's/{lsdirs\( \([0-9]\+\)\)\?}/\2/g' \
+ -e 's/{lsdirs\( \([0-9]\+\)\)\? =[^}]\+}/\2/g')
+lsdirs_subdir_count=${lsdirs_subdir_count:=$LSDIRS_MAX_SUBDIRS}
+lsdirs_subdirs=$(cd $INDIR; \
+ find . -mindepth 1 -type d -print | sort -r)
+while IFS= read -r lsdirs_command; do
+ [ -z "$lsdirs_command" ] && continue
+ lsdirs_macroname=$(echo "$lsdirs_command" | \
+ grep '{lsdirs\( [0-9]\+\)\? =[^}]\+}' | \
+ sed -e 's/{lsdirs\( [0-9]\+\)\? =\([^}]\+\)}/\2/g')
+ lsdirs_html="<ul class=\"dir\">\n"
+ details_open=" open"
+ while IFS= read -r lsdirs_subdir; do
+ [ $lsdirs_subdir_count -le 0 ] && break
+ lsdirs_subdir_count=$(($lsdirs_subdir_count-1))
+ [ -z "$lsdirs_subdir" ] && continue
+ lsdirs_html="$lsdirs_html\n<li>\n<details${details_open}>\n\
+ <summary>"
+ if [ -n "$lsdirs_macroname" ]; then
+ lsdirs_html="$lsdirs_html{=$lsdirs_macroname}"
+ fi
+ lsdirs_html="$lsdirs_html$(basename "$lsdirs_subdir")\
+ </summary>\n\
+ <div>\n"
+
+ lsdirscontent_files=$(cd $INDIR; \
+ find $lsdirs_subdir -mindepth 1 -name '*.slw' -print)
+ while IFS= read -r lsdirscontent_file; do
+ [ -z "$lsdirscontent_file" ] && continue
+ lsdirs_html="$lsdirs_html\
+ $($0 -b -d $INDIR $INDIR/$lsdirscontent_file)"
+ done <<< "$lsdirscontent_files"
+
+ lsdirs_html="$lsdirs_html\
+ </div>\n\
+ </details>\n</li>\n"
+ details_open=""
+ done <<< "$lsdirs_subdirs"
+ lsdirs_html="$lsdirs_html\n</ul><!--dir-->\n"
+ lsdirs_html=$(echo "$lsdirs_html" | \
+ sed -z -e's/\//\\\//g' -e's/\[/\\\[/g' -e's/\]/\\\]/g' -e's/\./\\\./g' \
+ -e's/\"/\\\"/g' -e's/\n/\\n/g')
+ DOC=$(echo "$DOC" | \
+ sed -e "s/$lsdirs_command/$lsdirs_html/g")
+done <<< "$lsdirs_commands"
+
declare -A MACROS
MACRO_NAMES=$(sed -e 's/{=\(\S\+\)}/\1/g;t;d' $INFILE)
@@ -264,40 +319,6 @@ for macro_name in $MACRO_NAMES; do
sed -ze "s/\s*{=$macro_name}\\(.*\\){\\/=$macro_name}\s*//g")
done
-DIR_COMMANDS=$(echo "$DOC" | grep '{dir \"[^\"]*\" \"[^\"]*\"}')
-shopt -s extglob
-#shopt -s nullglob
-while IFS= read -r DIR_COMMAND; do
- FORMAT=$(echo "$DIR_COMMAND" | \
- sed -e 's/{dir \"\([^\"]*\)\" \"[^\"]*\"}/\1/g')
- DIR_PATTERN=$(echo "$DIR_COMMAND" | \
- sed -e 's/{dir \"[^\"]*\" \"\([^\"]*\)\"}/\1/g')
- DIR_FILES=$(cd $INDIR; \
- find . -regextype sed -regex "\.\/$DIR_PATTERN\/.*\.slw" -print)
- FORMAT=$(echo "$FORMAT" | \
- sed -e 's/\//\\\//g' -e 's/\"/\\\"/g')
- DIR_PATTERN=$(echo "$DIR_PATTERN" | \
- sed -e 's/\//\\\//g' -e 's/\"/\\\"/g' -e 's/\*/\\\*/g' \
- -e 's/\./\\\./g' -e 's/\[/\\\[/g' -e 's/\]/\\\]/g')
- DIR_HTML="<ul class=\"dir\">\n"
- while IFS= read -r DIR_FILE; do
- DIR_FILE_HTML=$(echo "$DIR_FILE" | \
- sed -e's/\.slw/\.html/g')
- HAS_YAML=$(grep -- '^---' "$INDIR/$DIR_FILE" 2>/dev/null)
- if [ -n "$HAS_YAML" ]; then
- DATE=$(sed '/^---/,$d' $INDIR/$DIR_FILE | \
- grep -e'^date:' | sed -e 's/^date: \(.*\)$/\1/g')
- DIR_HTML="$DIR_HTML\n<li><a href=\"$DIR_FILE_HTML\">$DATE</a></li>\n"
- fi
- done <<< "$DIR_FILES"
- DIR_HTML="$DIR_HTML\n</ul><!--dir-->\n"
- DIR_HTML=$(echo "$DIR_HTML" | \
- sed -e's/\//\\\//g' -e's/\[/\\\[/g' -e's/\./\\\./g' \
- -e's/\"/\\\"/g')
- DOC=$(echo "$DOC" | \
- sed -e "s/{dir \"$FORMAT\" \"$DIR_PATTERN\"}/$DIR_HTML/g")
-done <<< "$DIR_COMMANDS"
-
if [ $BODY_ONLY -eq 0 ]; then
begin_html
begin_head
@@ -309,6 +330,7 @@ if [ $BODY_ONLY -eq 0 ]; then
end_head
begin_body
fi
+[ -n "${VARS[title]}" ] && echo "<h2>${VARS[title]}</h2>"
body "$DOC"
if [ $BODY_ONLY -eq 0 ]; then
end_body