commit 69ed56682e5467ec40c2635c0bd2abf6d31a2e06
parent 2ab7b34e50ee2d0d34fef0d51c41b3c6623f1087
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date: Mon, 27 Mar 2017 08:16:00 -0400
Merge branch 'master' of github.com:hs0ucy/fakestache-ssg
Diffstat:
7 files changed, 116 insertions(+), 54 deletions(-)
diff --git a/fakestache b/fakestache
@@ -16,7 +16,8 @@
. lib/mo/mo
# Include all the main functions
-. functions/parse_yaml
+. functions/parse-yaml
+. functions/is-in-array
. functions/get-archetypes
. functions/build-pandoc-templates
. functions/get-pandoc-templates
@@ -27,54 +28,81 @@
. functions/get-static-files
. functions/clean-content-folder
-get_archetypes
# Reset all variables that might be set
+unset -v reset
reset=false
-case $1 in
- "${archetypes[*]}")
- if [ -n "$2" ]; then
- archetype_title="$2"
- archetype_date=$NOW_DATE
- archetype_datetime=$NOW_DATETIME
- archetype_template="$1"
-
- # Remove special chars and white spaces for the filename
- archetype_title_nospecials=${archetype_title//[\'!,:;?]/}
- archetype_filename=${archetype_title_nospecials// /-}.md
-
- mkdir -p "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/"
-
- mo $ARCHETYPES_PATH/$1.md > "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/${archetype_filename,,}"
-
- echo "- The file '$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/${archetype_filename,,}' hab been created."
-
- exit 0
- else
- echo "- ERROR: Requires a second argument! You need a title to create a $1." >&2
- exit 1
- fi
- ;;
- -d|--dev)
- BASE_URL=$SITE_URL_DEV
-
- case $2 in
- -r|--reset)
- reset=true
- ;;
- esac
- ;;
- -r|--reset)
- reset=true
-
- case $2 in
- -d|--dev)
- BASE_URL=$SITE_URL_DEV
- ;;
- esac
- ;;
-esac
+get_archetypes
+
+if is_in_array "$1" "${archetypes[@]}" == 1; then
+ if [ -n "$2" ]; then
+ archetype_title="$2"
+ archetype_date=$NOW_DATE
+ archetype_datetime=$NOW_DATETIME
+ archetype_template="$1"
+
+ # Remove special chars, white spaces for the filename, replace
+ # uppcase by lower, and replace non-ascii
+ archetype_filename=${archetype_title//[[:space:]]/-}.md
+ archetype_filename=${archetype_filename//[^[:alnum:]-.]/}
+ archetype_filename=$(echo ${archetype_filename,,} | iconv -f utf-8 -t us-ascii//translit)
+
+ mkdir -p "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/"
+
+ mo $ARCHETYPES_PATH/$1.md > "$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/$archetype_filename"
+
+ echo "- The file '$CONTENT_PATH/$1/${NOW_DATE:0:4}/${NOW_DATE:5:2}/$archetype_filename' hab been created."
+
+ exit 0
+ else
+ echo "- ERROR: Requires a second argument! You need a title to create a $1."
+ exit 1
+ fi
+else
+ case $1 in
+ -d|--dev)
+ # In dev mode the URL is localhost
+ BASE_URL=$SITE_URL_DEV
+
+ # In dev mode the site is build in `/tmp`
+ PUBLICHTML_PATH=$TMP_PATH/$PUBLICHTML
+
+ # Create `/tmp/fakestache` directory if it is not there
+ [ ! -d "$PUBLICHTML_PATH/" ] && mkdir -p "$PUBLICHTML_PATH/"
+
+ case $2 in
+ -r|--reset)
+ reset=true
+ ;;
+ esac
+
+ # Open the dev mode site in the default browser
+ # @todo But the server comment missing
+ #$BROWSER $BASE_URL
+ ;;
+ -r|--reset)
+ reset=true
+
+ case $2 in
+ -d|--dev)
+ # In dev mode the URL is localhost
+ BASE_URL=$SITE_URL_DEV
+
+ # In dev mode the site is build in `/tmp`
+ PUBLICHTML_PATH=$TMP_PATH/$PUBLICHTML
+
+ # Create `/tmp/fakestache` directory if it is not there
+ [ ! -d "$PUBLICHTML_PATH/" ] && mkdir -p "$PUBLICHTML_PATH/"
+
+ # Open the dev mode site in the default browser
+ # @todo But the server comment missing
+ #$BROWSER $BASE_URL
+ ;;
+ esac
+ ;;
+ esac
+fi
if hash pandoc 2>/dev/null && (( ${BASH_VERSION%%.*} >= 4 )); then
# Ok Pandoc is here.
@@ -87,6 +115,7 @@ if hash pandoc 2>/dev/null && (( ${BASH_VERSION%%.*} >= 4 )); then
clean_content_folder
echo "- Your New Website Is Ready Here : $PUBLICHTML_PATH/ . Thanks Pandoc!!"
+
exit 0
else
echo "- Sorry But You must Install *Pandoc* and/or have Bash >= 4 To Using *FakeStache SSG*."
diff --git a/functions/create-feed b/functions/create-feed
@@ -7,6 +7,7 @@ create_feed () {
field_datetime=$(echo $feed_entry | cut -d "|" -f 2)
field_permalink=$(echo $feed_entry | cut -d "|" -f 3)
field_title=$(echo $feed_entry | cut -d "|" -f 4)
+ field_id=$(echo $feed_entry | cut -d "|" -f 5)
mo "$TPL_MUSTACHE_PATH/feed/feed-entry.mustache"
diff --git a/functions/create-html-pages b/functions/create-html-pages
@@ -13,12 +13,12 @@ create_html_pages () {
# Then create others
case "$1" in
true)
- find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \))
- rm -R "$PUBLICHTML_PATH/"*
+ find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \))
+ rm -R "$PUBLICHTML_PATH/"*
[ -d "$TMP_PATH/" ] && rm -R "$TMP_PATH/"*
;;
false)
- find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 2 -type f \( -name "*.md" ! -name "index.md" \) -mtime -100)
+ find_noindex_markdown=$(find "$CONTENT_PATH/" -mindepth 1 -type f \( -name "*.md" ! -name "index.md" \) -mtime -100)
;;
esac
@@ -35,6 +35,9 @@ create_html_pages () {
# Get the relative path of the markdown file
page_path="$(realpath --relative-to=$CONTENT_PATH $markdown)"
+ # Create an unique ID for each content
+ page_id="tag:$SITE_DOMAINNAME,${config_date}:${config_date:0:4}/${config_date:5:2}/${outputname%.*}"
+
# Check if a section have a specific template or use the default template
if [[ " ${templates[*]} " == *" $templatename "* ]]; then
pandoc -s "$markdown" \
@@ -52,7 +55,7 @@ create_html_pages () {
-o "$(dirname "$markdown")/${outputname%.*}.html"
fi
- echo "$config_date|$config_datetime|$BASE_URL/${page_path%.*}.html|$config_title"
+ echo "$config_date|$config_datetime|$BASE_URL/${page_path%.*}.html|$config_title|$page_id"
done | sort -nr -o "$FAKESTACHE_PATH"/"$DB"
move_html_to_publichtml
diff --git a/functions/create-html-sections b/functions/create-html-sections
@@ -42,9 +42,9 @@ create_html_sections () {
# Create symlinks for images in section's landing page
for img in $(find "$indexsubdir/" -type f \( -name "*.jpg" -or -name "*.png" \)); do
- rel_img_path=$(realpath --relative-to=$indexsubdir $img)
+ rel_img_path=$(realpath --relative-to=$indexsubdir $img)
- $(ln -s -f "$rel_img_path" "$indexsubdir")
+ $(ln -s -f "$rel_img_path" "$indexsubdir")
done
if test "$(ls -A "$tmp_folder/")"; then
diff --git a/functions/get-pandoc-templates b/functions/get-pandoc-templates
@@ -9,7 +9,5 @@ get_pandoc_templates () {
templatename=$(basename "$template")
# Push templates names in the array
templates+=(${templatename%.*})
- done
- # End
+ done
}
-
diff --git a/functions/is-in-array b/functions/is-in-array
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+function is_in_array () {
+ local e
+ for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
+ return 1
+}
diff --git a/functions/parse-yaml b/functions/parse-yaml
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Source: https://gist.github.com/pkuczynski/8665367#file-parse_yaml-sh
+
+parse_yaml() {
+ local prefix=$2
+ local s
+ local w
+ local fs
+ s='[[:space:]]*'
+ w='[a-zA-Z0-9_]*'
+ fs="$(echo @|tr @ '\034')"
+ sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
+ -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
+ awk -F"$fs" '{
+ indent = length($1)/2;
+ vname[indent] = $2;
+ for (i in vname) {if (i > indent) {delete vname[i]}}
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+ printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
+ }
+ }' | sed 's/_=/+=/g'
+}