new commit

This commit is contained in:
2023-09-02 20:22:34 -05:00
parent a69b5d3904
commit d15176f5e6
7 changed files with 360 additions and 7 deletions

22
utils/config.sh Normal file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/bash
PROJ_DIR=~/Blog
BLOG_DIR=$PROJ_DIR/blog
UTILS=$PROJ_DIR/utils
LIBS=$UTILS/libs
function include () {
local LIB_NAME="${1:?"include : a lib name was not provided"}"
[[ ! "$LIB_NAME" == *.sh ]] && LIB_NAME="$LIB_NAME.sh"
local LIB_PATH=""
if [[ ! -f $LIBS/$LIB_NAME ]]; then
echo "include : $LIBS/$LIB_NAME does not exist."
exit 1
else
LIB_PATH=$LIBS/$LIB_NAME
fi
. $LIB_PATH
}

View File

@@ -1,15 +1,14 @@
#!/usr/bin/bash
function get_blog_pages () {
## The blog/project dir
local BLOG_DIR=~/Blog
## 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) )
if ls -1 $BLOG_DIR/*.wiki >/dev/null 2>&1; then
VAR=( $(ls -1 $BLOG_DIR/*.wiki | grep -v 'index.wiki' ) )
fi
}

View File

@@ -1,9 +1,9 @@
#!/usr/bin/bash
function generate_blog_post () {
include blog-page
## 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"}"
@@ -25,7 +25,7 @@ function generate_blog_post () {
---------------------------
`
TITLES=""
TITLES="[[index.wiki|Index]]"
for page in ${last_few_posts[@]}; do
read JUNK TITLE <<< "$( grep '%title' $page )"
TITLES="${TITLES} [[$page|$TITLE]]"
@@ -40,3 +40,28 @@ EOF
return 0
}
function generate_index () {
local -a blog_files
local OUTPUT=$BLOG_DIR/index.wiki
local TITLE DATE JUNK FILENAME
include blog-page
get_blog_pages blog_files
cat >$OUTPUT <<EOF
%title Blog Index
`
for file in ${blog_files[@]}; do
read JUNK TITLE <<< "$( grep '%title' $file )"
FILENAME="$(basename $file)"
DATE="$(grep -i 'date:' $file | grep -Eo '[0-9]{4}/[0-9]{2}/[0-9]{2}')"
echo "[[$FILENAME|$TITLE ($DATE)]]"
done
`
EOF
}

32
utils/main.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/bash
PROJ_DIR=~/Blog
CONFIG=$PROJ_DIR/utils/config.sh
## Loading in config
[[ -f $CONFIG ]] && . $CONFIG
include generate
usage () {
cat <<EOF
main.sh [ -n | --new ] "<title>" "<filename>"
EOF
}
while [[ $# -ne 0 ]]; do
case $1 in
-n | --new)
shift
: "
$1 = Title
$2 = Filename
"
TITLE="${1:?"main.sh : Title was not provided"}"
FILENAME="${2:?"main.sh : Filename was not provided"}"
generate_blog_post "$TITLE" "$FILENAME"
sync
generate_index
break
;;
esac
done