From 12c2e63f83348fd57f50de4f43846889c03344c0 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Sat, 1 May 2021 13:02:35 +0100 Subject: [PATCH] render text files too --- notes2web | 38 ++++++++++++++++++++++++++++++---- readme.md | 2 ++ templates/textarticlefoot.html | 3 +++ templates/textarticlehead.html | 15 ++++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 templates/textarticlefoot.html create mode 100644 templates/textarticlehead.html diff --git a/notes2web b/notes2web index 1c82220..ed3c305 100755 --- a/notes2web +++ b/notes2web @@ -6,6 +6,8 @@ # set default config values, load user config, export config variables name="" article_template="/opt/notes2web/templates/article.html" +textarticlehead_template="/opt/notes2web/templates/textarticlehead.html" +textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html" listitem_template="/opt/notes2web/templates/listitem.html" index_template="/opt/notes2web/templates/index.html" stylesheet="/opt/notes2web/styles.css" @@ -17,6 +19,8 @@ done export name export article_template +export textarticlehead_template +export textarticlefoot_template export listitem_template export index_template export stylesheet @@ -29,16 +33,39 @@ function _renderarticle { --standalone\ -t html\ --template "$article_template"\ - -o "$(dirname "$1")/index.html"\ + -o "${1}.html"\ "$1"\ --mathjax } +function _rendertextarticle { + [[ "$(file -b "$1")" == "ASCII text" ]] || exit + echo "rendering text file $1" + sed -e "s#\\\$title\\\$#$1#" "$textarticlehead_template"\ + > "${1}.html" + cat "$1" >> "${1}.html" + cat "$textarticlefoot_template" >> "${1}.html" +} + + function _adddirtoindex { dir="$(dirname "$1")" echo "

$(basename "$dir") notes

" >> index.md find "$dir" -name '*.md' -exec bash -c "_addarticletoindex '{}'" \; + find "$dir" -not -path '**/.git/**' -not -name '*.md' -type f -exec bash -c "_addtextarticletoindex '{}'" \; +} + + +function _addtextarticletoindex { + [[ "$(file -b "$1")" == "ASCII text" ]] || exit + pandoc\ + -t html\ + -V "filepath=${1}.html"\ + -V "title=$1"\ + --template "$listitem_template"\ + "$1"\ + >> index.md } @@ -46,7 +73,7 @@ function _addarticletoindex { echo "adding $1 to list of notes" pandoc\ -t html\ - -V "filepath=$(dirname "$1")"\ + -V "filepath=${1}.html"\ --template "$listitem_template"\ "$1"\ >> index.md @@ -54,14 +81,17 @@ function _addarticletoindex { export -f _renderarticle +export -f _rendertextarticle export -f _adddirtoindex export -f _addarticletoindex +export -f _addtextarticletoindex #render each markdown file in every folder passed in args -for file in "$@" +for dir in "$@" do - find "$file" -name '*.md' -exec bash -c "_renderarticle '{}'" \; + find "$dir" -name '*.md' -exec bash -c "_renderarticle '{}'" \; + find "$dir" -not -path '**/.git/**' -not -name '*.md' -type f -exec bash -c "_rendertextarticle '{}'" \; done diff --git a/readme.md b/readme.md index a2f3d31..2bfd634 100644 --- a/readme.md +++ b/readme.md @@ -36,6 +36,8 @@ Default config values: ```bash name="" article_template="/opt/notes2web/templates/article.html" +textarticlehead_template="/opt/notes2web/templates/textarticlehead.html" +textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html" listitem_template="/opt/notes2web/templates/listitem.html" index_template="/opt/notes2web/templates/index.html" stylesheet="/opt/notes2web/styles.css" diff --git a/templates/textarticlefoot.html b/templates/textarticlefoot.html new file mode 100644 index 0000000..ae90cda --- /dev/null +++ b/templates/textarticlefoot.html @@ -0,0 +1,3 @@ + +

page generated by notes2web

+ diff --git a/templates/textarticlehead.html b/templates/textarticlehead.html new file mode 100644 index 0000000..4396f82 --- /dev/null +++ b/templates/textarticlehead.html @@ -0,0 +1,15 @@ + + + + + +$title$ + + + +

$title$

+

This file was not rendered by notes2head because it is a plaintext file, not a markdown + file. + Below is an unformatted representation of the file: +

+