commit f083a27ffecea17f51cd3e51a43de0b6515d01c3
parent 2d5bc36e2f36198dc9ef8d81075657b27b3e71de
Author: mjkloeckner <martin.cachari@gmail.com>
Date: Sun, 25 Sep 2022 20:36:16 -0300
General scripts clean
Diffstat:
4 files changed, 32 insertions(+), 102 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
profile*
logos
fonts/Futura
+deploy.sh
diff --git a/css/style.css b/css/style.css
@@ -298,8 +298,8 @@ code {
padding-top: .5em;
padding-bottom: .5em;
- padding-left: 1em;
- padding-right: 1em;
+ padding-left: .75em;
+ padding-right: .75em;
border-radius: .2em;
diff --git a/sort_blog_index.py b/sort_blog_index.py
@@ -1,26 +1,46 @@
#!/usr/bin/env python3
-
-# usage:
+
+# Generates a list of file names sorted based on a date contained in them.
+# Files in root folder must have a line like the following:
+# <meta name="article-date" content="23-Oct-2022">
+# also the folders in the root folder must have a file named the same as
+# the folder but with an html extension.
+
+# For example:
+# root_folder
+# |- first_folder
+# | `-- first_folder.html
+# `-- second_folder
+# `-- second_folder.html
+
+# The program executed with the root_folder path as argument should print to
+# stdout the names of first_folder and second_folder sorted based on the
+# contents of the first_folder.html and second_folder.html
+
+# usage:
# ./sort_blog_index.py <root_folder>
+# if no root_folder path is provided then the current path is assumed
+# author: github.com/mjkloeckner
+
import os
import re
import time
import datetime
import sys
+date_delimiter = "-"
+regex = re.compile('(?<=<meta name="article-date" content=")(.*?)(?=")')
+suffix = '.html'
+paths = []
+
if len(sys.argv) == 1:
- print("No PATH provided, assuming current folder")
+ print("==> No PATH provided, assuming current folder")
root_folder = os.path.abspath(os.getcwd())
print(root_folder)
else:
root_folder = sys.argv[1]
-# root_folder = "/home/mk/soydev/webp/tmp/html/blog/"
-date_delimiter = "-"
-regex = re.compile('(?<=<meta name="article-date" content=")(.*?)(?=")')
-
-# <meta name="article-date" content="23-Oct-2021">
def get_content(file_name):
with open(file_name) as f:
for line in f:
@@ -28,11 +48,7 @@ def get_content(file_name):
if result is not None:
return time.mktime(datetime.datetime.strptime(result.group(0), "%d-%b-%Y").timetuple())
-# list file and directories
folders = os.listdir(root_folder)
-suffix = '.html'
-
-paths = []
for folder in folders:
paths.append(os.path.join(root_folder, folder + "/" + folder + suffix))
diff --git a/sync.sh b/sync.sh
@@ -2,7 +2,6 @@
set -xe
-page_title="Martin Klöckner's webpage"
root_folder="/home/mk/soydev/webp/kloeckner.com.ar"
blog_folder="blog"
blog_index_file="blog_index.shtml"
@@ -16,10 +15,7 @@ generate_blog_index() {
touch $root_folder/$blog_index_file
for i in $(./sort_blog_index.py /home/mk/soydev/webp/tmp/html/blog/); do
- # article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oE '[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}')
article_date=$(cat $i | grep -oP '(?<=<meta name="article-date" content=")(.*?)(?=")')
-
- # article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP "(?<=<title>)(.*?)(?= - $page_title)")
article_title=$(cat $i | grep -oP '(?<=<meta name="article-title" content=")(.*?)(?=")')
file_name=$(echo "$i" | grep -oE '[^/]*$' | cut -d '.' -f 1)
@@ -30,27 +26,6 @@ generate_blog_index() {
{ set -xe; } 2>/dev/null
}
-generate_latest_uploads_old() {
- { set +xe; } 2>/dev/null
-
- rm $root_folder/$latest_uploads_file 2> /dev/null
-
- for i in $(ls -lt $blog_folder); do
- # if exists and it's a directory
- if [ -d $root_folder/$blog_folder/$i ]; then
- # article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oE '[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}')
- article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP '(?<=<meta name="article-date" content=")(.*?)(?=")')
-
- # article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP "(?<=<title>)(.*?)(?= - $page_title)")
- article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP '(?<=<meta name="article-title" content=")(.*?)(?=")')
-
- printf "<li><time>%s</time> <a href=\"/$blog_folder/$i/$i.html\">%s</a></li>\n" "${article_date}" "${article_title}" >> $root_folder/$latest_uploads_file
- fi
- done
-
- { set -xe; } 2>/dev/null
-}
-
generate_latest_uploads() {
{ set +xe; } 2>/dev/null
@@ -61,64 +36,6 @@ generate_latest_uploads() {
{ set -xe; } 2>/dev/null
}
-generate_rss_feed_old() {
- { set +xe; } 2>/dev/null
-
- # printf "# Blog\n\n[RSS Feed](feed.xml)\n\n" > $bf
-
- cp rss_feed_top.xml $rss_feed_file
- printf "<lastBuildDate>%s</lastBuildDate>\n" "$(date)" >> $rss_feed_file
- # printf "<atom:link href=\"https://kloeckner.com.ar/rss.xml\" rel=\"self\" type=\"application/rss+xml\"/>\n" >> $rss_feed_file
-
- for i in $(ls "$blog_folder"); do
- # if exists and it's a directory
- if [ -d $root_folder/$blog_folder/$i ]; then
- last_modified=$(stat $root_folder/$blog_folder/$i/$i.html --format "%Y")
- rss_file_date=$(stat $rss_feed_file --format "%Y")
-
- # article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oE '[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}')
- article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP '(?<=<meta name="article-date" content=")(.*?)(?=")')
- # article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP "(?<=<title>)(.*?)(?= - $page_title)")
- article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP '(?<=<meta name="article-title" content=")(.*?)(?=")')
- # article_description="$(cat $root_folder/$blog_folder/$i/$i.html | sed 's/ \|\t//g' | tr --delete '\n' | grep -oE '<article>.*</article>')"
-
- pandoc $root_folder/$blog_folder/$i/$i.html -o $root_folder/$blog_folder/$i/$i.md
- article_description="$(md2html $root_folder/$blog_folder/$i/$i.md | sed -E -e 's/ \(last\ update//g' -e 's/\{[^\}]*\}//g' -e 's/<code>|<\/code>//g' -e 's/<em>|<\/em>//g')"
- rm $root_folder/$blog_folder/$i/$i.md
-
- # Get basic data of the post (date, title)
- # f="src/blog/$i/*.md"
- # d=$(echo $i | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')
- # t=$(head -n 1 $f | sed 's/# //')
-
- # Add blog post to the list
- # echo "* $d [$t]($i)" >> $bf
-
- # Create RSS feed item
- echo "<item>" >> $rss_feed_file
- echo "<title>$article_title</title>" >> $rss_feed_file
- echo "<link>https://kloeckner.com.ar/blog/$i/$i.html</link>" >> $rss_feed_file
- echo "<description>
- <htmlData>
- <![CDATA[<html> $article_description </html> ]]>
- </htmlData>
- </description>" >> $rss_feed_file
- echo "<pubDate>$article_date</pubDate>" >> $rss_feed_file
- echo "$article_date"
- echo "</item>" >> $rss_feed_file
- echo "" >> $rss_feed_file
- # printf "" "${article_date}" "${article_title}" >> $root_folder/$latest_uploads_file
- fi
- done
-
- # Close the RSS feed file
- echo "" >> $rss_feed_file
- echo "</channel>" >> $rss_feed_file
- echo "</rss>" >> $rss_feed_file
-
- { set -xe; } 2>/dev/null
-}
-
generate_rss_feed() {
{ set +xe; } 2>/dev/null
@@ -128,12 +45,8 @@ generate_rss_feed() {
printf "<lastBuildDate>%s</lastBuildDate>\n" "$(date)" >> $rss_feed_file
for i in $(./sort_blog_index.py /home/mk/soydev/webp/tmp/html/blog/); do
- # article_date=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oE '[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}')
article_date=$(cat $i | grep -oP '(?<=<meta name="article-date" content=")(.*?)(?=")')
-
- # article_title=$(cat $root_folder/$blog_folder/$i/$i.html | grep -oP "(?<=<title>)(.*?)(?= - $page_title)")
article_title=$(cat $i | grep -oP '(?<=<meta name="article-title" content=")(.*?)(?=")')
-
file_name=$(echo "$i" | grep -oE '[^/]*$' | cut -d '.' -f 1)
pandoc $root_folder/$blog_folder/$file_name/$file_name.html -o $root_folder/$blog_folder/$file_name/$file_name.md
@@ -194,7 +107,7 @@ esac
chown mk:mk $root_folder/$latest_uploads_file
-rm -r /var/www/html || true
+rm -rf /var/www/html 2>/dev/null
cp -rf $root_folder /var/www/html