aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitali64 <vitali64pmemail@protonmail.com>2021-12-18 18:07:24 +0100
committerVitali64 <vitali64pmemail@protonmail.com>2021-12-18 18:08:28 +0100
commit1cdae9a1928acbf35b3780be282afbbc2d5ae77c (patch)
tree0be231c02429250652075505da8ebba2c7d0acc0
parentb0530c4d4d283b5dbdcc18e3ee60a876c3997aa3 (diff)
downloadseen-1cdae9a1928acbf35b3780be282afbbc2d5ae77c.tar.gz
seen-1cdae9a1928acbf35b3780be282afbbc2d5ae77c.zip
be more verbose and add some new options
New options are added : --rm and --clear. It's also more verbose.
-rwxr-xr-xmain.sh37
-rw-r--r--red.html33
2 files changed, 36 insertions, 34 deletions
diff --git a/main.sh b/main.sh
index b3e4c19..b46e9cc 100755
--- a/main.sh
+++ b/main.sh
@@ -6,12 +6,40 @@
# START
+usage() {
+ echo "Usage : ./seen [OPTIONS]"
+ echo
+ echo "--clear : Remove generated blog"
+ echo "--rm : Remove everything and start from scratch"
+}
+
+echo -e "Seen, a simple static blog generator\n Licensed under the GNU GPLv3"
+
+if [ $1 = "--clear" ]; then
+ echo "-> [$(date +%R)] Deleting generated blog ..."
+ rm -rf "www/*"
+ exit
+elif [ $1 = "--rm" ]; then
+ echo "-> [$(date +%R)] Deleting all data ..."
+ rm -rf "www/*" "articles/*"
+ exit
+elif [ $1 = "" ]; then
+ echo "-> [$(date +%R)] No options specified, generating blog ..."
+else
+ echo "-> [$(date +%R)] Error : Invalid option, cannot continue."
+ usage
+ exit 1
+fi
+
# Erase www/index.html and insert the header
+echo "-> [$(date +%R)] Inserting the header ..."
+
cat "templates/header.html" > www/index.html
# Detect articles
+echo "-> [$(date +%R)] Detecting articles' markdown file ..."
articles="$(ls -1 articles/*.md|sed -e 's@.md@@g' -e 's@articles/@@g')"
# Set the defaults
@@ -24,11 +52,15 @@ date="1st January 1970"
for line in ${articles}
do
+
. "articles/${line}.cfg" # Override the defaults
+ mkdir "www/articles" 2&>/dev/null
cat "templates/header.html" > "www/articles/${line}.html" # Erase <article>.html and insert the header
+ echo "-> [$(date +%R)] Converting ${line}.md to html ..."
markdown "articles/${line}.md" >> "www/articles/${line}.html" # Convert the markdown text to html
+ echo "-> [$(date +%R)] Adding ${line} article to index.html ..."
cat "templates/footer.html" >> "www/articles/${line}.html" # Insert the footer into the article page
# Add an entry in index.html
@@ -42,7 +74,10 @@ done
# Insert the footer into the index.html
+echo "-> [$(date +%R)] Inserting the footer ..."
+
cat "templates/footer.html" >> "www/index.html"
-echo "Enjoy your blog."
+echo "-> [$(date +%R)] Generation made successfully!"
+echo "Enjoy your blog. Exiting ..."
diff --git a/red.html b/red.html
deleted file mode 100644
index ba88b5e..0000000
--- a/red.html
+++ /dev/null
@@ -1,33 +0,0 @@
-<h1>seen</h1>
-
-<p><em>A simple blog generator written in bash</em></p>
-
-<h3>How to use</h3>
-
-<p>First, install <code>markdown</code> because this script uses it heavily.</p>
-
-<p>Put your markdown files on <code>articles/&lt;name of file&gt;.md</code>.</p>
-
-<p>You also need to create a config file. Put it in <code>articles/&lt;name of file&gt;.cfg</code>. It should use the same name your markdown file uses.</p>
-
-<ul>
-<li>Example :</li>
-</ul>
-
-
-<pre><code>
-
-name="Hello World"
-
-desc="Welcome to my blog!"
-
-date="9th December 2021"
-
-</code></pre>
-
-
-<p>And run the following:</p>
-
-<pre><code>$ chmod +x main.sh
-$ ./main.sh
-</code></pre>