diff --git a/Makefile b/Makefile index 15cddcf..ae34208 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ install: mkdir -p $(DESTDIR)$(PREFIX)/bin sed '/^source/d' inc/* kb > $(DESTDIR)$(PREFIX)/bin/kb chmod +x $(DESTDIR)$(PREFIX)/bin/kb + mkdir -p $(DESTDIR)$(PREFIX)/share/kb + cp -r templates $(DESTDIR)$(PREFIX)/share/kb uninstall: diff --git a/inc/to-html b/inc/to-html index e01990a..9bf5f1b 100644 --- a/inc/to-html +++ b/inc/to-html @@ -31,6 +31,30 @@ generate-html-toc(){ to-html(){ local destination="$1" - local toc="$(generate-html-toc)" - echo "$toc" + 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" + } diff --git a/kb b/kb index 526ca26..f5d8519 100755 --- a/kb +++ b/kb @@ -22,7 +22,7 @@ WHITE='\033[1;37m' NC='\033[0m' # 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 # ################################################## diff --git a/templates/main.html b/templates/main.html new file mode 100644 index 0000000..c81b714 --- /dev/null +++ b/templates/main.html @@ -0,0 +1,18 @@ + + + + + + +$if(Tags)$ + +$endif$ +$Title$ + + + +#TOC# + +$body$ + +