commit
69bfb3d395
4 changed files with 136 additions and 34 deletions
@ -0,0 +1,60 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
|
||||||
|
# This file is responsible for generating an html structure of documents |
||||||
|
# All md files will be converted to html |
||||||
|
# Everything else will be copied exactly |
||||||
|
|
||||||
|
# The table of contents will be a nested ul structure |
||||||
|
# The top level will be the tags, under each tag there will be a list of documents that are tagged with that tag |
||||||
|
# This will result in doucuments being listed multiple times, once for each tag they are in |
||||||
|
generate-html-toc(){ |
||||||
|
echo "<nav><ul>" |
||||||
|
# Loop through each tag |
||||||
|
listTags --noheader | while read item; do |
||||||
|
local tag="$(echo "$item" | awk -F ' +' '{print $1}')" |
||||||
|
local count="$(echo "$item" | awk -F ' +' '{print $2}')" |
||||||
|
echo "<li>" |
||||||
|
echo "$tag ($count)" |
||||||
|
echo "<ul>" |
||||||
|
echo "SELECT items.filename,items.title |
||||||
|
FROM items LEFT JOIN links ON items.id = links.itemID |
||||||
|
LEFT JOIN tags ON links.tagID = tags.id |
||||||
|
WHERE tags.name = '$(safeSQL "$tag")' |
||||||
|
GROUP BY items.id;" | |
||||||
|
sqlite3 "${sqliteFile}" | |
||||||
|
awk -F '|' '{sub(/\.md/,".html",$1);print "<li><a href=\"" $1 "\">" $2 "</a></li>"}' |
||||||
|
echo "</ul>" |
||||||
|
echo "</li>" |
||||||
|
done |
||||||
|
echo "</ul></nav>" |
||||||
|
} |
||||||
|
|
||||||
|
to-html(){ |
||||||
|
local destination="$1" |
||||||
|
local preTemplate="/usr/local/share/kb/templates/main.html" |
||||||
|
local tocFile="$(mktemp)" |
||||||
|
local templateFile="$(mktemp)" |
||||||
|
generate-html-toc > "$tocFile" |
||||||
|
|
||||||
|
# If there is a template in the users .local/share directory, use that |
||||||
|
[ -e "${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html" ] && |
||||||
|
preTemplate="${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html" |
||||||
|
|
||||||
|
# If there is a template in the data directory, use that |
||||||
|
[ -e "${dataDir}templates/main.html" ] && |
||||||
|
preTemplate="${dataDir}templates/main.html" |
||||||
|
|
||||||
|
|
||||||
|
sed "s#\#TOC\##\${ $tocFile() }#" "$preTemplate" > "$templateFile" |
||||||
|
|
||||||
|
|
||||||
|
find "$dataDir" -name "*.md" | while read file; do |
||||||
|
local newFile="${file##*/}" |
||||||
|
newFile="${newFile/.md/.html}" |
||||||
|
sed -E 's/\.md( *)\)/.html\1\)/' "$file" | |
||||||
|
pandoc -f markdown -t html --template "$templateFile" > "$destination/$newFile" |
||||||
|
done |
||||||
|
|
||||||
|
rm "$tocFile" "$templateFile" |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="en"> |
||||||
|
<head> |
||||||
|
<meta charset="utf-8" /> |
||||||
|
<meta name="generator" content="KB" /> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
||||||
|
$if(Tags)$ |
||||||
|
<meta name="keywords" content="$for(Tags)$$Tags$, $endfor$" /> |
||||||
|
$endif$ |
||||||
|
<title>$Title$</title> |
||||||
|
</head> |
||||||
|
<body> |
||||||
|
|
||||||
|
#TOC# |
||||||
|
|
||||||
|
$body$ |
||||||
|
</body> |
||||||
|
</html> |
Loading…
Reference in new issue