Compare commits
29 Commits
e69fad1184
...
catagories
Author | SHA1 | Date | |
---|---|---|---|
c7b708da77 | |||
59bd42f185 | |||
b267154316 | |||
adcda2f37d | |||
3ed298592f | |||
9009885f53 | |||
0acac4dc55 | |||
f07e6fae57 | |||
22326e7000 | |||
07a1cddc9f | |||
33edb5def8 | |||
722c02db7a | |||
cb7bc1d4c9 | |||
4a421ac4bd | |||
f388992436 | |||
108721eb0c | |||
e012077ecd | |||
b9b71f5f02 | |||
a507ef5e66 | |||
f46aacc5b7 | |||
546dc17057 | |||
778bf9410a | |||
5675c3b814 | |||
f59bef3428 | |||
2f51c2dd9d | |||
77c5187294 | |||
ab3dcd56c7 | |||
f9736ae49a | |||
f92e5e9f17 |
@@ -5,3 +5,5 @@ Hello all, this is a project I put togethor for my Capstone project (not the pro
|
||||
## Function
|
||||
The core of this project depends on you having VimWiki installed. The second depends on you having bash installed as a shell.
|
||||
|
||||
## What it does
|
||||
This simply automates the creation of new wiki posts and updating the index page.
|
||||
|
2
Site
2
Site
Submodule Site updated: 20beb7025c...d25ee5b17d
2
blog
2
blog
Submodule blog updated: 8623acba92...8f59dd1f7b
@@ -37,8 +37,8 @@ function get_last_5_pages (){
|
||||
VAR=( ${pages[@]} )
|
||||
else
|
||||
## Otherwise, itterate through the last 5 blog posts
|
||||
INDEX=-5
|
||||
while [[ $INDEX -ne 0 ]]; do
|
||||
INDEX=0
|
||||
while [[ $INDEX -ne 5 ]]; do
|
||||
VAR+=( "${pages[$INDEX]}" )
|
||||
## Increment the index so that we get closer and closer to end of the list
|
||||
((INDEX++))
|
||||
|
@@ -39,6 +39,7 @@ echo -e $TITLES
|
||||
`
|
||||
|
||||
*Date:* `date +'%Y/%m/%d'`
|
||||
|
||||
*Author:* Tristan Ancelet
|
||||
|
||||
= $PAGE_TITLE =
|
||||
|
85
utils/libs/get.sh
Normal file
85
utils/libs/get.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
function get_category_names () {
|
||||
local -n OUTPUT_CATEGORY_NAMES_VAR="${1:?"get_category_names : Output variable not provided"}"
|
||||
local CATEGORY_NAME
|
||||
|
||||
for category_path in $BLOG_DIR/posts/*; do
|
||||
CATEGORY_NAME="${category_path/*\//}"
|
||||
OUTPUT_CATEGORY_NAMES_VAR+=( "$CATEGORY_NAME" )
|
||||
done
|
||||
}
|
||||
|
||||
function get_category_paths () {
|
||||
local -a CATEGORY_PATHS=( $BLOG_DIR/posts/* ) CATEGORY_NAMES
|
||||
local -n OUTPUT_CATEGORY_VAR="${1:?"get_categories : No category variable provided"}"
|
||||
|
||||
for path in ${CATEGORY_PATHS[@]}; do
|
||||
OUTPUT_CATEGORY_VAR[${path/*\//}]=$path
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
function get_posts_in_category () {
|
||||
local -A CATEGORIES
|
||||
local CATEGORY_NAME="${1:?"get_posts_in_category : Category name not provided"}"
|
||||
local -n OUTPUT_POST_VAR="${2:?"get_posts_in_category : Output variable not provided"}"
|
||||
|
||||
get_category_paths CATEGORIES
|
||||
|
||||
if [[ "${!CATEGORIES[@]}" != *$CATEGORY_NAME* ]]; then
|
||||
echo "get_posts_in_category : There is no category by that name"
|
||||
exit
|
||||
fi
|
||||
|
||||
CATEGORY_PATH="${CATEGORIES[$CATEGORY_NAME]}"
|
||||
|
||||
for post in ${CATEGORY_PATH}/*.wiki; do
|
||||
FULLPATH=$post
|
||||
FILENAME="${post/*\/}"
|
||||
TIMESTAMP=`cut -d '-' -f 1 <<< "$FILENAME"`
|
||||
DATE=`date -d @$TIMESTAMP +"$DATE_FORMAT"`
|
||||
WIKI_PATH=/posts/$CATEGORY_NAME/$FILENAME
|
||||
POST_TITLE="`grep '%title' $FULLPATH | cut -d ' ' -f 2-` ($DATE)"
|
||||
DATA="$FULLPATH:$WIKI_PATH:$POST_TITLE"
|
||||
OUTPUT_POST_VAR+=( "$DATA" )
|
||||
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
function get_posts_by_category () {
|
||||
local -a CATEGORY_NAMES POSTS
|
||||
local -A POST_BY_CATEGORY
|
||||
local post_string
|
||||
|
||||
local -n OUTPUT_POST_ASSOCIATIVE_ARRAY="${1:?"get_posts_by_category : Output variable not provided"}"
|
||||
|
||||
get_category_names CATEGORY_NAMES
|
||||
|
||||
for name in ${CATEGORY_NAMES[@]}; do
|
||||
get_posts_in_category $name POSTS
|
||||
for i in ${!POSTS[@]}; do
|
||||
post="${POSTS[$i]}"
|
||||
if [[ "$post_string" ]]; then
|
||||
post_string+="${POST_DELIMITER}${post}"
|
||||
else
|
||||
post_string="$post"
|
||||
fi
|
||||
done
|
||||
|
||||
OUTPUT_POST_ASSOCIATIVE_ARRAY[$name]="$post_string"
|
||||
|
||||
post_string=""
|
||||
unset POSTS
|
||||
done
|
||||
}
|
||||
|
||||
function deserialize_posts () {
|
||||
local -n OUTPUT_POST_ARRAY="${1:?"deserialize_posts : Output variable not provided"}"
|
||||
local SERIALIZED_POSTS="${2:?"deserialize_posts : Serialized posts not provided"}"
|
||||
|
||||
OIFS=$IFS
|
||||
IFS="$POST_DELIMITER"
|
||||
read -a OUTPUT_POST_ARRAY <<< "$SERIALIZED_POSTS"
|
||||
}
|
@@ -30,7 +30,7 @@ while [[ $# -ne 0 ]]; do
|
||||
FILENAME="${2:?"main.sh : Filename was not provided"}"
|
||||
generate_blog_post "$TITLE" "$DATESTAMP-$FILENAME"
|
||||
sync
|
||||
generate_index
|
||||
generate_hook
|
||||
break
|
||||
;;
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
## If user is not running this in the root of the project dir
|
||||
if [[ ! -d utils ]]; then
|
||||
## Change directory to project dir
|
||||
cd `dirname $1`
|
||||
cd `dirname $0`
|
||||
cd ..
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user