rss feeds
This commit is contained in:
parent
8c1ea36acf
commit
ff79fdd2a7
33
create_feeds.py
Normal file
33
create_feeds.py
Normal file
@ -0,0 +1,33 @@
|
||||
import posts
|
||||
import users
|
||||
import config
|
||||
|
||||
def create_rss():
|
||||
from datetime import datetime
|
||||
with open(f"{config.webroot}/rss", "w") as main_rss_file:
|
||||
file_content = f'''<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>{config.site_name}</title>
|
||||
<link>{config.site_url}</title>
|
||||
<description>{config.site_description}</description>
|
||||
<pubDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</pubDate>
|
||||
<lastBuildDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</lastBuildDate>
|
||||
'''
|
||||
for current_post_index in range(len(posts.posts)):
|
||||
file_content += f'''
|
||||
<item>
|
||||
<title>{posts.posts[current_post_index]["title"]}</title>
|
||||
<link>{config.site_url}/post/{current_post_index}.{config.file_extension}</link>
|
||||
<description>{posts.posts[current_post_index]["content"]}</descriptiont>
|
||||
<pubDate>{posts.posts[current_post_index]["pubdate"]}</pubDate>
|
||||
<editDate>{posts.posts[current_post_index]["editdate"]}</editDate>
|
||||
</item>'''
|
||||
file_content += '''
|
||||
</channel>
|
||||
</rss>'''
|
||||
|
||||
main_rss_file.write(file_content)
|
||||
|
||||
def create_atom():
|
||||
print("Atom generation under development")
|
@ -54,6 +54,9 @@ def create_post_page(post_index):
|
||||
|
||||
def create_timeline():
|
||||
with open(f"{config.webroot}/index.{config.file_extension}", "w") as timeline_file:
|
||||
site_header = config.site_header
|
||||
site_header = parse_post.parse_header(site_header)
|
||||
timeline_file.write(f"{site_header}")
|
||||
output.log("Writing posts to timeline")
|
||||
for current_post_index in range(len(posts.posts)-1,-1,-1):
|
||||
username = users.users[posts.posts[current_post_index]["userID"]]
|
||||
|
@ -1,13 +1,19 @@
|
||||
### General ###
|
||||
site_url = "gemini://example.com"
|
||||
webroot = "/path/to/root"
|
||||
site_name = "Example Name"
|
||||
site_description = "This Site is about X, Y and Z topics!"
|
||||
webroot = "/path/to/webroot"
|
||||
date_format = "%d/%m/%Y at %H:%M" # The date that is displayed on the page
|
||||
post_seperator = "---------------------------------------------"
|
||||
posts_in_timeline = 100
|
||||
file_extension = "gmi" # Could also be .html, .md, .txt or any other file extension
|
||||
file_extension = "gmi"
|
||||
|
||||
### Feeds ###
|
||||
atom = False
|
||||
rss = True
|
||||
|
||||
### Logging ###
|
||||
logfile = "/path/to/logfile"
|
||||
logfile = "./log"
|
||||
verbose = False
|
||||
|
||||
### Format ###
|
||||
@ -20,6 +26,14 @@ verbose = False
|
||||
# %L - URL Permanent link to the post
|
||||
# %U - URL the the user (poster)
|
||||
# %N - the username of the user (poster)
|
||||
# %R - Site wide RSS feed
|
||||
# %Y - Site Name as defined by site_name
|
||||
# %y - Site Descriptin as defined by site_description
|
||||
site_header = '''
|
||||
# %Y
|
||||
## %y
|
||||
=> %R RSS Feed
|
||||
'''
|
||||
user_page_post_format = '''
|
||||
## %T
|
||||
%C
|
||||
@ -36,8 +50,10 @@ Published: %D
|
||||
Last Edited: %E
|
||||
'''
|
||||
timeline_post_format = '''
|
||||
## %T
|
||||
### %T
|
||||
%C
|
||||
=> %U %N
|
||||
=> %L permalink
|
||||
%S
|
||||
'''
|
||||
|
||||
autogenerated = True
|
||||
|
@ -9,7 +9,14 @@ try:
|
||||
except:
|
||||
print("No users database")
|
||||
initialise.initialise()
|
||||
try:
|
||||
import config
|
||||
if config.autogenerated == True:
|
||||
print("Error: autogenerated = True")
|
||||
exit()
|
||||
except:
|
||||
print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False")
|
||||
exit()
|
||||
import newpost
|
||||
import editpost
|
||||
import rebuild
|
||||
|
@ -15,3 +15,10 @@ def parse_post_format(post, post_index, username):
|
||||
|
||||
return post
|
||||
|
||||
def parse_header(header):
|
||||
header = header.replace("%R", f"{config.site_url}/rss")
|
||||
header = header.replace("%Y", f"{config.site_name}")
|
||||
header = header.replace("%y", f"{config.site_description}")
|
||||
return header
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import config
|
||||
import create_pages
|
||||
import create_feeds # Rss, Atom
|
||||
try:
|
||||
import users
|
||||
except:
|
||||
@ -8,8 +9,14 @@ try:
|
||||
import posts
|
||||
except:
|
||||
print("No posts database")
|
||||
|
||||
|
||||
def rebuild():
|
||||
create_pages.create_timeline()
|
||||
if config.rss == True:
|
||||
create_feeds.create_rss()
|
||||
if config.atom == True:
|
||||
create_feeds.create_atom()
|
||||
for current_user_index in range(len(users.users)):
|
||||
create_pages.create_user_page(current_user_index, users.users[current_user_index])
|
||||
for current_post_index in range(len(posts.posts)):
|
||||
|
Loading…
x
Reference in New Issue
Block a user