@@ -1886,7 +1923,8 @@ def UpdatePublicationRights(server):
text = text + ". "
- Notify(account, "/account/"+account, text)
+ if granted or revoked:
+ Notify(account, "/account/"+account, text)
def DoComment(server):
@@ -2263,27 +2301,41 @@ def RSS(server):
favicon = config.get("favicon", "")
if favicon.startswith("/"):
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 = """
- """+config.get("title", "My Website")+"""
+ """+title+"""
https://"""+config.get("domain", "example.com")+"""
"""+config.get("tagline", "")+""""""+favicon+"""
- """+config.get("title", "My Website")+"""
+ """+title+"""
https://"""+config.get("domain", "example.com")+"""
"""
-
- for n, article in enumerate(Articles):
+ n = 0
+ for article in Articles:
+ if author and author != Articles[article].get("author", ""):
+ continue
+
+ n += 1
if n > 10:
break
@@ -2310,3 +2362,214 @@ def RSS(server):
"""
send(server, rss, 200)
+
+
+def Search(server):
+
+ Articles = allArticles()
+ Tabs = tabs()
+ config = Set.Load()
+
+ # Generating
+ 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 + """
+
+
+
+
+ """
+
+ # 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 + '
'+str(page)+'
'
+
+ if To < len(list(counted))-1:
+ html = html + Button(str(page+1), urlNoPage+"&page="+str(page+1), "right")
+
+
+ html = html + """
+
+
+
+
+
+
+
+ """
+
+
+ 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 + '
'
+
+ if len(list(counted)) > Buffer:
+ if page > 0:
+ html = html + Button(str(page-1), urlNoPage+"&page="+str(page-1), "left")
+
+ html = html + '
'+str(page)+'
'
+
+ 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)
diff --git a/modules/Run.py b/modules/Run.py
index 9beb367..23610cf 100644
--- a/modules/Run.py
+++ b/modules/Run.py
@@ -186,6 +186,9 @@ class handler(BaseHTTPRequestHandler):
elif self.path[1:].startswith("read_notification"):
Render.ReadNotification(self)
+
+ elif self.path[1:].startswith("search"):
+ Render.Search(self)
elif self.path.startswith("/graph/"):
@@ -193,7 +196,7 @@ class handler(BaseHTTPRequestHandler):
if "?" in url: url = url[:url.find("?")]
Render.Graph(self, url)
- elif self.path == "/rss":
+ elif self.path.startswith("/rss"):
Render.RSS(self)
elif self.path.startswith("/pictures/"):