fakestache (3703B)
1 #!/bin/bash 2 # 3 # FAKESTACHE SSG - Yep! An Other Static Website Generator! 4 # (Pandoc + Mustache + Bash) 5 # 6 7 # Dependencies : 8 # * Pandoc - Make sure it's installed on your machine : `$ pandoc -v`. 9 # * Mustache - Is already includes in pantash : `lib/mo/`. 10 11 # Include the main configuration files 12 . config/site.cfg 13 . config/app.cfg 14 15 # Include mustache for bash 16 . lib/mo/mo 17 18 # Include all the main functions 19 . functions/parse-yaml 20 . functions/is-in-array 21 . functions/get-archetypes 22 . functions/build-pandoc-templates 23 . functions/get-pandoc-templates 24 . functions/move-html-to-publichtml 25 . functions/create-html-pages 26 . functions/create-html-sections 27 . functions/create-feed 28 . functions/get-static-files 29 . functions/clean-content-folder 30 31 32 # Reset all variables that might be set 33 unset -v reset 34 reset=false 35 36 get_archetypes 37 38 if is_in_array "$1" "${archetypes[@]}" == 1; then 39 if [ -n "$2" ]; then 40 archetype_title="$2" 41 archetype_date=$NOW_DATE 42 archetype_datetime=$NOW_DATETIME 43 archetype_template="$1" 44 45 # Remove special chars, white spaces for the filename, replace 46 # uppcase by lower, and replace non-ascii 47 archetype_filename=${archetype_title//[[:space:]]/-}.md 48 archetype_filename=${archetype_filename//[^[:alnum:]-.]/} 49 archetype_filename=$(echo ${archetype_filename,,} | iconv -f utf-8 -t us-ascii//translit) 50 51 mkdir -p "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/" 52 53 mo $ARCHETYPES_PATH/$1.md > "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/$archetype_filename" 54 55 echo "- The file '$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/$archetype_filename' hab been created." 56 57 exit 0 58 else 59 echo "- ERROR: Requires a second argument! You need a title to create a $1." 60 exit 1 61 fi 62 else 63 case $1 in 64 -d|--dev) 65 # In dev mode the URL is localhost 66 BASE_URL=$SITE_URL_DEV 67 68 # In dev mode the site is build in `/tmp` 69 PUBLICHTML_PATH=$TMP_PATH/$PUBLICHTML 70 71 # Create `/tmp/fakestache` directory if it is not there 72 [ ! -d "$PUBLICHTML_PATH/" ] && mkdir -p "$PUBLICHTML_PATH/" 73 74 case $2 in 75 -r|--reset) 76 reset=true 77 ;; 78 esac 79 80 # Open the dev mode site in the default browser 81 # @todo But the server comment missing 82 #$BROWSER $BASE_URL 83 ;; 84 -r|--reset) 85 reset=true 86 87 case $2 in 88 -d|--dev) 89 # In dev mode the URL is localhost 90 BASE_URL=$SITE_URL_DEV 91 92 # In dev mode the site is build in `/tmp` 93 PUBLICHTML_PATH=$TMP_PATH/$PUBLICHTML 94 95 # Create `/tmp/fakestache` directory if it is not there 96 [ ! -d "$PUBLICHTML_PATH/" ] && mkdir -p "$PUBLICHTML_PATH/" 97 98 # Open the dev mode site in the default browser 99 # @todo But the server comment missing 100 #$BROWSER $BASE_URL 101 ;; 102 esac 103 ;; 104 esac 105 fi 106 107 if hash pandoc 2>/dev/null && (( ${BASH_VERSION%%.*} >= 4 )); then 108 # Ok Pandoc is here. 109 # Then execute main functions 110 build_pandoc_templates 111 create_html_pages "$reset" 112 create_html_sections 113 create_feed 114 get_static_files 115 clean_content_folder 116 117 echo "- Your New Website Is Ready Here : $PUBLICHTML_PATH/ . Thanks Pandoc!!" 118 119 exit 0 120 else 121 echo "- Sorry But You must Install *Pandoc* and/or have Bash >= 4 To Using *FakeStache SSG*." 122 echo "- Please Visit <http://pandoc.org/installing.html>." 123 124 exit 1 125 fi