hugosoucycc

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

commit 1db455e17a564e505a630c025943efe69a3179ec
parent 3909eb190731a39394c099b3af97a26fd5c36914
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Sun,  6 Nov 2016 19:36:34 -0500

Simplify the creations of pages and landing pages

Diffstat:
Mfunctions/create-html-pages | 71+++++++++++++++++++++++++++++++----------------------------------------
Mfunctions/create-html-sections | 27+++++----------------------
2 files changed, 36 insertions(+), 62 deletions(-)

diff --git a/functions/create-html-pages b/functions/create-html-pages @@ -11,62 +11,53 @@ create_html_pages () { -o "$CONTENT_PATH/index.html" "$CONTENT_PATH/index.md" case "$1" in - true) find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f -name \*.md) ;; - false) find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f -name \*.md -mtime -1) ;; + true) + find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \)) + rm -R "$PUBLICHTML_PATH/"* + rm -R "$TMP_PATH/" + ;; + false) + find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \) -mtime -1) + ;; esac # Then create others for markdown in $find_noindex_markdown; do - # Parent folder name without path - page_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 + # Get the value of the template config + templatename=$config_template - page_path="$year"/"$month"/"${outputname%.*}" + # page_path="$year"/"$month"/"${outputname%.*}" + # Get the relative path of the markdown file + page_path="$(realpath --relative-to=$CONTENT_PATH $markdown)" # Check if a section have a specific template or use the default template - if [[ " ${templates[*]} " == *" $page_section "* ]]; then - # Check if the date property value is not "null" - if [[ "$config_date" != "null" ]]; then - - pandoc -s "$markdown" \ - --template="$TPL_PANDOC_PATH/${page_section}.html" \ - --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \ - --variable=permalink:"$BASE_URL/$page_section/$page_path.html" \ - -o "$(dirname "$markdown")/$page_path.html" - else - pandoc -s "$markdown" \ - --template="$TPL_PANDOC_PATH/${page_section}.html" \ - -o "$(dirname "$markdown")/${outputname%.*}.html" - fi + 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 - if [[ "$config_date" != "null" ]]; then - 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_section/$page_path.html" \ - -o "$(dirname "$markdown")/$page_path.html" - else - pandoc -s "$markdown" \ - --template="$TPL_PANDOC_PATH/default.html" \ - -o "$(dirname "$markdown")/${outputname%.*}.html" - fi + 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%.*}" \ + -o "$(dirname "$markdown")/${outputname%.*}.html" fi - done + echo "$config_date|$config_datetime|$BASE_URL/${page_path%.*}.html|$config_title" + done > fakestache.tmp.db + + sort -nr fakestache.tmp.db > "$FAKESTACHE_PATH"/"$DB" + + rm fakestache.tmp.db + move_html_to_publichtml } diff --git a/functions/create-html-sections b/functions/create-html-sections @@ -14,9 +14,9 @@ create_html_sections () { fi # For each section page create a temporary "includes" folder - mkdir -p "$TMP_PATH/panstash/$(basename "$indexsubdir")" + mkdir -p "$TMP_PATH/$(basename "$indexsubdir")" - tmp_folder="$TMP_PATH/panstash/$(basename "$indexsubdir")" + tmp_folder="$TMP_PATH/$(basename "$indexsubdir")" # For all markdown files that are not "index.md" for markdown in $(find "$indexsubdir/" -type f \( -name "*.md" ! -name "index.md" \)); do @@ -37,13 +37,7 @@ 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 - - pandoc "$markdown" -s \ - --variable=url:"$BASE_URL/${url#*/}" \ - --template="$TPL_PANDOC_PATH/feed-entry.txt" \ - -t plain \ - -o "$tmp_folder/$markdown_date-${outputname%.*}".entry.xhtml + -o "$tmp_folder/$markdown_date-${outputname%.*}".inc.html done if test "$(ls -A "$tmp_folder/")"; then @@ -51,24 +45,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 - - # This is for the feed - pandoc -t html $(find "$tmp_folder/" -type f -name \*.entry.xhtml | sort -nr) \ - -o "$tmp_folder/tmp.feed.xhtml" \ - --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" - - # This is for the feed - pandoc -t html "$tmp_folder/tmp.feed.xhtml" -s \ - --template="$TPL_PANDOC_PATH/feed.txt" \ - -o "$PUBLICHTML/feed.$(basename "$indexsubdir").atom.xml" \ - --parse-raw + -o "$indexsubdir/index.html" fi done