summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-08-24 14:20:27 +0100
committerPaul Buetow <paul@buetow.org>2024-08-24 14:20:27 +0100
commita0cdf880c32264165f1af87d7f0465d3923ffe88 (patch)
treef5b4ccb757c4bd053e694139cb96f28e2bb7d320
parent28e275da0a1b9db74e1d93cfff80c4af1214dff6 (diff)
nicer ToC for HTML
-rw-r--r--lib/gemfeed.source.sh1
-rw-r--r--lib/html.source.sh36
-rw-r--r--lib/notes.source.sh2
-rw-r--r--lib/template.source.sh9
4 files changed, 35 insertions, 13 deletions
diff --git a/lib/gemfeed.source.sh b/lib/gemfeed.source.sh
index d888866..f069ef5 100644
--- a/lib/gemfeed.source.sh
+++ b/lib/gemfeed.source.sh
@@ -61,6 +61,5 @@ GEMFEED
mv "$gemfeed_dir/index.gmi.tmp" "$gemfeed_dir/index.gmi"
-
gemfeed::updatemainindex
}
diff --git a/lib/html.source.sh b/lib/html.source.sh
index 1666239..f30cb22 100644
--- a/lib/html.source.sh
+++ b/lib/html.source.sh
@@ -30,7 +30,6 @@ html::make_heading () {
local -r id=$(tr -cd 'A-Za-z0-9' <<< "$text")
if [ "$HTML_VARIANT_TO_USE" = exact ]; then
- #echo "<span class='h${level}'>$(html::encode "$text")</span><br />"
echo "<h${level} style='display: inline' id='${id}'>$(html::encode "$text")</h${level}><br />"
else
echo "<h${level} id='${id}'>$(html::encode "$text")</h${level}><br />"
@@ -139,6 +138,33 @@ html::source_highlight () {
fi
}
+html::list::encode () {
+ local text="$1"; shift
+
+ if [[ "$text" != '.'* ]]; then
+ # No ToC
+ html::encode "$text"
+ return
+ fi
+
+ local -i toc_indent=0
+
+ # If there's a . (dot) in the liste element, it then indicates a ToC element
+ while [[ "$text" == '.'* ]]; do
+ text="$($SED 's/\.//' <<< "$text")"
+ : $(( toc_indent++ ))
+ done
+
+ while [ $toc_indent -ge 2 ]; do
+ echo -n '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '
+ : $(( toc_indent-- ))
+ done
+
+ text="${text/ /}"
+ local -r id=$(tr -cd 'A-Za-z0-9' <<< "$text")
+ echo "<a href='#$id')'>$(html::encode "$text")</a>"
+}
+
# Convert Gemtext to HTML
html::fromgmi () {
local is_list=no
@@ -148,9 +174,8 @@ html::fromgmi () {
while IFS='' read -r line; do
if [[ "$is_list" == yes ]]; then
- if [[ "$line" == '* '* ]]; then
- echo "<li>$(html::encode "${line/\* /}")</li>" |
- html::process_inline
+ if [[ "$line" == '* '* ]]; then
+ echo "<li>$(html::list::encode "${line/\* /}")</li>" | html::process_inline
else
is_list=no
if [ "$HTML_VARIANT_TO_USE" = exact ]; then
@@ -180,8 +205,7 @@ $line"
'* '*)
is_list=yes
echo "<ul>"
- echo "<li>$(html::encode "${line/\* /}")</li>" |
- html::process_inline
+ echo "<li>$(html::list::encode "${line/\* /}")</li>" | html::process_inline
;;
'```'*)
language=$(cut -d'`' -f4 <<< "$line")
diff --git a/lib/notes.source.sh b/lib/notes.source.sh
index 0f5251d..bdea5fc 100644
--- a/lib/notes.source.sh
+++ b/lib/notes.source.sh
@@ -18,6 +18,8 @@ notes::generate () {
log INFO "Generating Notes index for $notes_dir"
+ log INFO "Hello world"
+
cat <<NOTES > "$notes_dir/index.gmi.tmp"
# Notes on $DOMAIN
diff --git a/lib/template.source.sh b/lib/template.source.sh
index 519f2cf..f6b25a9 100644
--- a/lib/template.source.sh
+++ b/lib/template.source.sh
@@ -92,20 +92,17 @@ template::inline::index () {
# To generate a table of contents
template::inline::toc () {
- echo '```'
- echo 'Table of contents'
- echo '================='
+ echo '## Table of Contents'
echo ''
< "$(basename "$CURRENT_TPL")" $SED -E -n '
/^```/,/^```/! {
/^#+ / {
- s/#/ /g
- s/^ //
+ s/#/* ./
+ s/#/./g
p
}
}
'
- echo '```'
}
template::test () {