Added a few things

This commit is contained in:
Tristan Ancelet 2023-08-31 23:40:43 -05:00
parent 8139180727
commit 2822ce369b
7 changed files with 70 additions and 13 deletions

View File

View File

View File

@ -1 +0,0 @@
#!/usr/bin/bash

View File

@ -1,3 +0,0 @@
#!/usr/bin/bash

Binary file not shown.

View File

@ -1,30 +1,49 @@
#!/usr/bin/bash #!/usr/bin/bash
function get_blog_pages () { function get_blog_pages () {
## The blog/project dir
local BLOG_DIR=~/Blog 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" local -n VAR="$VAR_NAME"
## Setting the list to the available blog files.
VAR=( $(ls $BLOG_DIR/blog/????-??-??.wiki) ) VAR=( $(ls $BLOG_DIR/blog/????-??-??.wiki) )
} }
function get_last_5_pages (){ function get_last_5_pages (){
## Index to use in the iterrations later
local INDEX
## Local variable to store pages (locally)
local -a pages 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 local PAGES
## Grabbing pages from above function
get_blog_pages pages get_blog_pages pages
## Getting page count
PAGES=${#pages[@]}; 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 if [[ $PAGES -lt 5 ]]; then
for (( i=$((PAGES-1)); i==0; i--)); do VAR=( ${pages[@]} )
echo ${i}
done
else 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 fi
} }
if [[ "$0" == *"blog-page.sh" ]]; then
get_last_5_pages
fi

42
utils/libs/generate.sh Normal file
View File

@ -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 <<EOF
%title $PAGE_TITLE
---------------------------
`
TITLES=""
for page in ${last_few_posts[@]}; do
read JUNK TITLE <<< "$( grep '%title' $page )"
TITLES="${TITLES} [[$page|$TITLE]]"
done
echo $TITLES
`
---------------------------
*Date:* `date +'%Y/%m/%d'`
*Author:* Tristan Ancelet
EOF
return 0
}