From 2822ce369b50a0d6a839e05ed88a03c1bcda4b02 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Thu, 31 Aug 2023 23:40:43 -0500 Subject: [PATCH] Added a few things --- blog/2023-08-31.wiki | 0 blog/2023-08-32.wiki | 0 utils/generate-new-blog-page.sh | 1 - utils/generate-new.sh | 3 --- utils/libs/.blog-page.sh.swp | Bin 12288 -> 0 bytes utils/libs/blog-page.sh | 37 +++++++++++++++++++++------- utils/libs/generate.sh | 42 ++++++++++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 13 deletions(-) delete mode 100644 blog/2023-08-31.wiki delete mode 100644 blog/2023-08-32.wiki delete mode 100644 utils/generate-new-blog-page.sh delete mode 100644 utils/generate-new.sh delete mode 100644 utils/libs/.blog-page.sh.swp create mode 100644 utils/libs/generate.sh 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 58ae971778d89763dbc5e7f7ab623fb18ce7900a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2!EVz)5Qev$@S&l=9j1;2b|u#ds0WBlNku7zHlP9pDJqd2JI$(=H?o};DQYT+ME#g=6(m) z8}CK`M@3|bOfxUeXHIP|%60a`Fi?s2N+o*;%cMFPIi76jtVC+p8D=s{ok;qr<6~?O zyxnjy?VoxQPqG0vaCQT;;`Xh2@l~(t^K|vf%d>CAk!*ksumLu}2G{@_U;}J`4V*gz z*MOfB*lwB*ahf1$+bvcnubS1#W^H;3D{g*ze#Q_zFIQPv8T13-&+&-heI80vq57 zcnqrGGRSk71>D#G8(;%$fDNz#Hoykh02^QfY~X(z=t-gNhFK@_(yX)8$**LmLiVWL zCf%s%E%Yk1mrJ_wZ1%Hxe<3E5FbOUKUCir20&susDn@9!KoL|H?g zW?2E1b!d_5dJz>7VluG3$z*RBck?Ujbh3Ohtx;Z@(6*afu1SU&rDUvZJYDNNSl=qH zt~<+UcJWy}kbBZ1>uCR&@-W@Nv(svBuEI%~#`Fc|M)kYPdP~v1mq^c#LOSqL8YF68 z24O&%qDZ0Zhh?fH<4oy?M;lF3amU5Idht&s$0V2*p^)mlGfWf5m$Bn}xNZLzqm;)5 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 <