Add scripts to streamline posting

This commit is contained in:
Peter 2023-08-06 01:08:38 +08:00
parent a28151beba
commit 9063de30fe
3 changed files with 65 additions and 93 deletions

View File

@ -1,93 +0,0 @@
# The layout text of site
# ----- Commons label -----
layout:
post: Post
category: Category
tag: Tag
# The tabs of sidebar
tabs:
# format: <filename_without_extension>: <value>
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: <http://strftime.net/>, <https://day.js.org/docs/en/display/format>
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

40
post.sh Executable file
View File

@ -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

25
push.sh Executable file
View File

@ -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