mirror of
https://git.davidovski.xyz/kblg.git
synced 2024-08-15 00:43:36 +00:00
added rss
This commit is contained in:
parent
e021b7b1f8
commit
07b3876853
3 changed files with 38 additions and 3 deletions
25
build.py
25
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()
|
||||
|
||||
|
||||
|
|
6
templates/item.xml
Normal file
6
templates/item.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<item>
|
||||
<title>%name%</title>
|
||||
<link>https://davidovski.xyz/%url%</link>
|
||||
<pubDate>%date%</pubDate>
|
||||
<description><![CDATA[%content%]]></description>
|
||||
</item>
|
10
templates/rss.xml
Normal file
10
templates/rss.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
|
||||
<channel>
|
||||
<title>kblg</title>
|
||||
<link>https://github.com/davidovski/kblg</link>
|
||||
<description>kblg</description>
|
||||
%items%
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in a new issue