commit a7e6917a4cdba77d5dba83b22c2e13130ad29931
parent ba3433af0e86c4611050796a5bf4019364df9536
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date: Mon, 7 Nov 2016 16:09:20 -0500
Enhance with some good pratices + add a test.
Diffstat:
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/functions/build-pandoc-templates b/functions/build-pandoc-templates
@@ -5,7 +5,7 @@ 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
+ rm -Rf "${TPL_PANDOC_PATH:?}/"*
# HTML Templates
for mustache in "$TPL_MUSTACHE_PATH/"*.mustache; do
@@ -13,14 +13,8 @@ build_pandoc_templates () {
mustachename=$(basename "$mustache")
# And then the convertion without the mustache extension
mo "$mustache" > "$TPL_PANDOC_PATH/${mustachename%.*}".html
- done
- # End
+ done
- # Feed Templates
- for mustachefeed in "$TPL_MUSTACHE_PATH/feed/"*.mustache; do
- # Remove files path
- mustachefeedname=$(basename "$mustachefeed")
- # And then the convertion without the mustache extension
- mo "$mustachefeed" > "$TPL_PANDOC_PATH/${mustachefeedname%.*}".txt
- done
+ # Feed Template
+ mo "$TPL_MUSTACHE_PATH/feed/feed.mustache" > "$TPL_PANDOC_PATH/feed.txt"
}
diff --git a/functions/create-html-pages b/functions/create-html-pages
@@ -14,7 +14,7 @@ create_html_pages () {
true)
find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \))
rm -R "$PUBLICHTML_PATH/"*
- rm -R "$TMP_PATH/"
+ rm -R "$TMP_PATH/"*
;;
false)
find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \) -mtime -1)
@@ -31,8 +31,7 @@ create_html_pages () {
# Get the value of the template config
templatename=$config_template
-
- # page_path="$year"/"$month"/"${outputname%.*}"
+
# Get the relative path of the markdown file
page_path="$(realpath --relative-to=$CONTENT_PATH $markdown)"
@@ -41,14 +40,14 @@ create_html_pages () {
pandoc -s "$markdown" \
--template="$TPL_PANDOC_PATH/${templatename}.html" \
--variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \
- --variable=permalink:"$BASE_URL/${page_path%.*}.html" \
+ --variable=permalink:"$BASE_URL/${page_path%.*}" \
-o "$(dirname "$markdown")/${outputname%.*}.html"
else
pandoc -s "$markdown" \
--template="$TPL_PANDOC_PATH/default.html" \
--variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \
- --variable=permalink:"$BASE_URL/${page_path%.*}.html" \
+ --variable=permalink:"$BASE_URL/${page_path%.*}" \
-o "$(dirname "$markdown")/${outputname%.*}.html"
fi
diff --git a/functions/create-html-sections b/functions/create-html-sections
@@ -37,7 +37,11 @@ create_html_sections () {
--variable=url:"$BASE_URL/${url#*/}" \
--template="$TPL_PANDOC_PATH/${tplname}-index.inc.html" \
-t html5 \
- -o "$tmp_folder/$markdown_date-${outputname%.*}".inc.html
+ -o "$tmp_folder/$markdown_date-${outputname%.*}".inc.html
+
+ page_path="$(realpath --relative-to=$CONTENT_PATH/ ${markdown%.*}.html)"
+
+ echo "------- $page_path"
done
if test "$(ls -A "$tmp_folder/")"; then
@@ -45,13 +49,13 @@ create_html_sections () {
# Create an HTML file with all the includes in descending order
pandoc -t html5 $(find "$tmp_folder/" -type f -name \*.inc.html | sort -nr) \
-o "$tmp_folder/tmp.html" \
- --parse-raw
+ --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 "$tmp_folder/tmp.html" \
- -o "$indexsubdir/index.html"
+ -A "$tmp_folder/tmp.html" \«
+ -o "$indexsubdir/index.html"
fi
done