generate website in separate folder

This commit is contained in:
Akbar Rahman 2021-05-01 13:37:23 +01:00
parent 32e2aeff45
commit b452df9822
2 changed files with 19 additions and 14 deletions

View File

@ -5,6 +5,7 @@
# set default config values, load user config, export config variables # set default config values, load user config, export config variables
name="" name=""
output="web"
article_template="/opt/notes2web/templates/article.html" article_template="/opt/notes2web/templates/article.html"
textarticlehead_template="/opt/notes2web/templates/textarticlehead.html" textarticlehead_template="/opt/notes2web/templates/textarticlehead.html"
textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html" textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html"
@ -18,6 +19,7 @@ do
done done
export name export name
export output
export article_template export article_template
export textarticlehead_template export textarticlehead_template
export textarticlefoot_template export textarticlefoot_template
@ -28,12 +30,13 @@ export stylesheet
function _renderarticle { function _renderarticle {
echo "rendering $1" echo "rendering $1"
mkdir -p "$(dirname "$output/${1}.html")"
pandoc\ pandoc\
--toc\ --toc\
--standalone\ --standalone\
-t html\ -t html\
--template "$article_template"\ --template "$article_template"\
-o "${1}.html"\ -o "$output/${1}.html"\
"$1"\ "$1"\
--mathjax --mathjax
} }
@ -42,16 +45,17 @@ function _renderarticle {
function _rendertextarticle { function _rendertextarticle {
[[ "$(file -b "$1")" == "ASCII text" ]] || exit [[ "$(file -b "$1")" == "ASCII text" ]] || exit
echo "rendering text file $1" echo "rendering text file $1"
mkdir -p "$(dirname "$output/${1}.html")"
sed -e "s#\\\$title\\\$#$1#" "$textarticlehead_template"\ sed -e "s#\\\$title\\\$#$1#" "$textarticlehead_template"\
> "${1}.html" > "$output/${1}.html"
cat "$1" >> "${1}.html" cat "$1" >> "$output/${1}.html"
cat "$textarticlefoot_template" >> "${1}.html" cat "$textarticlefoot_template" >> "$output/${1}.html"
} }
function _adddirtoindex { function _adddirtoindex {
dir="$(dirname "$1")" dir="$(dirname "$1")"
echo "<h2>$(basename "$dir") notes</h2>" >> index.md echo "<h2>$(basename "$dir") notes</h2>" >> $output/index.md
find "$dir" -name '*.md' -exec bash -c "_addarticletoindex '{}'" \; find "$dir" -name '*.md' -exec bash -c "_addarticletoindex '{}'" \;
find "$dir" -not -path '**/.git/**' -not -name '*.md' -type f -exec bash -c "_addtextarticletoindex '{}'" \; find "$dir" -not -path '**/.git/**' -not -name '*.md' -type f -exec bash -c "_addtextarticletoindex '{}'" \;
} }
@ -65,7 +69,7 @@ function _addtextarticletoindex {
-V "title=$1"\ -V "title=$1"\
--template "$listitem_template"\ --template "$listitem_template"\
"$1"\ "$1"\
>> index.md >> $output/index.md
} }
@ -76,7 +80,7 @@ function _addarticletoindex {
-V "filepath=${1}.html"\ -V "filepath=${1}.html"\
--template "$listitem_template"\ --template "$listitem_template"\
"$1"\ "$1"\
>> index.md >> $output/index.md
} }
@ -96,9 +100,9 @@ done
# create an intermediate markdown file of links to each article # create an intermediate markdown file of links to each article
echo "---" > index.md echo "---" > $output/index.md
[[ -z "$name" ]] && echo "title: notes" >> index.md || echo "title: ${name}'s notes" >> index.md [[ -z "$name" ]] && echo "title: notes" >> $output/index.md || echo "title: ${name}'s notes" >> $output/index.md
echo "---" >> index.md echo "---" >> $output/index.md
# mark folders to be included in notes2web's index # mark folders to be included in notes2web's index
@ -113,12 +117,12 @@ find -name '.2web' -exec bash -c "_adddirtoindex '{}'" \;
echo "copying styles.css to current directory" echo "copying styles.css to current directory"
cp "$stylesheet" ./styles.css cp "$stylesheet" "$output/styles.css"
echo "rendering index.md" echo "rendering index.md"
pandoc\ pandoc\
-t html\ -t html\
--template "$index_template"\ --template "$index_template"\
-o index.html\ -o "$output/index.html"\
"index.md" "$output/index.md"

View File

@ -34,7 +34,8 @@ directory.
Default config values: Default config values:
```bash ```bash
name="" name="" # your name
output="web" # the folder where the website will be generated in
article_template="/opt/notes2web/templates/article.html" article_template="/opt/notes2web/templates/article.html"
textarticlehead_template="/opt/notes2web/templates/textarticlehead.html" textarticlehead_template="/opt/notes2web/templates/textarticlehead.html"
textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html" textarticlefoot_template="/opt/notes2web/templates/textarticlefoot.html"