hugosoucycc

[ARCHIVED] Another old source code of <hugo.soucy.cc>.
Log | Files | Refs | Submodules

commit 4aaa235848246741e4492ec2e7ed77851d0eff7c
parent bdc54f3b1b9a75200975c4edf927c32dbced7aac
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sun, 31 Jul 2016 13:54:31 -0400

Move main functions outside panstash.sh

Diffstat:
Afunctions/build-pandoc-templates.sh | 28++++++++++++++++++++++++++++
Afunctions/clean-content-folder.sh | 13+++++++++++++
Afunctions/create-html-pages.sh | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Afunctions/create-html-sections.sh | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Afunctions/get-static-files.sh | 8++++++++
Afunctions/move-html-to-publichtml.sh | 8++++++++
Mpanstash.sh | 161+++++++++++--------------------------------------------------------------------
7 files changed, 181 insertions(+), 140 deletions(-)

diff --git a/functions/build-pandoc-templates.sh b/functions/build-pandoc-templates.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Convert Mustache templates into Pandoc templates +build_pandoc_templates () { + echo "Convert Mustache templates into Pandoc templates" + + # Purge the $TPL_PANDOC_PATH/ folder before the conversion + rm -Rf $TPL_PANDOC_PATH/*.html + + for mustache in $TPL_MUSTACHE_PATH/*.mustache; do + # Remove files path + mustachename=$(basename "$mustache") + # And then the convertion without the mustache extension + $PANSTASH_PATH/lib/mo/mo $mustache > $TPL_PANDOC_PATH/${mustachename%.*}.html + done + # End + + # Create an array with templates names + templates=() + + for template in $TPL_PANDOC_PATH/*; do + # Template name without path + templatename=$(basename "$template") + # Push templates names in the array + templates+=(${templatename%.*}) + done + # End +} diff --git a/functions/clean-content-folder.sh b/functions/clean-content-folder.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Then remove those in the content folder +clean_content_folder () { + echo "Clean the content/ folder from all the HTML files" + + find $CONTENT_PATH/ -name \*.html -type f -delete + + # After that remove empty directories + echo "Clean the content/ folder from all the empty directories" + + find $CONTENT_PATH/ -type d -empty -delete +} diff --git a/functions/create-html-pages.sh b/functions/create-html-pages.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# +#. functions/move-html-to-publichtml.sh + +# Create all the HTML pages with pandoc +create_html_pages () { + echo "Create all the HTML pages with pandoc" + + # Create the homepage + pandoc --template=$TPL_PANDOC_PATH/index.html -o $CONTENT_PATH/index.html $CONTENT_PATH/index.md + + # Then create others + for markdown in $(find $CONTENT_PATH/ -mindepth 2 -type f -name \*.md); do + # Parent folder name without path + section=$(basename $(dirname "$markdown")) + + # Markdown files names without path + outputname=$(basename "$markdown") + + # Parse the YAML block of the markdown + eval $(parse_yaml $markdown "config_") + + if [[ "$config_date" != "null" ]]; then + # Get year and month + year=${config_date:0:4} + month=${config_date:5:2} + + # First create year and month folders + mkdir -p $(dirname "$markdown")/$year/$month + fi + + # Check if a section have a specific template or use the default template + if [[ " ${templates[*]} " == *" $section "* ]]; then + # Check if the date property value is not "null" + if [[ "$config_date" != "null" ]]; then + pandoc -s $markdown --template=$TPL_PANDOC_PATH/${section}.html -o $(dirname "$markdown")/$year/$month/${outputname%.*}.html + else + pandoc -s $markdown --template=$TPL_PANDOC_PATH/${section}.html -o $(dirname "$markdown")/${outputname%.*}.html + fi + + else + if [[ "$config_date" != "null" ]]; then + pandoc -s $markdown --template=$TPL_PANDOC_PATH/default.html -o $(dirname "$markdown")/$year/$month/${outputname%.*}.html + else + pandoc -s $markdown --template=$TPL_PANDOC_PATH/default.html -o $(dirname "$markdown")/${outputname%.*}.html + fi + fi + done + + move_html_to_publichtml +} diff --git a/functions/create-html-sections.sh b/functions/create-html-sections.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Create section page list +create_html_sections () { + echo "Create section page list" + + for indexsubdir in $(find $CONTENT_PATH/ -mindepth 2 -name index.md -exec dirname {} \;); do + # For each section page create a temporary "includes" folder + mkdir $indexsubdir/includes + + if [[ " ${templates[*]} " == *" $(basename "$indexsubdir") "* ]]; then + tplname=$(basename "$indexsubdir") + else + tplname=default + fi + + # For all markdown files that are not "index.md" + for markdown in $(find $indexsubdir/ -type f \( -name "*.md" ! -name "index.md" \)); do + # Markdown files names without path + outputname=$(basename "$markdown") + + # Parse the YAML block of the markdown + eval $(parse_yaml $markdown "config_") + + # Set the variable for the date + markdown_date=$config_date + + # Set the variable for the URL + url=$(find $PUBLICHTML/ -type f -name ${outputname%.*}.html;) + + # Create all the includes files that make up section page and put them into the "includes" folder + pandoc $markdown -s --variable=url:$BASE_URL/${url#*/} --template=$TPL_PANDOC_PATH/"$tplname"-index.inc.html -t html5 -o $indexsubdir/includes/$markdown_date-${outputname%.*}.inc.html + done + + if test "$(ls -A "$indexsubdir/includes/")"; then + # Sort all the includes files + sorted_includes=$(find $indexsubdir/includes/ -type f -name \*.inc.html | sort -nr) + + # Create an HTML file with all the includes in descending order + pandoc -t html5 $sorted_includes -o $indexsubdir/includes/includes.html --parse-raw + + # Merge the "includes.html" and "index.md" to create the section page list + pandoc -t html5 $indexsubdir/index.md -s --template=$TPL_PANDOC_PATH/"$tplname"-index.html -A $indexsubdir/includes/includes.html -o $indexsubdir/index.html + + # Remove the temporary "includes" folder and all his content + rm -Rf $indexsubdir/includes/ + fi + done + + move_html_to_publichtml +} diff --git a/functions/get-static-files.sh b/functions/get-static-files.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Rsync the static files into the public_html/ folder +get_static_files () { + echo "Rsync the static files into the public_html/ folder" + + rsync -avmh $ASSETS_PATH/ $PUBLICHTML_PATH/ +} diff --git a/functions/move-html-to-publichtml.sh b/functions/move-html-to-publichtml.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Rsync all HTML files and folders to the public_html folder +move_html_to_publichtml () { + echo "Rsync all HTML files and folders to the public_html/ folder" + + rsync -avmh --include='*.html' -f 'hide,! */' $CONTENT_PATH/ $PUBLICHTML_PATH/ +} diff --git a/panstash.sh b/panstash.sh @@ -1,153 +1,34 @@ #!/bin/bash # -# PANSTASH - Yep! An other static website generator! +# PANSTASH - Yep! An Other Static Website Generator! # (Pandoc + Mustache + Bash) # + +# Dependencies : +# * Pandoc - Make sure it's installed on your machine : `$ pandoc -v`. +# * Mustache - Is already includes in pantash : `lib/mo/`. + # Include the main configuration file . config/config.sh # Include parse_yaml function . lib/parse_yaml.sh -# Convert Mustache templates into Pandoc templates -echo "01) Convert Mustache templates into Pandoc templates" - -# Purge the $TPL_PANDOC_PATH/ folder before the conversion -rm -Rf $TPL_PANDOC_PATH/*.html - -for mustache in $TPL_MUSTACHE_PATH/*.mustache; do - # Remove files path - mustachename=$(basename "$mustache") - # And then the convertion without the mustache extension - $PANSTASH_PATH/lib/mo/mo $mustache > $TPL_PANDOC_PATH/${mustachename%.*}.html -done -# End - -# Create an array with templates names -templates=() - -for template in $TPL_PANDOC_PATH/*; do - # Template name without path - templatename=$(basename "$template") - # Push templates names in the array - templates+=(${templatename%.*}) -done -# End - -# Empty the public_html/ folder -# rm -Rf PUBLICHTML_PATH/* - -# Create all the HTML pages with pandoc -echo "02) Create all the HTML pages with pandoc" - -# Create the homepage -pandoc --template=$TPL_PANDOC_PATH/index.html -o $CONTENT_PATH/index.html $CONTENT_PATH/index.md - -# Then create others -for markdown in $(find $CONTENT_PATH/ -mindepth 2 -type f -name \*.md); do - # Parent folder name without path - section=$(basename $(dirname "$markdown")) - - # Markdown files names without path - outputname=$(basename "$markdown") - - # Parse the YAML block of the markdown - eval $(parse_yaml $markdown "config_") - - if [[ "$config_date" != "null" ]]; then - # Get year and month - year=${config_date:0:4} - month=${config_date:5:2} - - # First create year and month folders - mkdir -p $(dirname "$markdown")/$year/$month - fi - - # Check if a section have a specific template or use the default template - if [[ " ${templates[*]} " == *" $section "* ]]; then - # Check if the date property value is not "null" - if [[ "$config_date" != "null" ]]; then - pandoc -s $markdown --template=$TPL_PANDOC_PATH/${section}.html -o $(dirname "$markdown")/$year/$month/${outputname%.*}.html - else - pandoc -s $markdown --template=$TPL_PANDOC_PATH/${section}.html -o $(dirname "$markdown")/${outputname%.*}.html - fi - - else - if [[ "$config_date" != "null" ]]; then - pandoc -s $markdown --template=$TPL_PANDOC_PATH/default.html -o $(dirname "$markdown")/$year/$month/${outputname%.*}.html - else - pandoc -s $markdown --template=$TPL_PANDOC_PATH/default.html -o $(dirname "$markdown")/${outputname%.*}.html - fi - fi -done - -# Rsync all HTML files and folders to the public_html folder -echo "03) Rsync all HTML files and folders to the public_html/ folder" - -rsync -avmh --include='*.html' -f 'hide,! */' $CONTENT_PATH/ $PUBLICHTML_PATH/ - -# Create section page list -echo "04) Create section page list" -for indexsubdir in $(find $CONTENT_PATH/ -mindepth 2 -name index.md -exec dirname {} \;); do - # For each section page create a temporary "includes" folder - mkdir $indexsubdir/includes - - if [[ " ${templates[*]} " == *" $(basename "$indexsubdir") "* ]]; then - tplname=$(basename "$indexsubdir") - else - tplname=default - fi - - # For all markdown files that are not "index.md" - for markdown in $(find $indexsubdir/ -type f \( -name "*.md" ! -name "index.md" \)); do - # Markdown files names without path - outputname=$(basename "$markdown") - - # Parse the YAML block of the markdown - eval $(parse_yaml $markdown "config_") - - # Set the variable for the date - markdown_date=$config_date - - # Set the variable for the URL - url=$(find $PUBLICHTML/ -type f -name ${outputname%.*}.html;) - - # Create all the includes files that make up section page and put them into the "includes" folder - pandoc $markdown -s --variable=url:$BASE_URL/${url#*/} --template=$TPL_PANDOC_PATH/"$tplname"-index.inc.html -t html5 -o $indexsubdir/includes/$markdown_date-${outputname%.*}.inc.html - done - - if test "$(ls -A "$indexsubdir/includes/")"; then - # Sort all the includes files - sorted_includes=$(find $indexsubdir/includes/ -type f -name \*.inc.html | sort -nr) - - # Create an HTML file with all the includes in descending order - pandoc -t html5 $sorted_includes -o $indexsubdir/includes/includes.html --parse-raw - - # Merge the "includes.html" and "index.md" to create the section page list - pandoc -t html5 $indexsubdir/index.md -s --template=$TPL_PANDOC_PATH/"$tplname"-index.html -A $indexsubdir/includes/includes.html -o $indexsubdir/index.html - - # Remove the temporary "includes" folder and all his content - rm -Rf $indexsubdir/includes/ - fi -done - -# Rsync the new HTML files of the section pages to the public_html/ folder -echo "05) Rsync the new HTML files of the section pages to the public_html/ folder" - -rsync -avmh --include='*.html' -f 'hide,! */' $CONTENT_PATH/ $PUBLICHTML_PATH/ - -# Rsync the static files into the public_html/ folder -echo "06) Rsync the static files into the public_html/ folder" -rsync -avmh $ASSETS_PATH/ $PUBLICHTML_PATH/ - -# Then remove those in the content folder -echo "07) Clean the content/ folder from all the HTML files" - -find $CONTENT_PATH/ -name \*.html -type f -delete +# Include all the main functions +. functions/build-pandoc-templates.sh +. functions/move-html-to-publichtml.sh +. functions/create-html-pages.sh +. functions/create-html-sections.sh +. functions/get-static-files.sh +. functions/clean-content-folder.sh -# After that remove empty directories -echo "08) Clean the content/ folder from all the empty directories" +# Execute main functions +build_pandoc_templates +create_html_pages +create_html_sections +get_static_files +clean_content_folder -find $CONTENT_PATH/ -type d -empty -delete +echo "Your new website is ready here : $PUBLICHTML_PATH/ . Thanks Pandoc!!" -echo "09) Your new website is ready here : $PUBLICHTML_PATH/" +exit