-
Notifications
You must be signed in to change notification settings - Fork 1
/
Post
executable file
·48 lines (39 loc) · 1.33 KB
/
Post
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Finding global
blog_loc='/home/vietthan/Documents/OdinProjects/vietthan.github.io/_posts/'
now=$(date)
# Just some more fun with dates
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
hour=$(date +%H)
min=$(date +%M)
sec=$(date +%S)
# format dates
format_date=$(date +"%Y-%m-%d %H:%M:%S %z")
printf "\t%s\n" "$format_date"
# verification, but also for fun
printf "\tOn the %s day of the %s month of the %s year based on most people's calendar.\n" "$day" "$month" "$year"
printf "\tViet's log will record another chapter at the %s hour, %s minute, and %s second\n\n" "$hour" "$min" "$day"
# format title
title=$1
lower_title=$(echo $title | awk '{print tolower($0)}')
formatted_title="${lower_title// /-}"
filename="${year}-${month}-${day}-${formatted_title}.md"
fullname="${blog_loc}${filename}"
# Create the post
printf "\tCreating post: %s\n" "$filename"
# Populate the post
if [ -f $fullname ]; then
printf "\tFile %s at blogging path exists. Will clear file content\n" "$filename"
> $fullname
else
printf "\tFile %s does not exist. Will be created.\n" "$filename"
touch "${fullname}"
fi
printf "%s\n" "---" >> $fullname
printf "layout: post\n" >> $fullname
printf "title: \"%s\"\n" "$title" >> $fullname
printf "date: %s\n" "$format_date" >> $fullname
printf "categories: \n" >> $fullname
printf "%s\n" "---">> $fullname