hugosoucycc

[ARCHIVED] Another old source code of <hugo.soucy.cc>.
Log | Files | Refs | Submodules

commit 567df8cf8a09dd0ae7f72749d271e48628ee5e22
parent be5deeac38d728f6f9323de00b9c17c17569c271
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat, 18 Mar 2017 08:56:15 -0400

Fix archetypes in array problem

Diffstat:
Mfakestache | 141++++++++++++++++++++++++++++++++++++++++---------------------------------------
Afunctions/is-in-array | 7+++++++
2 files changed, 79 insertions(+), 69 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,79 +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 - # Use this instead : echo Hej på dig, du den dära | iconv -f utf-8 -t us-ascii//translit - # Source <http://stackoverflow.com/questions/1975057/bash-convert-non-ascii-characters-to-ascii> - - 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) - # 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 +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 and white spaces for the filename + archetype_title_nospecials=${archetype_title//[\'!,:;?]/} + archetype_filename=${archetype_title_nospecials// /-}.md + # Use this instead : echo Hej på dig, du den dära | iconv -f utf-8 -t us-ascii//translit + # Source <http://stackoverflow.com/questions/1975057/bash-convert-non-ascii-characters-to-ascii> + + 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. 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 +}