diff options
author | nathansmith117 <nathansmith@posteo.com> | 2025-03-30 21:50:32 -0600 |
---|---|---|
committer | nathansmith117 <nathansmith@posteo.com> | 2025-03-30 21:50:32 -0600 |
commit | 61cbae386b256bb6adb0adaa52cd00585a0820e2 (patch) | |
tree | 90a430ea7308d35d16d918bac398342f0bfe03bc | |
parent | 45aaca33b67b1dc764b199a9e4c3aebf4892c2a7 (diff) |
Made blogging system better
-rw-r--r-- | blog/README.md | 4 | ||||
-rw-r--r-- | blog/articles.xml | 15 | ||||
-rw-r--r-- | blog/articles/dreamlog1.xml | 2 | ||||
-rw-r--r-- | blog/articles/overthinking.xml | 2 | ||||
-rw-r--r-- | blog/feed.xml | 25 | ||||
-rwxr-xr-x | blog/generate.sh | 4 | ||||
-rwxr-xr-x | blog/generate_feed.py | 49 | ||||
-rwxr-xr-x | blog/generate_html.py (renamed from blog/generate.py) | 28 | ||||
-rw-r--r-- | blog/index.html | 22 |
9 files changed, 113 insertions, 38 deletions
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 @@ +<channel> + <item> + <title>Dream log 1</title> + <name>dreamlog1</name> + <pubDate>Sun, 30 Mar 2025 01:51:00 GMT</pubDate> + <file>articles/dreamlog1.xml</file> + </item> + + <item> + <title>Overthinking</title> + <name>overthinking</name> + <pubDate>Sat, 29 Mar 2025 11:42:00 GMT</pubDate> + <file>articles/overthinking.xml</file> + </item> +</channel> 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 @@ <article> - <p id="dreamlog1"> + <p> 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 @@ <article> - <p id="overthinking"> + <p> 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 @@ <image> <url>http://nathansmith117.beevomit.org/images/icon.png</url> <title>Nathan's shitty blog</title> - <link>http://nathansmith117.beevomit.org</link> + <link>http://nathansmith117.beevomit.org/blog</link> </image> - - + <item> <title>Dream log 1</title> <link>http://nathansmith117.beevomit.org/blog#dreamlog1</link> <pubDate>Sun, 30 Mar 2025 01:51:00 GMT</pubDate> <description> <![CDATA[ -<article> - <p id="dreamlog1"> + <article> + <p> 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. - </p> + </p> </article> - ]]> - </description> - </item> + ]]> + </description> + </item> + <item> <title>Overthinking</title> <link>http://nathansmith117.beevomit.org/blog#overthinking</link> <pubDate>Sat, 29 Mar 2025 11:42:00 GMT</pubDate> <description> <![CDATA[ -<article> - <p id="overthinking"> + <article> + <p> 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. </p> </article> + ]]> </description> </item> + </channel> </rss> + 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 = """<?xml version="1.0" encoding="UTF-8" ?> +<rss version=\"2.0\"> + <channel> + <title>Nathan's shitty blog</title> + <description>The coffee powered blog of chaos</description> + <link>http://nathansmith117.beevomit.org/blog</link> + <image> + <url>http://nathansmith117.beevomit.org/images/icon.png</url> + <title>Nathan's shitty blog</title> + <link>http://nathansmith117.beevomit.org/blog</link> + </image> + """ + + for item in root: + with open(item.find("file").text, "r") as fp: + feed_xml += """ + <item> + <title>{title}</title> + <link>http://nathansmith117.beevomit.org/blog#{name}</link> + <pubDate>{date}</pubDate> + <description> + <![CDATA[ + {article} + ]]> + </description> + </item> + """.format( + title=item.find("title").text, + name=item.find("name").text, + date=item.find("pubDate").text, + article=fp.read() + ) + + feed_xml += """ + </channel> +</rss> + """ + print(feed_xml) + +if __name__ == "__main__": + main() diff --git a/blog/generate.py b/blog/generate_html.py index 09c2320..7360fa3 100755 --- a/blog/generate.py +++ b/blog/generate_html.py @@ -9,25 +9,21 @@ 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 = """ - <table border="1" width="60%"> - <tr><td><h2>{title}</h2>--- {date}</td></tr> - <tr><td>{article}</td></tr> - </table> - """ - - html_text = html_text.format( + return """ + <table border="1" width="60%"> + <tr><td><h2 id=\"{name}\">{title}</h2>--- {date}</td></tr> + <tr><td>{article}</td></tr> + </table> + """.format( + name=article_info["name"], title=article_info["title"], date=article_info["pubDate"], article=article ) - - return html_text def main(): - tree = et.parse("feed.xml") + tree = et.parse("articles.xml") root = tree.getroot() - channel = root[0] template = "" @@ -38,13 +34,17 @@ def main(): article_html = "" # Get articles from rss - for item in channel.findall("item"): + for item in root: article_info = { "title": item.find("title").text, + "name": item.find("name").text, "pubDate": item.find("pubDate").text } + + article = "" - article = item.find("description").text + with open(item.find("file").text, "r") as fp: + article = fp.read() # Remove article tags. article = article[article.find("<article>")+9::] 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 { <!-- Python will insert the articles from rss here --> - <table border="1" width="60%"> - <tr><td><h2>Dream log 1</h2>--- Sun, 30 Mar 2025 01:51:00 GMT</td></tr> - <tr><td> - <p id="dreamlog1"> + <table border="1" width="60%"> + <tr><td><h2 id="dreamlog1">Dream log 1</h2>--- Sun, 30 Mar 2025 01:51:00 GMT</td></tr> + <tr><td> + <p> 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. - </p> + </p> </td></tr> - </table> + </table> - <table border="1" width="60%"> - <tr><td><h2>Overthinking</h2>--- Sat, 29 Mar 2025 11:42:00 GMT</td></tr> - <tr><td> - <p id="overthinking"> + <table border="1" width="60%"> + <tr><td><h2 id="overthinking">Overthinking</h2>--- Sat, 29 Mar 2025 11:42:00 GMT</td></tr> + <tr><td> + <p> 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. </p> </td></tr> - </table> + </table> </center> </body> |