commit a8bc142aa12c5e9356f1f1803f191df1adc59fdc
parent af4c1d7c73f534600610ec699491a5a4ee4ccc64
Author: Hugo Soucy <hugo@soucy.cc>
Date: Mon, 5 Jun 2017 19:32:41 -0400
Add or modify functions
Diffstat:
5 files changed, 130 insertions(+), 79 deletions(-)
diff --git a/functions/create-html-pages b/functions/create-html-pages
@@ -1,62 +1,95 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Create all the HTML pages with pandoc
create_html_pages () {
- echo "- Create all the HTML pages with pandoc"
-
- get_pandoc_templates
+ echo "- Create all the HTML pages"
# Create the homepage
- pandoc --template="$TPL_PANDOC_PATH/index.html" \
- -o "$CONTENT_PATH/index.html" "$CONTENT_PATH/index.md"
+ create_homepage () {
+ # Load the meta file of the homepage
+ . "$CONTENT_PATH/index.meta"
- # Then create others
- case "$1" in
- true)
- find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \))
- rm -R "$PUBLICHTML_PATH/"*
- [ -d "$TMP_PATH/" ] && rm -R "$TMP_PATH/"*
- ;;
- false)
- find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \))
- ;;
- esac
-
- for markdown in $find_noindex_markdown; do
- # Markdown files names without path
- outputname=$(basename "$markdown")
-
- # Parse the YAML block of the markdown
- eval "$(parse_yaml "$markdown" "config_")"
-
- # Get the value of the template config
- templatename=$config_template
-
- # Get the relative path of the markdown file
- page_path="$(realpath --relative-to=$CONTENT_PATH $markdown)"
-
- # Create an unique ID for each content
- page_id="tag:$SITE_DOMAINNAME,${config_date}:${config_date:0:4}/${config_date:5:2}/${outputname%.*}"
-
- # Check if a section have a specific template or use the default template
- if [[ " ${templates[*]} " == *" $templatename "* ]]; then
- 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" \
- -o "$(dirname "$markdown")/${outputname%.*}.html"
-
- else
- pandoc -s "$markdown" \
- --template="$TPL_PANDOC_PATH/default.html" \
- --variable=template:"default" \
- --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \
- --variable=permalink:"$BASE_URL/${page_path%.*}.html" \
- -o "$(dirname "$markdown")/${outputname%.*}.html"
+ local page_title=$title
+ local description="$description"
+ local keywords="$keywords"
+
+ if [ ! -z "$description" ]; then
+ has_description=true
fi
- echo "$config_date|$config_datetime|$BASE_URL/${page_path%.*}.html|$config_title|$page_id"
- done | sort -nr -o "$FAKESTACHE_PATH"/"$DB"
+ if [ ! -z "$keywords" ]; then
+ has_keywords=true
+ fi
+
+ # Convert markdown to html
+ local main_content=$(make_html_from_md "$CONTENT_PATH/index.md")
+
+ mo "$TPL_MUSTACHE_PATH/index.mustache" > "$CONTENT_PATH/index.html"
+ }
+
+ # Then create others
+ create_allpages () {
+ rm -R "$PUBLICHTML_PATH/"*
+ [ -d "$TMP_PATH/" ] && rm -R "$TMP_PATH/"*
+
+ get_templates
+
+ for markdown in $(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \)); do
+ # Markdown files names without path
+ local outputname=$(basename "$markdown")
+
+ # Get the relative path of the markdown file
+ local page_path="${markdown#$CONTENT_PATH}"
+
+ # Load the meta file of the markdown
+ . "${markdown%.*}.meta"
+
+ local page_title="$title"
+ local date="$date"
+ local datetime="$datetime"
+ local modified="$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)"
+ local templatename="$template"
+ local permalink="$BASE_URL${page_path%.*}.html"
+ local description="$description"
+ local keywords="$keywords"
+
+ if [ ! -z "$description" ]; then
+ has_description=true
+ fi
+
+ if [ ! -z "$keywords" ]; then
+ has_keywords=true
+ fi
+
+ # Convert markdown to html
+ local main_content="$(make_html_from_md "$markdown")"
+
+ # Create an unique ID for each content
+ local page_id="tag:$SITE_DOMAINNAME,${date}:${date:0:4}/${date:5:2}/${outputname%.*}"
+
+ # Check if the specified template exist
+ if is_in_array "$templatename" "${templates[@]}"; then
+ mo "$TPL_MUSTACHE_PATH/${templatename}.mustache" > "$(dirname "$markdown")/${outputname%.*}.html"
+ else
+ mo "$TPL_MUSTACHE_PATH/default.mustache" > "$(dirname "$markdown")/${outputname%.*}.html"
+ fi
+
+ unset description
+ unset has_description
+ unset keywords
+ unset has_keywords
+
+ echo "$date|$datetime|$BASE_URL${page_path%.*}.html|$page_title|$page_id"
+ done | sort -nr -o "$FAKESTACHE_PATH"/"$DB"
+ }
+
+ create_homepage
+ unset description
+ unset has_description
+ unset keywords
+ unset has_keywords
+
+ create_allpages
move_html_to_publichtml
}
diff --git a/functions/create-html-sections b/functions/create-html-sections
@@ -4,61 +4,58 @@
create_html_sections () {
echo "- Create section page list"
- get_pandoc_templates
+ get_templates
for indexsubdir in $(find "$CONTENT_PATH/" -mindepth 2 -name index.md -exec dirname {} \;); do
- if [[ " ${templates[*]} " == *" $(basename "$indexsubdir") "* ]]; then
- tplname="$(basename "$indexsubdir")"
+ if is_in_array "$(basename "$indexsubdir")" "${templates[@]}"; then
+ local tplname="$(basename "$indexsubdir")"
else
- tplname=default
+ local tplname=default
fi
# For each section page create a temporary "includes" folder
mkdir -p "$TMP_PATH/$(basename "$indexsubdir")"
- tmp_folder="$TMP_PATH/$(basename "$indexsubdir")"
+ local tmp_folder="$TMP_PATH/$(basename "$indexsubdir")"
+
+ # Convert markdown to html
+ local main_content=$(make_html_from_md "$indexsubdir/index.md")
# 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")"
+ local outputname="$(basename "$markdown")"
+
+ # Get the relative path of the markdown file
+ local page_path="${markdown#$CONTENT_PATH}"
- # Parse the YAML block of the markdown
- eval "$(parse_yaml "$markdown" "config_")"
+ # Load the meta file of the markdown
+ . "${markdown%.*}.meta"
# Set the variable for the date
- markdown_date="$config_date$config_datetime"
+ local markdown_date="$date$datetime"
- # Set the variable for the URL
- url=$(find "$PUBLICHTML/" -type f -name "${outputname%.*}".html;)
+ # Set the variable for the permalink
+ local permalink=$(find "$PUBLICHTML/" -type f -name "${outputname%.*}".html;)
+ local permalink="$BASE_URL/${permalink#*/}"
# 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 "$tmp_folder/$markdown_date-${outputname%.*}".inc.html
+ mo "$TPL_MUSTACHE_PATH/${tplname}-index.inc.mustache" > "$tmp_folder/$markdown_date-${outputname%.*}".inc.html
done
# Create symlinks for images in section's landing page
for img in $(find "$indexsubdir/" -type f \( -name "*.jpg" -or -name "*.png" \)); do
- rel_img_path=$(realpath --relative-to=$indexsubdir $img)
+ rel_img_path=${img#$indexsubdir}
- $(ln -s -f "$rel_img_path" "$indexsubdir")
+ $(ln -s -f "$rel_img_path" "$indexsubdir")
done
if test "$(ls -A "$tmp_folder/")"; then
# Sort all the includes files
# 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
-
- # 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"
+ local list_items=$(cat $(find "$tmp_folder/" -type f -name \*.inc.html | sort -nr))
+
+ mo "$TPL_MUSTACHE_PATH/${tplname}-index.mustache" > "$indexsubdir/index.html"
fi
done
diff --git a/functions/get-archetypes b/functions/get-archetypes
@@ -4,7 +4,7 @@
get_archetypes () {
archetypes=()
- for archetype in $ARCHETYPES_PATH/*; do
+ for archetype in $ARCHETYPES_PATH/*md; do
# Template name without path
archetypename=$(basename "$archetype")
# Push templates names in the array
diff --git a/functions/get-templates b/functions/get-templates
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+
+# Create an array with templates names
+get_templates () {
+ templates=()
+
+ for template in $(find "$TPL_MUSTACHE_PATH/" -type f \( -name "*.mustache" \! -name "default.mustache" ! -name "*.inc.mustache" ! -name "*-index.mustache" \)); do
+ # Template name without path
+ templatename=$(basename "$template")
+ # Push templates names in the array
+ templates+=(${templatename%.*})
+ done
+
+ #echo ${templates[@]}
+}
diff --git a/functions/make-html-from-md b/functions/make-html-from-md
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+# Create HTML files with the Markdown.pl script
+make_html_from_md () {
+ "$FAKESTACHE_PATH/lib/markdown/Markdown.pl" $1
+}