diff --git a/insert-posts.sh b/insert-posts.sh index 2116344..f090f08 100755 --- a/insert-posts.sh +++ b/insert-posts.sh @@ -8,7 +8,10 @@ function usage() { } [ ! -x "$(command -v sqlite3)" ] && echo "You need SQLite3 to run this" && exit 1 -[ -z "$BLOG_DIR" ] && echo '$BLOG_DIR is not set! Defaulting to .' && BLOG_DIR="." +if [ -z "$BLOG_DIR" ]; then + echo "Looking for posts in ./posts because BLOG_DIR is not set." + BLOG_DIR="." +fi # params -> slug, title, content, date function update_post() { @@ -17,33 +20,33 @@ function update_post() { local title=${3:?Title is required} local content=${4:?Content is required} - echo "$date" "$slug" "$title" "$content" + echo "Trying to update $slug" sqlite3 \ "$BLOG_DIR/database.db" \ - "UPDATE blog_post SET title = '$title', content = '$content' WHERE slug = '$slug'" 2&> /dev/null + "UPDATE blog_post SET title = '$title', content = '$content' WHERE slug = '$slug'" 2> /dev/null - local status=$? + local status="$?" - [ $status -eq 0 ] && echo "Updated already post: $slug." && return + [[ "$status" = "0" ]] && echo "Successfully updated already existing post: $slug" && return echo "Failed to update, or insert post: $slug." } # params -> slug, title, content, date function insert_post() { - [ $# -eq 0 ] && exit 1; + [ ! $# -eq 4 ] && exit 1; local date=${1:?Date is required} local slug=${2:?Slug is required} local title=${3:?Title is required} local content=${4:?Content is required} - sqlite3 "$BLOG_DIR/database.db" "INSERT INTO blog_post (slug, title, content, date) VALUES ('$slug', '$title', '$content', '$date');" 2&> /dev/null + sqlite3 "$BLOG_DIR/database.db" "INSERT INTO blog_post (slug, title, content, date) VALUES ('$slug', '$title', '$content', '$date');" 2> /dev/null - local status=$? + local status="$?" - [ $status -eq 0 ] && echo "Inserted $slug successfully." && return - update_post "$date" "$slug" "$title" "$content" + [ "$status" = "0" ] && echo "Inserted $slug successfully." && return + [ "$status" = "19" ] && echo "Post $slug already exists." && update_post "$date" "$slug" "$title" "$content" } # # # # # # # # # # # # # # # # # # # # # # # # diff --git a/post2.post b/post2.post new file mode 100644 index 0000000..63a0162 --- /dev/null +++ b/post2.post @@ -0,0 +1,4 @@ +aug 23 2021 +test-post +test post +abcdefg test post \ No newline at end of file diff --git a/posts/books-of-2022.blog b/posts/books-of-2022.blog deleted file mode 100644 index 6cf4c87..0000000 --- a/posts/books-of-2022.blog +++ /dev/null @@ -1,62 +0,0 @@ -Sep 6, 2022 -my-books-for-2022-and-going-into-2023 -My books for 2022, and going into 2023 -

- Here is a compiled list of books that I read in 2022. - (In no particular order) -

- -

- The following books are books that I have started but not finished. - I plan to finish these books in 2023. -

- -

- The following are books I have acquired, and plan to read in 2023. -

- -

- My goal for 2022 was to get better at absorbing useful information from - technical books. I think I met that goal to a good extent, as I was able - to improve my software skills by a good margin this year through the - help of technical literature. -

\ No newline at end of file diff --git a/posts/test-post-two.post b/posts/test-post-two.post deleted file mode 100644 index be5aed6..0000000 --- a/posts/test-post-two.post +++ /dev/null @@ -1,4 +0,0 @@ -Aug 30 2022 -blog-testing -Blog Testing -

BASH SCRIPTS adasdFTW

\ No newline at end of file diff --git a/posts/test-post.post b/posts/test-post.post deleted file mode 100644 index 4b21a23..0000000 --- a/posts/test-post.post +++ /dev/null @@ -1,6 +0,0 @@ -Aug 29, 2022 -test-post -Test Post -

- Some SUPER COOL content. -

\ No newline at end of file