-
Notifications
You must be signed in to change notification settings - Fork 1
/
blog_post_generator.sh
executable file
·185 lines (163 loc) · 7.15 KB
/
blog_post_generator.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# Banner
echo "
███████╗██╗ ██╗████████╗██╗ ██╗██████╗ ███████╗ ██╗███╗ ██╗███████╗██╗ ██████╗ ██╗ ██╗████████╗
██╔════╝██║ ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝ ██║████╗ ██║██╔════╝██║██╔════╝ ██║ ██║╚══██╔══╝
█████╗ ██║ ██║ ██║ ██║ ██║██████╔╝█████╗ ██║██╔██╗ ██║███████╗██║██║ ███╗███████║ ██║
██╔══╝ ██║ ██║ ██║ ██║ ██║██╔══██╗██╔══╝ ██║██║╚██╗██║╚════██║██║██║ ██║██╔══██║ ██║
██║ ╚██████╔╝ ██║ ╚██████╔╝██║ ██║███████╗ ██║██║ ╚████║███████║██║╚██████╔╝██║ ██║ ██║
╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
"Unlocking the Future, One Insight at a Time"
"
# Get the current year and store it in a variable
year=$(date +%Y)
# Emojis
rocket="🚀"
pencil="✏️"
thumbs_up="👍"
warning="⚠️"
book="📖"
machine="🤖"
skills="🛠️"
web_development="🌐"
linux="🐧"
windows="🪟"
code="💻"
operating_system="🖥️"
report="💻 📊"
# Check if Hugo is installed
if ! command -v hugo &> /dev/null; then
echo "${warning} Hugo is not installed on your system."
echo "Please install Hugo before running this script."
echo "You can install Hugo from: https://gohugo.io/installation/"
exit 1
fi
# Section: Category Selection
echo "=== ${rocket} Category Selection ==="
echo "Please select a category:"
echo "1. ${rocket} machine-learning"
echo "2. ${rocket} essential-skills"
echo "3. ${rocket} Web-Development"
echo "4. ${rocket} OS"
echo "5. ${rocket} linux"
echo "6. ${rocket} windows"
echo "7. ${rocket} Code-Report"
echo "8. ${rocket} AI-Thoughts"
echo "9. ${rocket} MultiVerse-Insights"
echo "10. ${rocket} Write your Ownn Category"
# Function to validate user input as a number
validate_number() {
if [[ $1 =~ ^[0-9]+$ ]]; then
return 0
else
return 1
fi
}
# Prompt the user for category until a valid number is entered
while true; do
read -rp "${pencil} Enter the number corresponding to your choice: " category
validate_number "$category"
if [ $? -eq 0 ]; then
case $category in
1) category="machine-learning"; break;;
2) category="essential-skills"; break;;
3) category="Web-Development"; break;;
4) category="OS"; break;;
5) category="linux"; break;;
6) category="windows"; break;;
7) category="Code-Report"; break;;
8) category="AI-Thoughts"; break;;
9) category="MultiVerse-Insights"; break;;
10) read -rp "${pencil} Enter the name of the category: " category; break;;
*) echo "Invalid choice. Please enter a valid number.";;
esac
else
echo "Invalid input. Please enter a number."
fi
done
echo
echo
# Telling user which caregory they have seclected using emoji plus category name
if [[ "$category" = "machine-learning" ]]; then
echo "=== ${machine} You have seclect: ${category} Category ==="
elif [[ "$category" = "essential-skills" ]]; then
echo "=== ${skills} You have seclect: ${category} Category ==="
elif [[ "$category" = "Web-Development" ]]; then
echo "=== ${web_development} You have seclect: ${category} Category ==="
elif [[ "$category" = "OS" ]]; then
echo "=== ${operating_system} You have seclect: ${category} Category ==="
elif [[ "$category" = "linux" ]]; then
echo "=== ${linux} You have seclect: ${category} Category ==="
elif [[ "$category" = "windows" ]]; then
echo "=== ${windows} You have seclect: ${category} Category ==="
elif [[ "$category" = "Code-Report" ]]; then
echo "=== ${report} You have seclect: ${category} Category ==="
elif [[ "$category" = "AI-Thoughts" ]]; then
echo "=== ${code} You have seclect: ${category} Category ==="
elif [[ "$category" = "MultiVerse-Insights" ]]; then
echo "=== ${book} You have seclect: ${category} Category ==="
else
echo "=== ${book} You have seclect: ${category} Category ==="
fi
echo
echo
# Section: Blog Post Name
echo "=== ${rocket} Blog Post Name ==="
# Loop until a valid blog post name is entered
while true; do
read -rp "${pencil} Enter the name of the blog post: " blog_post_name
# Validate the blog post name
if [[ -z "$blog_post_name" ]]; then
echo "${warning} Blog post name cannot be empty."
echo "Please enter a valid blog post name."
else
break
fi
done
echo
# Section: Creating Blog Post
echo "=== ${rocket} Creating Blog Post ==="
# Use the variables to generate the command
if [ "$category" = "Code-Report" ]; then
date=$(date +%Y-%m-%d)
command="hugo new post/${year}/${category}/${date}-${blog_post_name}.md"
elif [ "$category" = "windows" ];then
command="hugo new post/${year}/OS/windows/${blog_post_name}.md"
elif [ "$category" = "linux" ];then
command="hugo new post/${year}/OS/linux/${blog_post_name}.md"
else
command="hugo new post/${year}/${category}/${blog_post_name}.md"
fi
# Execute the command
output=$(eval "$command")
if [ $? -eq 0 ]; then
# Extract the path from the command output
path=$(echo "$output" | cut -d' ' -f2)
echo
# Section: Success Message
echo "=== ${rocket} Success! ==="
echo "${thumbs_up} New blog post created successfully!"
echo "Blog post location: $path"
else
# Section: Error Message
echo
echo "=== ${rocket} Error! ==="
echo "An error occurred while creating the blog post."
echo "Please see the error message above for details."
exit 1
fi
echo
# Random Nice Message
nice_messages=(
"Great job! Keep up the amazing work!"
"Your insights are valuable and appreciated!"
"You're making a positive impact with your writing!"
"Continue sharing your knowledge and inspiring others!"
"Congratulations on another fantastic blog post!"
)
# Select a random message from the array
random_index=$((RANDOM % ${#nice_messages[@]}))
random_message=${nice_messages[$random_index]}
echo "=== ${rocket} Nice Message ==="
echo "${random_message}"
echo