From 07b387685336e9bb6bee84ee1e79528d031df462 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 8 Aug 2021 04:39:56 +0100 Subject: [PATCH] added rss --- build.py | 25 ++++++++++++++++++++++--- templates/item.xml | 6 ++++++ templates/rss.xml | 10 ++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 templates/item.xml create mode 100644 templates/rss.xml diff --git a/build.py b/build.py index 0f88612..5e9a0c3 100644 --- a/build.py +++ b/build.py @@ -39,8 +39,12 @@ def formatEntry(content, page): def make(): - shutil.rmtree(dist) - os.makedirs(os.path.join(dist, "entries")) + try: + os.makedirs(os.path.join(dist, "entries")) + except: + print("Already have content") + shutil.rmtree(os.path.join(dist, "src")) + shutil.rmtree(os.path.join(dist, "images")) shutil.copytree(source, os.path.join(dist, "src")) shutil.copytree(images, os.path.join(dist, "images")) @@ -53,7 +57,7 @@ def make(): formatEntry(summary_templ, page) .replace( "%content%", - "\n".join(page["html"].split("\n")[:10]) + "\n".join(page["html"].split("\n")[:summary_max]) ) for page in pages @@ -82,6 +86,21 @@ def make(): ) + item_templ = getTemplateHTML("item.xml") + rss_templ = getTemplateHTML("rss.xml") + itemsXML = "\n".join( + [ + formatEntry(item_templ, page).replace("%content%", page["html"]) + for page in pages + ] + ) + + with open(os.path.join(dist, "rss.xml"), "w") as index: + index.write( + rss_templ.replace("%items%", itemsXML) + ) + + print(f"built in {len(pages)} pages") make() diff --git a/templates/item.xml b/templates/item.xml new file mode 100644 index 0000000..031cd35 --- /dev/null +++ b/templates/item.xml @@ -0,0 +1,6 @@ + + %name% + https://davidovski.xyz/%url% + %date% + + diff --git a/templates/rss.xml b/templates/rss.xml new file mode 100644 index 0000000..ac4cfba --- /dev/null +++ b/templates/rss.xml @@ -0,0 +1,10 @@ + + + + + kblg + https://github.com/davidovski/kblg + kblg + %items% + +