RSS implementation
This commit is contained in:
parent
a4759785cb
commit
5cdb9bf44c
4 changed files with 101 additions and 4 deletions
|
@ -29,6 +29,8 @@ def Set():
|
|||
print()
|
||||
print(clr["tdyl"]+"--title"+clr["norm"]+" - Set title of the website.")
|
||||
print(clr["tdyl"]+"--tagline"+clr["norm"]+" - Set tagline of the website.")
|
||||
print(clr["tdyl"]+"--domain"+clr["norm"]+" - Let the server know the clearnet domain.")
|
||||
print(clr["tdyl"]+"--tor"+clr["norm"]+" - Let the server know the tor domain.")
|
||||
print(clr["tdyl"]+"--port"+clr["norm"]+" - Set port where to run the website.")
|
||||
print(clr["tdyl"]+"--css"+clr["norm"]+" - Set a CSS file.")
|
||||
print(clr["tdyl"]+"--css_edit"+clr["norm"]+" - edit a CSS file.")
|
||||
|
|
|
@ -19,6 +19,8 @@ def guess_type(path):
|
|||
return "application/json"
|
||||
if "/css" in path or ".css" in path:
|
||||
return "text/css"
|
||||
if "/rss" in path or ".rss" in path:
|
||||
return "application/rss+xml"
|
||||
if "/icon" in path or path.endswith(".png"):
|
||||
return "image/png"
|
||||
if path.endswith("jpg"):
|
||||
|
@ -62,8 +64,8 @@ def head(title="", description="", image="", config={}, author=""):
|
|||
<!-- Now meta tags for social media -->
|
||||
|
||||
<meta property="og:site_name" content=\""""+config.get("title", "My Website")+"""">
|
||||
<meta property="og:title" content=\""""+Simplify(title, False)+"""">
|
||||
<meta property="og:description" content=\""""+Simplify(description, False)+"""">
|
||||
<meta property="og:title" content=\""""+Safe(title)+"""">
|
||||
<meta property="og:description" content=\""""+Safe(description)+"""">
|
||||
<meta property="og:image" content=\""""+image+"""">
|
||||
|
||||
"""
|
||||
|
@ -425,7 +427,7 @@ def ArticlePage(server, url):
|
|||
url = url.replace(".md", "")
|
||||
|
||||
config = Set.Load()
|
||||
tab, article = url.split("/")
|
||||
tab, article, *rest = url.split("/")
|
||||
Tabs = tabs()
|
||||
Articles = articles(tab)
|
||||
f = Set.Folder()
|
||||
|
@ -483,13 +485,24 @@ def ArticlePage(server, url):
|
|||
if recording:
|
||||
html = html + '<audio controls="controls" style="min-width:100%;" src="'+recording+'"></audio>'
|
||||
|
||||
|
||||
|
||||
|
||||
html = html + '<div class="dark_box">'
|
||||
html = html + markdown.convert(f+"/tabs/"+tab+"/"+article+"/text.md")
|
||||
html = html + '</div>'
|
||||
|
||||
# RSS
|
||||
|
||||
html = html + """
|
||||
|
||||
<div class="dark_box">
|
||||
<center>
|
||||
|
||||
"""+ Button("Subscribe RSS", "/rss", "rss") +"""
|
||||
|
||||
</center>
|
||||
</div>
|
||||
"""
|
||||
|
||||
# Comments
|
||||
|
||||
|
@ -1867,3 +1880,62 @@ def ReadNotification(server):
|
|||
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Unable to read notification!", e)
|
||||
|
||||
|
||||
def RSS(server):
|
||||
|
||||
# Rendering rss feed.
|
||||
|
||||
Articles = allArticles()
|
||||
config = Set.Load()
|
||||
|
||||
favicon = config.get("favicon", "")
|
||||
if favicon.startswith("/"):
|
||||
favicon = "https://"+config.get("domain", "example.com")+favicon
|
||||
|
||||
rss = """
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<channel>
|
||||
|
||||
<title>"""+config.get("title", "My Website")+"""</title>
|
||||
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
||||
<description>"""+config.get("tagline", "")+"""</description>
|
||||
|
||||
<image>
|
||||
<url>"""+favicon+"""</url>
|
||||
<title>"""+config.get("title", "My Website")+"""</title>
|
||||
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
||||
</image>
|
||||
|
||||
"""
|
||||
|
||||
for n, article in enumerate(Articles):
|
||||
|
||||
if n > 10:
|
||||
break
|
||||
|
||||
pubDate = Articles[article].get("timestamp", 0)
|
||||
pubDate = datetime.fromtimestamp(pubDate)
|
||||
pubDate = pubDate.strftime('%a, %d %b %H:%M:%S')+" -0000"
|
||||
|
||||
rss = rss + """
|
||||
<item>
|
||||
|
||||
<title>"""+Articles[article].get("title", article)+"""</title>
|
||||
<link>https://"""+config.get("domain", "example.com")+Articles[article].get("url", "")+"""</link>
|
||||
<description><![CDATA["""+markdown.convert(Articles[article].get("description", article), False)+"""]]></description>
|
||||
<pubDate>"""+pubDate+"""</pubDate>
|
||||
|
||||
</item>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
rss = rss + """
|
||||
</channel>
|
||||
</rss>
|
||||
"""
|
||||
|
||||
send(server, rss, 200)
|
||||
|
|
|
@ -132,6 +132,9 @@ class handler(BaseHTTPRequestHandler):
|
|||
url = self.path[6:]
|
||||
if "?" in url: url = url[:url.find("?")]
|
||||
Render.Graph(self, url)
|
||||
|
||||
elif self.path == "/rss":
|
||||
Render.RSS(self)
|
||||
|
||||
elif self.path.startswith("/pictures/"):
|
||||
|
||||
|
|
|
@ -76,6 +76,17 @@ def Set():
|
|||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tagline Wasn't Specified!")
|
||||
print('Use: $ python3 run.py --set --title "Ultimate Club for Ultimate Hackers"')
|
||||
|
||||
if "--domain" in sys.argv:
|
||||
try:
|
||||
domain = sys.argv[ sys.argv.index("--domain") + 1]
|
||||
if "--" in domain: 1/0 # Failing this for the error message.
|
||||
Domain(domain)
|
||||
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the domain.", e)
|
||||
print('Use: $ python3 run.py --set --domain blenderdumbass.org')
|
||||
|
||||
|
||||
if "--port" in sys.argv:
|
||||
try:
|
||||
port = int(sys.argv[ sys.argv.index("--port") + 1])
|
||||
|
@ -147,6 +158,15 @@ def Tagline(tagline):
|
|||
|
||||
print(clr["bold"]+clr["tbyl"]+tagline+clr["norm"]+" is set as tagline.")
|
||||
|
||||
def Domain(domain):
|
||||
|
||||
data = Load()
|
||||
data["domain"] = domain
|
||||
|
||||
Save(data)
|
||||
|
||||
print(clr["bold"]+clr["tbyl"]+domain+clr["norm"]+" is set as domain.")
|
||||
|
||||
def Port(port):
|
||||
|
||||
data = Load()
|
||||
|
|
Loading…
Add table
Reference in a new issue