diff --git a/blog/2023-08-31.wiki b/blog/2023-08-31.wiki deleted file mode 100644 index e69de29..0000000 diff --git a/blog/2023-08-32.wiki b/blog/2023-08-32.wiki deleted file mode 100644 index e69de29..0000000 diff --git a/utils/generate-new-blog-page.sh b/utils/generate-new-blog-page.sh deleted file mode 100644 index 7f3915b..0000000 --- a/utils/generate-new-blog-page.sh +++ /dev/null @@ -1 +0,0 @@ -#!/usr/bin/bash diff --git a/utils/generate-new.sh b/utils/generate-new.sh deleted file mode 100644 index aa95744..0000000 --- a/utils/generate-new.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - - diff --git a/utils/libs/.blog-page.sh.swp b/utils/libs/.blog-page.sh.swp deleted file mode 100644 index 58ae971..0000000 Binary files a/utils/libs/.blog-page.sh.swp and /dev/null differ diff --git a/utils/libs/blog-page.sh b/utils/libs/blog-page.sh index 6e8b177..3b64ec6 100755 --- a/utils/libs/blog-page.sh +++ b/utils/libs/blog-page.sh @@ -1,30 +1,49 @@ #!/usr/bin/bash function get_blog_pages () { + ## The blog/project dir local BLOG_DIR=~/Blog - local VAR_NAME="${1:?"No variable was provided to lod the pages into"}" + + ## Getting the variable to set the list to externally + local VAR_NAME="${1:?"get_blog_pages : No variable was provided to lod the pages into"}" local -n VAR="$VAR_NAME" + + ## Setting the list to the available blog files. VAR=( $(ls $BLOG_DIR/blog/????-??-??.wiki) ) } function get_last_5_pages (){ + ## Index to use in the iterrations later + local INDEX + + ## Local variable to store pages (locally) local -a pages + + ## Variable name to dump list items into + local VAR_NAME="${1:?"get_last_5_pages : A variable name was not passed into the function"}" + ## Reference variable to handle setting value of external variable + local -n VAR="$VAR_NAME" + + ## Page Count Variable local PAGES + ## Grabbing pages from above function get_blog_pages pages + ## Getting page count PAGES=${#pages[@]}; + # if the count is less than the minimum, then just set the list as the one grabbed above if [[ $PAGES -lt 5 ]]; then - for (( i=$((PAGES-1)); i==0; i--)); do - echo ${i} - done + VAR=( ${pages[@]} ) else - echo "Hi" + ## Otherwise, itterate through the last 5 blog posts + INDEX=-5 + while [[ $INDEX -ne 0 ]]; do + VAR+=( "${pages[$INDEX]}" ) + ## Increment the index so that we get closer and closer to end of the list + ((INDEX++)) + done fi } - -if [[ "$0" == *"blog-page.sh" ]]; then - get_last_5_pages -fi diff --git a/utils/libs/generate.sh b/utils/libs/generate.sh new file mode 100644 index 0000000..e41aa0d --- /dev/null +++ b/utils/libs/generate.sh @@ -0,0 +1,42 @@ +#!/usr/bin/bash + +function generate_blog_post () { + ## Loading in required functions + local BLOG_PAGE=~/Blog/utils/libs/blog-page.sh + local BLOG_DIR=~/Blog/blog + [[ -f $BLOG_PAGE ]] && . $BLOG_PAGE + + local PAGE_TITLE="${1:?"generate_blog_post : Page Title was not provided"}" + local POST_FILENAME="${2:?"generate_blog_post : Filename not provided"}" + local POST_FILE=$BLOG_DIR/$POST_FILENAME + + if [[ -f $POST_FILE ]]; then + echo "This file ($POST_FILE) already exists. Faling program" + return 1 + fi + + local -a last_few_posts + get_last_5_pages last_few_posts + + + cat > $POST_FILE <