Added Search | RSS by author
This commit is contained in:
parent
f38e020de4
commit
9ff45581d9
2 changed files with 274 additions and 8 deletions
|
@ -347,6 +347,19 @@ def MainPage(server):
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
<form action="/search">
|
||||||
|
|
||||||
|
<input name="text" class="button" placeholder="Search..." >
|
||||||
|
|
||||||
|
<button class="button" type="submit">
|
||||||
|
<img style="vertical-align: middle" src="/icon/search">
|
||||||
|
Search
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tabs = tabs()
|
Tabs = tabs()
|
||||||
for tab in Tabs:
|
for tab in Tabs:
|
||||||
|
@ -543,12 +556,36 @@ def ArticlePage(server, url):
|
||||||
|
|
||||||
# RSS
|
# RSS
|
||||||
|
|
||||||
|
rsslink = "https://"+config.get("domain", "")+"/rss"
|
||||||
|
authorrsslink = rsslink+"?author="+Articles.get(article, {}).get("author","")
|
||||||
|
|
||||||
html = html + """
|
html = html + """
|
||||||
|
|
||||||
<div class="dark_box">
|
<div class="dark_box">
|
||||||
<center>
|
<center>
|
||||||
|
|
||||||
"""+ Button("Subscribe RSS", "/rss", "rss") +"""
|
<details>
|
||||||
|
<summary class="button">
|
||||||
|
|
||||||
|
<img style="vertical-align: middle" src="/icon/rss">
|
||||||
|
Subscribe RSS
|
||||||
|
|
||||||
|
</summary>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<img style="vertical-align: middle" src="/icon/user">
|
||||||
|
<input class="button" style="width:50%" value='"""+authorrsslink+"""'>
|
||||||
|
"""+Button("Author", authorrsslink, "link")+"""
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<img style="vertical-align: middle" src="/icon/internet">
|
||||||
|
<input class="button" style="width:50%" value='"""+rsslink+"""'>
|
||||||
|
"""+Button("Website", rsslink, "link")+"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
</center>
|
</center>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1886,7 +1923,8 @@ def UpdatePublicationRights(server):
|
||||||
|
|
||||||
text = text + ".<br>"
|
text = text + ".<br>"
|
||||||
|
|
||||||
Notify(account, "/account/"+account, text)
|
if granted or revoked:
|
||||||
|
Notify(account, "/account/"+account, text)
|
||||||
|
|
||||||
def DoComment(server):
|
def DoComment(server):
|
||||||
|
|
||||||
|
@ -2264,26 +2302,40 @@ def RSS(server):
|
||||||
if favicon.startswith("/"):
|
if favicon.startswith("/"):
|
||||||
favicon = "https://"+config.get("domain", "example.com")+favicon
|
favicon = "https://"+config.get("domain", "example.com")+favicon
|
||||||
|
|
||||||
|
author = server.parsed.get("author", [""])[0]
|
||||||
|
|
||||||
|
title = config.get("title", "My Website")
|
||||||
|
if author:
|
||||||
|
|
||||||
|
Accounts = accounts()
|
||||||
|
account = Accounts.get(author, {})
|
||||||
|
|
||||||
|
title = account.get("title", author)+" at: "+title
|
||||||
|
|
||||||
rss = """
|
rss = """
|
||||||
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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/">
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||||
<channel>
|
<channel>
|
||||||
|
|
||||||
<title>"""+config.get("title", "My Website")+"""</title>
|
<title>"""+title+"""</title>
|
||||||
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
||||||
<description>"""+config.get("tagline", "")+"""</description>
|
<description>"""+config.get("tagline", "")+"""</description>
|
||||||
|
|
||||||
<image>
|
<image>
|
||||||
<url>"""+favicon+"""</url>
|
<url>"""+favicon+"""</url>
|
||||||
<title>"""+config.get("title", "My Website")+"""</title>
|
<title>"""+title+"""</title>
|
||||||
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
<link>https://"""+config.get("domain", "example.com")+"""</link>
|
||||||
</image>
|
</image>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
n = 0
|
||||||
|
for article in Articles:
|
||||||
|
|
||||||
for n, article in enumerate(Articles):
|
if author and author != Articles[article].get("author", ""):
|
||||||
|
continue
|
||||||
|
|
||||||
|
n += 1
|
||||||
if n > 10:
|
if n > 10:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -2310,3 +2362,214 @@ def RSS(server):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
send(server, rss, 200)
|
send(server, rss, 200)
|
||||||
|
|
||||||
|
|
||||||
|
def Search(server):
|
||||||
|
|
||||||
|
Articles = allArticles()
|
||||||
|
Tabs = tabs()
|
||||||
|
config = Set.Load()
|
||||||
|
|
||||||
|
# Generating <head>
|
||||||
|
html = head(title = "Search",
|
||||||
|
description = "",
|
||||||
|
config = config
|
||||||
|
)
|
||||||
|
|
||||||
|
html = html + Button(config.get("title", "My Website"), "/", image=config.get("favicon", "/icon/internet"))
|
||||||
|
|
||||||
|
|
||||||
|
# The place where you can type your search
|
||||||
|
|
||||||
|
text = server.parsed.get("text",[""])[0]
|
||||||
|
|
||||||
|
try: page = int(server.parsed.get("page", ["0"])[0])
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
page = 0
|
||||||
|
|
||||||
|
searchtitle = server.parsed.get("title",[""])[0]
|
||||||
|
searchauthor = server.parsed.get("author",[""])[0]
|
||||||
|
searchpost = server.parsed.get("post",[""])[0]
|
||||||
|
searchdescription = server.parsed.get("description",[""])[0]
|
||||||
|
searchcomments = server.parsed.get("comments",[""])[0]
|
||||||
|
|
||||||
|
# Supporting legacy search links
|
||||||
|
if not any([searchtitle,
|
||||||
|
searchauthor,
|
||||||
|
searchpost,
|
||||||
|
searchdescription,
|
||||||
|
searchcomments
|
||||||
|
]):
|
||||||
|
searchtitle = True
|
||||||
|
searchpost = True
|
||||||
|
searchdescription = True
|
||||||
|
searchcomments = True
|
||||||
|
|
||||||
|
|
||||||
|
checkedtitle = ""
|
||||||
|
if searchtitle: checkedtitle = " checked "
|
||||||
|
|
||||||
|
checkedauthor = ""
|
||||||
|
if searchauthor: checkedauthor = " checked "
|
||||||
|
|
||||||
|
checkedpost = ""
|
||||||
|
if searchpost: checkedpost = " checked "
|
||||||
|
|
||||||
|
checkeddescription = ""
|
||||||
|
if searchdescription: checkeddescription = " checked "
|
||||||
|
|
||||||
|
checkedcomments = ""
|
||||||
|
if searchcomments: checkedcomments = " checked "
|
||||||
|
|
||||||
|
html = html + """
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<form action="/search">
|
||||||
|
|
||||||
|
<div class="toot">
|
||||||
|
|
||||||
|
<input name="text" class="button" placeholder="Search..." value='"""+text+"""'>
|
||||||
|
|
||||||
|
<button class="button" type="submit">
|
||||||
|
<img style="vertical-align: middle" src="/icon/search">
|
||||||
|
Search
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div class="button">
|
||||||
|
<input type="checkbox" """+checkedtitle+""" name="title"> Title
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button">
|
||||||
|
<input type="checkbox" """+checkedauthor+""" name="author"> Author
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button">
|
||||||
|
<input type="checkbox" """+checkedpost+""" name="post"> Post Text
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button">
|
||||||
|
<input type="checkbox" """+checkeddescription+""" name="description"> Description
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button">
|
||||||
|
<input type="checkbox" """+checkedcomments+""" name="comments"> Comments
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
</center>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Acutally doing the searching
|
||||||
|
|
||||||
|
counted = []
|
||||||
|
|
||||||
|
for article in Articles:
|
||||||
|
|
||||||
|
points = 0
|
||||||
|
|
||||||
|
# Title x 100 points
|
||||||
|
if searchtitle:
|
||||||
|
title = Articles[article].get("title", article)
|
||||||
|
points += title.lower().count(text.lower()) * 100
|
||||||
|
|
||||||
|
# Description x 10 points
|
||||||
|
if searchdescription:
|
||||||
|
description = Articles[article].get("description", "")
|
||||||
|
points += description.lower().count(text.lower()) * 10
|
||||||
|
|
||||||
|
# Author
|
||||||
|
if searchauthor:
|
||||||
|
author = Articles[article].get("author", "")
|
||||||
|
if author == text:
|
||||||
|
points += 2 # Perfect match with username preffered
|
||||||
|
|
||||||
|
# People might also look at the username
|
||||||
|
Accounts = accounts()
|
||||||
|
if text.lower() == Accounts.get(author, {}).get("title", "").lower():
|
||||||
|
points += 1
|
||||||
|
|
||||||
|
# Comments x 1
|
||||||
|
if searchcomments:
|
||||||
|
comments = Articles[article].get("comments", {}).get("comments", {})
|
||||||
|
for comment in comments:
|
||||||
|
commentText = comment.get("text", "")
|
||||||
|
points += commentText.lower().count(text.lower())
|
||||||
|
|
||||||
|
# Post Text x 1
|
||||||
|
if searchpost:
|
||||||
|
try:
|
||||||
|
f = Set.Folder()
|
||||||
|
url = Articles[article].get("url")
|
||||||
|
postText = open(f+"/tabs/"+url+"/text.md").read()
|
||||||
|
points += postText.lower().count(text.lower())
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
if points:
|
||||||
|
counted.append([points, article])
|
||||||
|
|
||||||
|
counted = list(reversed(sorted(counted)))
|
||||||
|
|
||||||
|
Buffer = 16
|
||||||
|
From = Buffer*page
|
||||||
|
To = From+Buffer
|
||||||
|
|
||||||
|
urlNoPage = server.path
|
||||||
|
if "page=" in urlNoPage: urlNoPage = urlNoPage[:urlNoPage.rfind("&")]
|
||||||
|
|
||||||
|
if len(list(counted)) > Buffer:
|
||||||
|
if page > 0:
|
||||||
|
html = html + Button(str(page-1), urlNoPage+"&page="+str(page-1), "left")
|
||||||
|
|
||||||
|
html = html + '<div class="button">'+str(page)+'</div>'
|
||||||
|
|
||||||
|
if To < len(list(counted))-1:
|
||||||
|
html = html + Button(str(page+1), urlNoPage+"&page="+str(page+1), "right")
|
||||||
|
|
||||||
|
|
||||||
|
html = html + """
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Article previews are neatly positioned into a grid here -->
|
||||||
|
|
||||||
|
<div class="flexity">
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
rendered = 0
|
||||||
|
for n, article in enumerate(counted):
|
||||||
|
|
||||||
|
points, article = article
|
||||||
|
|
||||||
|
if n < From: continue
|
||||||
|
if n >= To: break
|
||||||
|
|
||||||
|
html = html + ArticlePreview(Articles[article], Tabs, server.cookie)
|
||||||
|
rendered += 1
|
||||||
|
|
||||||
|
|
||||||
|
html = html + '</div><br>'
|
||||||
|
|
||||||
|
if len(list(counted)) > Buffer:
|
||||||
|
if page > 0:
|
||||||
|
html = html + Button(str(page-1), urlNoPage+"&page="+str(page-1), "left")
|
||||||
|
|
||||||
|
html = html + '<div class="button">'+str(page)+'</div>'
|
||||||
|
|
||||||
|
if To < len(list(counted))-1:
|
||||||
|
html = html + Button(str(page+1), urlNoPage+"&page="+str(page+1), "right")
|
||||||
|
|
||||||
|
|
||||||
|
html = html + LoginButton(server)
|
||||||
|
|
||||||
|
send(server, html, 200)
|
||||||
|
|
|
@ -187,13 +187,16 @@ class handler(BaseHTTPRequestHandler):
|
||||||
elif self.path[1:].startswith("read_notification"):
|
elif self.path[1:].startswith("read_notification"):
|
||||||
Render.ReadNotification(self)
|
Render.ReadNotification(self)
|
||||||
|
|
||||||
|
elif self.path[1:].startswith("search"):
|
||||||
|
Render.Search(self)
|
||||||
|
|
||||||
|
|
||||||
elif self.path.startswith("/graph/"):
|
elif self.path.startswith("/graph/"):
|
||||||
url = self.path[6:]
|
url = self.path[6:]
|
||||||
if "?" in url: url = url[:url.find("?")]
|
if "?" in url: url = url[:url.find("?")]
|
||||||
Render.Graph(self, url)
|
Render.Graph(self, url)
|
||||||
|
|
||||||
elif self.path == "/rss":
|
elif self.path.startswith("/rss"):
|
||||||
Render.RSS(self)
|
Render.RSS(self)
|
||||||
|
|
||||||
elif self.path.startswith("/pictures/"):
|
elif self.path.startswith("/pictures/"):
|
||||||
|
|
Loading…
Add table
Reference in a new issue