From 61cbae386b256bb6adb0adaa52cd00585a0820e2 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Sun, 30 Mar 2025 21:50:32 -0600 Subject: Made blogging system better --- blog/README.md | 4 +++ blog/articles.xml | 15 +++++++++++ blog/articles/dreamlog1.xml | 2 +- blog/articles/overthinking.xml | 2 +- blog/feed.xml | 25 ++++++++++-------- blog/generate.py | 59 ------------------------------------------ blog/generate.sh | 4 +++ blog/generate_feed.py | 49 +++++++++++++++++++++++++++++++++++ blog/generate_html.py | 59 ++++++++++++++++++++++++++++++++++++++++++ blog/index.html | 22 ++++++++-------- 10 files changed, 158 insertions(+), 83 deletions(-) create mode 100644 blog/README.md create mode 100644 blog/articles.xml delete mode 100755 blog/generate.py create mode 100755 blog/generate.sh create mode 100755 blog/generate_feed.py create mode 100755 blog/generate_html.py diff --git a/blog/README.md b/blog/README.md new file mode 100644 index 0000000..f9c06f2 --- /dev/null +++ b/blog/README.md @@ -0,0 +1,4 @@ +# Nathan's shitty blog +I am known for making things more complex than they need to be and this is a good example of that. + +All the articles are in articles/ and articles.xml stores information about each article. feed.xml and index.html are generated from the articles.xml file using the scripts. \ No newline at end of file diff --git a/blog/articles.xml b/blog/articles.xml new file mode 100644 index 0000000..171c186 --- /dev/null +++ b/blog/articles.xml @@ -0,0 +1,15 @@ + + + Dream log 1 + dreamlog1 + Sun, 30 Mar 2025 01:51:00 GMT + articles/dreamlog1.xml + + + + Overthinking + overthinking + Sat, 29 Mar 2025 11:42:00 GMT + articles/overthinking.xml + + diff --git a/blog/articles/dreamlog1.xml b/blog/articles/dreamlog1.xml index f7fc19f..00469c8 100644 --- a/blog/articles/dreamlog1.xml +++ b/blog/articles/dreamlog1.xml @@ -1,5 +1,5 @@
-

+

Last night I had the type of dream that inspires new stories. In my dream the favorite author: Kurt Vonnegut, was a unix and emacs user. And he wrote a book about someone in some government position or something along those lines who spent there entire life fucking around with unix diff --git a/blog/articles/overthinking.xml b/blog/articles/overthinking.xml index f64bc32..218710b 100644 --- a/blog/articles/overthinking.xml +++ b/blog/articles/overthinking.xml @@ -1,5 +1,5 @@

-

+

Whenver I decide to add something to this website I always overthink on how to add the thing. In general I just overthink how I will do everything. It slows me down. Right now I am overthinking trying to think what to write diff --git a/blog/feed.xml b/blog/feed.xml index 90c8441..00ea328 100644 --- a/blog/feed.xml +++ b/blog/feed.xml @@ -7,18 +7,17 @@ http://nathansmith117.beevomit.org/images/icon.png Nathan's shitty blog - http://nathansmith117.beevomit.org + http://nathansmith117.beevomit.org/blog - - + Dream log 1 http://nathansmith117.beevomit.org/blog#dreamlog1 Sun, 30 Mar 2025 01:51:00 GMT -

+

+

Last night I had the type of dream that inspires new stories. In my dream the favorite author: Kurt Vonnegut, was a unix and emacs user. And he wrote a book about someone in some government position or something along those lines who spent there entire life fucking around with unix @@ -29,20 +28,21 @@ Through all the things left behind on the unix system the last person on earth learned to not only survive but live well as the last person. They even became a unix power user through the guides left behind. -

+

- ]]> - - + ]]> + + + Overthinking http://nathansmith117.beevomit.org/blog#overthinking Sat, 29 Mar 2025 11:42:00 GMT -

+

+

Whenver I decide to add something to this website I always overthink on how to add the thing. In general I just overthink how I will do everything. It slows me down. Right now I am overthinking trying to think what to write @@ -59,8 +59,11 @@ Next time you overthink do what I do: eat junk food.

+ ]]>
+ + diff --git a/blog/generate.py b/blog/generate.py deleted file mode 100755 index 09c2320..0000000 --- a/blog/generate.py +++ /dev/null @@ -1,59 +0,0 @@ -#! /usr/bin/python3 - -""" -A script to generate html from the rss feed -""" - -import xml.etree.ElementTree as et - -# Generates a html table for the article -# I use table layout because fuck you -def make_article_table(article_info, article): - html_text = """ - - - -

{title}

--- {date}
{article}
- """ - - html_text = html_text.format( - title=article_info["title"], - date=article_info["pubDate"], - article=article - ) - - return html_text - -def main(): - tree = et.parse("feed.xml") - root = tree.getroot() - channel = root[0] - - template = "" - - # Open html template - with open("template.html", "r") as fp: - template = fp.read() - - article_html = "" - - # Get articles from rss - for item in channel.findall("item"): - article_info = { - "title": item.find("title").text, - "pubDate": item.find("pubDate").text - } - - article = item.find("description").text - - # Remove article tags. - article = article[article.find("
")+9::] - article = article[:article.find("
"):] - article_html += make_article_table(article_info, article) - - # Format the articles into the html - template = template.format(articles=article_html) - print(template) - -if __name__ == "__main__": - main() diff --git a/blog/generate.sh b/blog/generate.sh new file mode 100755 index 0000000..3ded0e8 --- /dev/null +++ b/blog/generate.sh @@ -0,0 +1,4 @@ +#! /usr/bin/sh + +./generate_feed.py > feed.xml +./generate_html.py > index.html diff --git a/blog/generate_feed.py b/blog/generate_feed.py new file mode 100755 index 0000000..a8eec23 --- /dev/null +++ b/blog/generate_feed.py @@ -0,0 +1,49 @@ +#! /usr/bin/python3 + +import xml.etree.ElementTree as et + +def main(): + tree = et.parse("articles.xml") + root = tree.getroot() + + feed_xml = """ + + + Nathan's shitty blog + The coffee powered blog of chaos + http://nathansmith117.beevomit.org/blog + + http://nathansmith117.beevomit.org/images/icon.png + Nathan's shitty blog + http://nathansmith117.beevomit.org/blog + + """ + + for item in root: + with open(item.find("file").text, "r") as fp: + feed_xml += """ + + {title} + http://nathansmith117.beevomit.org/blog#{name} + {date} + + + + + """.format( + title=item.find("title").text, + name=item.find("name").text, + date=item.find("pubDate").text, + article=fp.read() + ) + + feed_xml += """ + + + """ + print(feed_xml) + +if __name__ == "__main__": + main() diff --git a/blog/generate_html.py b/blog/generate_html.py new file mode 100755 index 0000000..7360fa3 --- /dev/null +++ b/blog/generate_html.py @@ -0,0 +1,59 @@ +#! /usr/bin/python3 + +""" +A script to generate html from the rss feed +""" + +import xml.etree.ElementTree as et + +# Generates a html table for the article +# I use table layout because fuck you +def make_article_table(article_info, article): + return """ + + + +

{title}

--- {date}
{article}
+ """.format( + name=article_info["name"], + title=article_info["title"], + date=article_info["pubDate"], + article=article + ) + +def main(): + tree = et.parse("articles.xml") + root = tree.getroot() + + template = "" + + # Open html template + with open("template.html", "r") as fp: + template = fp.read() + + article_html = "" + + # Get articles from rss + for item in root: + article_info = { + "title": item.find("title").text, + "name": item.find("name").text, + "pubDate": item.find("pubDate").text + } + + article = "" + + with open(item.find("file").text, "r") as fp: + article = fp.read() + + # Remove article tags. + article = article[article.find("
")+9::] + article = article[:article.find("
"):] + article_html += make_article_table(article_info, article) + + # Format the articles into the html + template = template.format(articles=article_html) + print(template) + +if __name__ == "__main__": + main() diff --git a/blog/index.html b/blog/index.html index 1cf2096..20e1de4 100644 --- a/blog/index.html +++ b/blog/index.html @@ -51,10 +51,10 @@ table { - - -

Dream log 1

--- Sun, 30 Mar 2025 01:51:00 GMT
-

+ + + -

Dream log 1

--- Sun, 30 Mar 2025 01:51:00 GMT
+

Last night I had the type of dream that inspires new stories. In my dream the favorite author: Kurt Vonnegut, was a unix and emacs user. And he wrote a book about someone in some government position or something along those lines who spent there entire life fucking around with unix @@ -65,14 +65,14 @@ table { Through all the things left behind on the unix system the last person on earth learned to not only survive but live well as the last person. They even became a unix power user through the guides left behind. -

+

+

- - -

Overthinking

--- Sat, 29 Mar 2025 11:42:00 GMT
-

+ + + -

Overthinking

--- Sat, 29 Mar 2025 11:42:00 GMT
+

Whenver I decide to add something to this website I always overthink on how to add the thing. In general I just overthink how I will do everything. It slows me down. Right now I am overthinking trying to think what to write @@ -89,7 +89,7 @@ table { Next time you overthink do what I do: eat junk food.

+

-- cgit v1.2.3