-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tmp.header
88 lines (71 loc) · 2.9 KB
/
.tmp.header
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
#!/bin/bash
################################################################################
# Name: mblog.sh
# Date: 2024-06-06
# Author: Amosnimos
# Description: To convert text files (date, title, content) to HTML articles with basic structure in designated output directory.
################################################################################
# ▙▗▌▛▀▖▌ ▞▀▖▞▀▖ ▞▀▖▌ ▌
# ▌▘▌▙▄▘▌ ▌ ▌▌▄▖ ▚▄ ▙▄▌
# ▌ ▌▌ ▌▌ ▌ ▌▌ ▌▗▖▖ ▌▌ ▌
# ▘ ▘▀▀ ▀▀▘▝▀ ▝▀ ▝▘▝▀ ▘ ▘
# mblog
# For handling error message
error() {
echo -e "\e[1;37;41mError: $1\e[0m"
if [[ -n "$2" ]]; then
exit 0
fi
}
day="$(date +%F)"
if [[ $# -gt 0 ]]; then
text_file=$1
else
read -p "Text file: " text_file
fi
read -p "Title: " title_selected
if [[ "$title_selected" == "" ]]; then
title_selected=$(basename "$text_file" .txt)
fi
read -p "Image URL: " image_url
if [[ "$image_url" != "" ]]; then
read -p "Image Name: " image_name
fi
date=$(date +%F)
article_name_lower=$(echo "${title_selected// /_}" | tr '[:upper:]' '[:lower:]')
output_directory="post_${article_name_lower}"
if [[ ! -d "$output_directory" ]];then
mkdir "$output_directory"
else
error "$output_directory already exist"
exit 1
fi
image_extension="${image_url##*.}"
curl "$image_url" "${output_directory}/${image_name}.${extension}"
output_file="post_${article_name_lower}/${day}_${article_name_lower}.html"
# Empty/create the output file
> "$output_file"
echo -ne "<!DOCTYPE html>\n<html>\n<head>\n<title>Amos Nimos: $title_selected</title>\n<link rel=\"icon\" type=\"img/x-icon\" href=\"img/favicon.ico\">\n<link rel=\"stylesheet\" href=\"../../../css/light.css\">\n</head>\n<body>\n<main>\n" >> "$output_file"
echo "<a class=\"btn-h\" href=\"../../../index.html\">Home</a> <a class=\"btn-h\" href=\"../blog.html\">Blog</a>" >> "$output_file"
echo "<h2 class=\"title\">$title_selected</h2>" >> "$output_file"
echo "<div class=\"article\">" >> "$output_file"
if [[ "$image_url" != "" ]]; then
echo "<img src=\"$image_url\" alt=\"$image_name\">" >> "$output_file"
fi
echo "<h3>$date</h3>" >> "$output_file"
echo "<p>" >> "$output_file"
if [[ ! -f "$text_file" ]]; then
echo "If no text file was provided, this is the default text you will see." >> "$output_file"
echo "ERROR: no file was provided!"
else
# Use sed to replace empty lines with two HTML new line tags
sed -e 's/^$/<\/p><p>/' "$text_file" >> "$output_file"
fi
echo "</p>" >> "$output_file"
echo "<p class=\"footer\">By Amos Nimos</p>" >> "$output_file"
echo -ne "</div>\n</main>\n</body>\n" >> "$output_file"
echo "<a class=\"btn-v\" href=\"post/${day}_${article_name_lower}.html\">[$date] $title_selected</a>" >> "post_${article_name_lower}/link.txt"
# Make the add link to blog.html page
if [[ -d ../../post ]]; then
cp $output_file ../../post/
fi