Adds the ability to convert to html

Issue #14

I still want, at some point, to add to other formats but this is fine
for now.

The tool uses pandoc to do the conversion from md to html

A sample template (without any styling) is provided. This can be
overwritten in $HOME/.config/kb/templates/main.html or in the
knowledgebase directory under `templates`.
master
Jonathan Hodgson 4 years ago
parent 4c891efdce
commit 7d554d5326
  1. 2
      Makefile
  2. 28
      inc/to-html
  3. 2
      kb
  4. 18
      templates/main.html

@ -9,6 +9,8 @@ install:
mkdir -p $(DESTDIR)$(PREFIX)/bin mkdir -p $(DESTDIR)$(PREFIX)/bin
sed '/^source/d' inc/* kb > $(DESTDIR)$(PREFIX)/bin/kb sed '/^source/d' inc/* kb > $(DESTDIR)$(PREFIX)/bin/kb
chmod +x $(DESTDIR)$(PREFIX)/bin/kb chmod +x $(DESTDIR)$(PREFIX)/bin/kb
mkdir -p $(DESTDIR)$(PREFIX)/share/kb
cp -r templates $(DESTDIR)$(PREFIX)/share/kb
uninstall: uninstall:

@ -31,6 +31,30 @@ generate-html-toc(){
to-html(){ to-html(){
local destination="$1" local destination="$1"
local toc="$(generate-html-toc)" local preTemplate="/usr/local/share/kb/templates/main.html"
echo "$toc" 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"
} }

2
kb

@ -22,7 +22,7 @@ WHITE='\033[1;37m'
NC='\033[0m' NC='\033[0m'
# Provide a variable with the location of this script. # Provide a variable with the location of this script.
#scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Source files # Source files
# ################################################## # ##################################################

@ -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…
Cancel
Save