blog/utils/libs/generate.sh

86 lines
1.6 KiB
Bash
Raw Normal View History

2023-09-01 04:40:43 +00:00
#!/usr/bin/bash
function generate_blog_post () {
2023-09-03 01:22:34 +00:00
include blog-page
2023-09-01 04:40:43 +00:00
## Loading in required functions
[[ -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
---------------------------
[[index.wiki|Index]]
---------------------------
last 5 posts
2023-09-01 04:40:43 +00:00
---------------------------
`
TITLES=""
2023-09-01 04:40:43 +00:00
for page in ${last_few_posts[@]}; do
read JUNK TITLE <<< "$( grep '%title' $page )"
TITLES="${TITLES}\n - [[$(basename $page)|$TITLE]]"
2023-09-01 04:40:43 +00:00
done
2023-10-31 03:37:18 +00:00
echo -e $TITLES
2023-09-01 04:40:43 +00:00
`
*Date:* `date +'%Y/%m/%d'`
2023-09-01 04:40:43 +00:00
*Author:* Tristan Ancelet
2023-09-06 02:39:53 +00:00
= $PAGE_TITLE =
2023-09-01 04:40:43 +00:00
EOF
return 0
}
2023-09-03 01:22:34 +00:00
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
--------
[[about-me.wiki|About Me]]
--------
## Blog Posts
-------------
2023-09-03 01:22:34 +00:00
`
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}')"
2023-10-31 03:37:18 +00:00
echo -e "- [[$FILENAME|$DATE - $TITLE ]] \n"
2023-09-03 01:22:34 +00:00
done
`
EOF
}
function generate_hook() {
generate_index
}