From 9063de30fedacb2a224012ff137d0166df7e38cd Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 6 Aug 2023 01:08:38 +0800 Subject: [PATCH] Add scripts to streamline posting --- _data/locales/en.yml | 93 -------------------------------------------- post.sh | 40 +++++++++++++++++++ push.sh | 25 ++++++++++++ 3 files changed, 65 insertions(+), 93 deletions(-) delete mode 100644 _data/locales/en.yml create mode 100755 post.sh create mode 100755 push.sh diff --git a/_data/locales/en.yml b/_data/locales/en.yml deleted file mode 100644 index 2454ca0..0000000 --- a/_data/locales/en.yml +++ /dev/null @@ -1,93 +0,0 @@ -# The layout text of site - -# ----- Commons label ----- - -layout: - post: Post - category: Category - tag: Tag - -# The tabs of sidebar -tabs: - # format: : - home: Home - categories: Categories - tags: Tags - archives: Archives - about: About - -# the text displayed in the search bar & search results -search: - hint: search - cancel: Cancel - no_results: Oops! No results found. - -panel: - lastmod: Recently Updated - trending_tags: Trending Tags - toc: Contents - -copyright: -# # Shown at the bottom of the post -# license: -# template: This post is licensed under :LICENSE_NAME by the author. -# name: CC BY 4.0 -# link: https://creativecommons.org/licenses/by/4.0/ - -# # Displayed in the footer -# brief: Some rights reserved. -# verbose: >- -# Except where otherwise noted, the blog posts on this site are licensed -# under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author. - -meta: Using the :PLATFORM theme :THEME. - -not_found: - statment: Sorry, we've misplaced that URL or it's pointing to something that doesn't exist. - -notification: - update_found: A new version of content is available. - update: Update - -# ----- Posts related labels ----- - -post: - written_by: By - posted: Posted - updated: Updated - words: words - pageview_measure: views - read_time: - unit: min - prompt: read - relate_posts: Further Reading - share: Share - button: - next: Newer - previous: Older - copy_code: - succeed: Copied! - share_link: - title: Copy link - succeed: Link copied successfully! - # pinned prompt of posts list on homepage - pin_prompt: Pinned - -# Date time format. -# See: , -df: - post: - strftime: "%b %e, %Y" - dayjs: "ll" - archives: - strftime: "%b" - dayjs: "MMM" - -# categories page -categories: - category_measure: - singular: category - plural: categories - post_measure: - singular: post - plural: posts diff --git a/post.sh b/post.sh new file mode 100755 index 0000000..c470878 --- /dev/null +++ b/post.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Function to sanitize the title +sanitize_title() { + title="$1" + sanitized_title=$(echo "$title" | tr -dc 'a-zA-Z0-9 ') + echo "$sanitized_title" | tr ' ' '-' +} + +# Function to generate the front matter with the current date +generate_front_matter() { + current_date=$(date +'%Y-%m-%d %H:%M:%S %z') + echo "---" + echo "title: $1" + echo "author: Peter Tanner" + echo "date: $current_date" + echo "categories: [Blogging] # Blogging | Electronics | Programming | Mechanical" + echo "tags: [getting started] # systems | embedded | rf | microwave | electronics | solidworks | automation" + echo "---" +} + +# Prompt the user for a title +read -e -p "Enter the title: " user_title + +# Sanitize the title +sanitized_title=$(sanitize_title "$user_title") + +# Generate the filename with the current date +current_date=$(date +'%Y-%m-%d') +filename="${current_date}-${sanitized_title}.md" +filepath="_posts/${filename}" + +# Check if the file already exists +if [ -e "$filepath" ]; then + echo "A file with the name '$filename' already exists in the '_posts' subdirectory." +else + # Create the new file and add the front matter + generate_front_matter "$user_title" > "$filepath" + echo "File '$filename' created successfully in the '_posts' subdirectory." +fi diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..ca148eb --- /dev/null +++ b/push.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +get_new_posts() { + git status --porcelain=v1 _posts | grep -E '^\?\?' | cut -d ' ' -f 2 | tr '\n' ' ' +} + +# Function to generate the commit message +generate_commit_message() { + printf "New posts: " + get_new_posts +} + +# Check if there are any new or modified files to commit +if [ -n "$(get_new_posts)" ]; then + # Add all new and modified files + echo "$(generate_commit_message)" + git add $(get_new_posts) + + # Commit the changes with the generated message + git commit -m "$(generate_commit_message)" + git push + echo "Changes committed successfully." +else + echo "No new or modified files to commit." +fi