create-html-pages (2787B)
1 #!/usr/bin/env bash 2 3 # Create all the HTML pages with pandoc 4 create_html_pages () { 5 echo "- Create all the HTML pages" 6 7 # Create the homepage 8 create_homepage () { 9 # Load the meta file of the homepage 10 . "$CONTENT_PATH/index.meta" 11 12 local page_title=$title 13 local description_loc="$SITE_DESCRIPTION" 14 local keywords_loc="$SITE_KEYWORDS" 15 16 # Convert markdown to html 17 local main_content=$(make_html_from_md "$CONTENT_PATH/index.md") 18 19 mo "$TPL_MUSTACHE_PATH/index.mustache" > "$CONTENT_PATH/index.html" 20 } 21 22 # Then create others 23 create_allpages () { 24 rm -R "$PUBLICHTML_PATH/"* 25 [ -d "$TMP_PATH/" ] && rm -R "$TMP_PATH/"* 26 27 get_templates 28 29 for markdown in $(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \)); do 30 # Markdown files names without path 31 local outputname=$(basename "$markdown") 32 33 # Get the relative path of the markdown file 34 local page_path="${markdown#$CONTENT_PATH}" 35 36 unset -v description_loc 37 unset -v keywords_loc 38 unset -v cite 39 unset -v citeurl 40 unset -v replyto 41 unset -v repostof 42 43 # Load the meta file of the markdown 44 . "${markdown%.*}.meta" 45 46 local page_title="$title" 47 local date="$date" 48 local datetime="$datetime" 49 # Using Perl because `stat` and `date` are not the same in OpenBSD and GNU/Linux 50 local modified="$(perl -MPOSIX -e 'print POSIX::strftime "%Y-%m-%dT%H:%M:%S", localtime((stat $ARGV[0])[9])' $markdown)" 51 local templatename="$template" 52 local permalink="$BASE_URL${page_path%.*}.html" 53 local description_loc="$description" 54 local keywords_loc="$keywords" 55 local cite_tpl="$cite" 56 local citeurl_tpl="$citeurl" 57 58 # Convert markdown to html 59 local main_content="$(make_html_from_md "$markdown")" 60 61 # Create an unique ID for each content 62 local page_id="tag:$SITE_DOMAINNAME,${date}:${date:0:4}/${date:5:2}/${outputname%.*}" 63 64 # Check if the specified template exist 65 if is_in_array "$templatename" "${templates[@]}"; then 66 mo "$TPL_MUSTACHE_PATH/${templatename}.mustache" > "$(dirname "$markdown")/${outputname%.*}.html" 67 else 68 mo "$TPL_MUSTACHE_PATH/default.mustache" > "$(dirname "$markdown")/${outputname%.*}.html" 69 fi 70 71 echo "$date|$datetime|$SITE_URL${page_path%.*}.html|$page_title|$page_id" 72 done | sort -nr -o "$FAKESTACHE_PATH"/"$DB" 73 } 74 75 create_homepage 76 create_allpages 77 78 move_html_to_publichtml 79 }