diff --git a/blog.py b/blog.py index 4fdebfd7..86050c75 100644 --- a/blog.py +++ b/blog.py @@ -28,7 +28,26 @@ from utils import getDomainFromActor from posts import createBlogsTimeline -def htmlBlogPostContent(baseDir: str,httpPrefix: str,translate: {}, \ +def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \ + nickname: str,domain: str,domainFull: str, \ + postJsonObject: {}) -> int: + """Returns the number of replies on the post + """ + if not postJsonObject['object'].get('id'): + return 0 + postFilename= \ + baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs/'+ \ + postJsonObject['object']['id'].replace('/','#')+'.replies' + if not os.path.isfile(postFilename): + return 0 + with open(postFilename, "r") as f: + lines = f.readlines() + return len(lines) + return 0 + + +def htmlBlogPostContent(authorized: bool, \ + baseDir: str,httpPrefix: str,translate: {}, \ nickname: str,domain: str,domainFull: str, \ postJsonObject: {}, \ handle: str,restrictToDomain: bool) -> str: @@ -104,14 +123,26 @@ def htmlBlogPostContent(baseDir: str,httpPrefix: str,translate: {}, \ blogStr+='
'+contentStr+'\n' blogStr+='

\n' + + #if not authorized: + replies= \ + noOfBlogReplies(baseDir,httpPrefix,translate, \ + nickname,domain,domainFull, \ + postJsonObject) + if replies>0: + blogStr+= \ + '

'+str(replies)+' '+ \ + translate['Replies'].lower()+'

' + if not linkedAuthor: blogStr+= \ - '

'+translate['About the author']+'

\n' return blogStr -def htmlBlogPost(baseDir: str,httpPrefix: str,translate: {}, \ +def htmlBlogPost(authorized: bool, \ + baseDir: str,httpPrefix: str,translate: {}, \ nickname: str,domain: str,domainFull: str, \ postJsonObject: {}) -> str: """Returns a html blog post @@ -126,15 +157,14 @@ def htmlBlogPost(baseDir: str,httpPrefix: str,translate: {}, \ blogStr=htmlHeader(cssFilename,blogCSS) blogStr+= \ - htmlBlogPostContent(baseDir,httpPrefix,translate, \ + htmlBlogPostContent(authorized,baseDir,httpPrefix,translate, \ nickname,domain,domainFull,postJsonObject, \ None,False) - + return blogStr+htmlFooter() return None - -def htmlBlogPage(session, \ +def htmlBlogPage(authorized: bool, session, \ baseDir: str,httpPrefix: str,translate: {}, \ nickname: str,domain: str,port: int, \ noOfItems: int,pageNumber: int) -> str: @@ -194,7 +224,7 @@ def htmlBlogPage(session, \ continue blogStr+= \ - htmlBlogPostContent(baseDir,httpPrefix,translate, \ + htmlBlogPostContent(authorized,baseDir,httpPrefix,translate, \ nickname,domain,domainFull,item, \ None,True) @@ -253,7 +283,8 @@ def singleBlogAccountNickname(baseDir: str) -> str: return acct.split('@')[0] return None -def htmlBlogView(session,baseDir: str,httpPrefix: str, \ +def htmlBlogView(authorized: bool, \ + session,baseDir: str,httpPrefix: str, \ translate: {},domain: str,port: int, \ noOfItems: int) -> str: """Show the blog main page @@ -270,7 +301,7 @@ def htmlBlogView(session,baseDir: str,httpPrefix: str, \ if noOfBlogAccounts(baseDir) <= 1: nickname=singleBlogAccountNickname(baseDir) if nickname: - return htmlBlogPage(session, \ + return htmlBlogPage(authorized,session, \ baseDir,httpPrefix,translate, \ nickname,domain,port, \ noOfItems,1) diff --git a/daemon.py b/daemon.py index c4f5a49e..36a200a4 100644 --- a/daemon.py +++ b/daemon.py @@ -1005,7 +1005,8 @@ class PubServer(BaseHTTPRequestHandler): if not self.server.session: self.server.session= \ createSession(self.server.useTor) - msg=htmlBlogView(self.server.session, \ + msg=htmlBlogView(authorized, \ + self.server.session, \ self.server.baseDir, \ self.server.httpPrefix, \ self.server.translate, \ @@ -1041,7 +1042,8 @@ class PubServer(BaseHTTPRequestHandler): if not self.server.session: self.server.session= \ createSession(self.server.useTor) - msg=htmlBlogPage(self.server.session, \ + msg=htmlBlogPage(authorized, \ + self.server.session, \ self.server.baseDir, \ self.server.httpPrefix, \ self.server.translate, \ @@ -1111,7 +1113,8 @@ class PubServer(BaseHTTPRequestHandler): if blogFilename and nickname: postJsonObject=loadJson(blogFilename) if isBlogPost(postJsonObject): - msg=htmlBlogPost(self.server.baseDir, \ + msg=htmlBlogPost(authorized, \ + self.server.baseDir, \ self.server.httpPrefix, \ self.server.translate, \ nickname,self.server.domain, \ diff --git a/epicyon-blog.css b/epicyon-blog.css index 3516c652..a464ada5 100644 --- a/epicyon-blog.css +++ b/epicyon-blog.css @@ -84,6 +84,12 @@ H3 { float: right; } +.blogreplies { + color: var(--button-highlighted); + font-size: var(--font-size5); + float: right; +} + img { border-radius: 5%; }