diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/.gitignore | 4 | ||||
-rwxr-xr-x | data/pyreplace.py | 15 | ||||
-rwxr-xr-x | data/rfc822date.py | 27 | ||||
-rw-r--r-- | data/template_rss_footer.xml | 3 | ||||
-rw-r--r-- | data/template_rss_header.xml | 11 | ||||
-rw-r--r-- | data/template_rss_item.xml | 10 | ||||
-rwxr-xr-x | data/update.sh | 31 |
7 files changed, 98 insertions, 3 deletions
diff --git a/data/.gitignore b/data/.gitignore index 8c1463c..1ea768b 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -1,3 +1,3 @@ -*.html INDEX.md -index.html +*.html +index.xml diff --git a/data/pyreplace.py b/data/pyreplace.py new file mode 100755 index 0000000..71e970e --- /dev/null +++ b/data/pyreplace.py @@ -0,0 +1,15 @@ +#!/bin/env python3 + +import sys + +if __name__ == '__main__': + if len(sys.argv) < 3: + sys.exit() + + data = [] + with open(sys.argv[3], 'r+') as file: + data = file.read() + data = data.replace(sys.argv[1], sys.argv[2]) + file.close() + with open(sys.argv[3], 'w') as filew: + filew.write(data) diff --git a/data/rfc822date.py b/data/rfc822date.py new file mode 100755 index 0000000..8ea9446 --- /dev/null +++ b/data/rfc822date.py @@ -0,0 +1,27 @@ +#!/bin/env python3 + +from datetime import datetime +import sys + +def help(): + print(sys.argv[0] + " YYYY-MM-DD-HHMMSS [+XXXX]") + +# test +#indate = "2022-12-22-182343" + +timezone = "+0000" + +if len(sys.argv) <= 1: + print("error no arg") + help() + sys.exit() +if len(sys.argv) == 3: + timezone = sys.argv[2] +if len(sys.argv) > 3: + print("error > 2 args") + help() + sys.exit() + +indate = sys.argv[1] +d = datetime.strptime(indate, "%Y-%m-%d-%H%M%S") +print(d.strftime("%a, %d %b %Y %H:%M:%S") + " " + timezone) diff --git a/data/template_rss_footer.xml b/data/template_rss_footer.xml new file mode 100644 index 0000000..a353561 --- /dev/null +++ b/data/template_rss_footer.xml @@ -0,0 +1,3 @@ + + </channel> +</rss> diff --git a/data/template_rss_header.xml b/data/template_rss_header.xml new file mode 100644 index 0000000..d15dbc9 --- /dev/null +++ b/data/template_rss_header.xml @@ -0,0 +1,11 @@ +<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> + <channel> + <title>$TITLE$</title> + <link>$TITLE_LINK$</link> + <description>$TITLE_DESC$</description> + <generator></generator> + <language>en-us</language> + <lastBuildDate></lastBuildDate> + <atom:link href="$MY_URL$" rel="self" type="application/rss+xml" /> + + diff --git a/data/template_rss_item.xml b/data/template_rss_item.xml new file mode 100644 index 0000000..5e74373 --- /dev/null +++ b/data/template_rss_item.xml @@ -0,0 +1,10 @@ + <item> + <title>$ITEM_TITLE$</title> + <link>$ITEM_LINK$</link> + <pubDate>$ITEM_PUBDATE$</pubDate> + <guid>$ITEM_LINK$</guid> + <description> + $ITEM_DESC$ + </description> + </item> + diff --git a/data/update.sh b/data/update.sh index 687c805..e7cb139 100755 --- a/data/update.sh +++ b/data/update.sh @@ -1,7 +1,21 @@ -#!/bin/sh +#!/bin/bash + +# RSS +RSS_TITLE='omeckman.net pub-docs' +RSS_TITLE_LINK='https://omeckman.net/pub-docs/' +RSS_TITLE_DESC='omeckman.net public documents / $blog' +RSS_MY_URL=${RSS_TITLE_LINK} cp INDEX_template.md INDEX.md +cp template_rss_header.xml index.xml + +#sed -i "s/\\\$TITLE</${RSS_TITLE}</g" index.xml +python3 pyreplace.py '$TITLE$' "${RSS_TITLE}" index.xml +python3 pyreplace.py '$TITLE_LINK$' "$RSS_TITLE_LINK" index.xml +python3 pyreplace.py '$TITLE_DESC$' "${RSS_TITLE_DESC}" index.xml +python3 pyreplace.py '$MY_URL$' "${RSS_MY_URL}" index.xml + for i in *.md do filename_wo_ext=$(echo "$i" | cut -f 1 -d '.') @@ -12,9 +26,24 @@ do if [ $filename_wo_ext != "INDEX" ] then echo "[$filename_wo_ext]($filename_wo_ext.html) " >> INDEX.md + + origdate=$(echo "$filename_wo_ext" | cut -f 1 -d '_') + pubdaterfc822=$(python3 rfc822date.py ${origdate}) + + RSS_ITEM_TITLE="$filename_wo_ext" + RSS_ITEM_LINK=${RSS_TITLE_LINK}${filename_wo_ext}.html + RSS_ITEM_PUBDATE=${pubdaterfc822} + RSS_ITEM_DESC=$RSS_ITEM_TITLE + cat template_rss_item.xml >> index.xml + python3 pyreplace.py '$ITEM_TITLE$' "${RSS_ITEM_TITLE}" index.xml + python3 pyreplace.py '$ITEM_LINK$' "${RSS_ITEM_LINK}" index.xml + python3 pyreplace.py '$ITEM_PUBDATE$' "${RSS_ITEM_PUBDATE}" index.xml + python3 pyreplace.py '$ITEM_DESC$' "${RSS_ITEM_DESC}" index.xml fi fi done +cat template_rss_footer.xml >> index.xml + ln -s INDEX.html index.html |