create-html-pages (2441B)
1 #!/bin/bash 2 3 # Create all the HTML pages with pandoc 4 create_html_pages () { 5 echo "- Create all the HTML pages with pandoc" 6 7 get_pandoc_templates 8 9 # Create the homepage 10 pandoc --template="$TPL_PANDOC_PATH/index.html" \ 11 -o "$CONTENT_PATH/index.html" "$CONTENT_PATH/index.md" 12 13 # Then create others 14 case "$1" in 15 true) 16 find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \)) 17 rm -R "$PUBLICHTML_PATH/"* 18 [ -d "$TMP_PATH/" ] && rm -R "$TMP_PATH/"* 19 ;; 20 false) 21 find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \) -mtime -100) 22 ;; 23 esac 24 25 for markdown in $find_noindex_markdown; do 26 # Markdown files names without path 27 outputname=$(basename "$markdown") 28 29 # Parse the YAML block of the markdown 30 eval "$(parse_yaml "$markdown" "config_")" 31 32 # Get the value of the template config 33 templatename=$config_template 34 35 # Get the relative path of the markdown file 36 page_path="$(realpath --relative-to=$CONTENT_PATH $markdown)" 37 38 # Create an unique ID for each content 39 page_id="tag:$SITE_DOMAINNAME,${config_date}:${config_date:0:4}/${config_date:5:2}/${outputname%.*}" 40 41 # Check if a section have a specific template or use the default template 42 if [[ " ${templates[*]} " == *" $templatename "* ]]; then 43 pandoc -s "$markdown" \ 44 --template="$TPL_PANDOC_PATH/${templatename}.html" \ 45 --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \ 46 --variable=permalink:"$BASE_URL/${page_path%.*}.html" \ 47 -o "$(dirname "$markdown")/${outputname%.*}.html" 48 49 else 50 pandoc -s "$markdown" \ 51 --template="$TPL_PANDOC_PATH/default.html" \ 52 --variable=template:"default" \ 53 --variable=modified:"$(date -r "$markdown" +%Y-%m-%dT%H:%M:%S)" \ 54 --variable=permalink:"$BASE_URL/${page_path%.*}.html" \ 55 -o "$(dirname "$markdown")/${outputname%.*}.html" 56 fi 57 58 echo "$config_date|$config_datetime|$BASE_URL/${page_path%.*}.html|$config_title|$page_id" 59 done | sort -nr -o "$FAKESTACHE_PATH"/"$DB" 60 61 move_html_to_publichtml 62 }