fakestache-ssg

[ARCHIVED] A static site generator in Bash 4.
Log | Files | Refs | Submodules | README

create-html-sections (2600B)


      1 #!/bin/bash
      2 
      3 # Create section page list
      4 create_html_sections () {
      5     echo "- Create section page list"
      6 
      7     get_pandoc_templates
      8 
      9     for indexsubdir in $(find "$CONTENT_PATH/" -mindepth 2 -name index.md -exec dirname {} \;); do
     10         if [[ " ${templates[*]} " == *" $(basename "$indexsubdir") "* ]]; then
     11             tplname="$(basename "$indexsubdir")"
     12         else
     13             tplname=default
     14         fi
     15 
     16         # For each section page create a temporary "includes" folder
     17         mkdir -p "$TMP_PATH/$(basename "$indexsubdir")"
     18 
     19         tmp_folder="$TMP_PATH/$(basename "$indexsubdir")"
     20 
     21         # For all markdown files that are not "index.md"
     22         for markdown in $(find "$indexsubdir/" -type f \( -name "*.md" ! -name "index.md" \)); do
     23             # Markdown files names without path
     24             outputname="$(basename "$markdown")"
     25 
     26             # Parse the YAML block of the markdown
     27             eval "$(parse_yaml "$markdown" "config_")"
     28 
     29             # Set the variable for the date
     30             markdown_date="$config_date$config_datetime"
     31 
     32             # Set the variable for the URL
     33             url=$(find "$PUBLICHTML/" -type f -name "${outputname%.*}".html;)
     34 
     35             # Create all the includes files that make up  section page and put them into the "includes" folder
     36             pandoc "$markdown" -s \
     37                    --variable=url:"$BASE_URL/${url#*/}" \
     38                    --template="$TPL_PANDOC_PATH/${tplname}-index.inc.html" \
     39                    -t html5 \
     40                    -o "$tmp_folder/$markdown_date-${outputname%.*}".inc.html
     41         done
     42 
     43         # Create symlinks for images in section's landing page
     44         for img in $(find "$indexsubdir/" -type f \( -name "*.jpg" -or -name "*.png" \)); do
     45             rel_img_path=$(realpath --relative-to=$indexsubdir $img)            
     46 
     47             $(ln -s -f "$rel_img_path" "$indexsubdir")            
     48         done
     49 
     50         if test "$(ls -A "$tmp_folder/")"; then
     51             # Sort all the includes files
     52             # Create an HTML file with all the includes in descending order
     53             pandoc -t html5 $(find "$tmp_folder/" -type f -name \*.inc.html | sort -nr) \
     54                    -o "$tmp_folder/tmp.html" \
     55                    --parse-raw
     56 
     57             # Merge the "includes.html" and "index.md" to create the section page list
     58             pandoc -t html5 "$indexsubdir/index.md" -s \
     59                    --template="$TPL_PANDOC_PATH/${tplname}-index.html" \
     60                    -A "$tmp_folder/tmp.html" \
     61                    -o "$indexsubdir/index.html"
     62         fi
     63     done
     64 
     65     move_html_to_publichtml
     66 }