Show hashtag gategory from search screen

main
Bob Mottram 2020-12-02 21:46:14 +00:00
parent dd796e84ae
commit 4a8ceda973
3 changed files with 57 additions and 1 deletions

View File

@ -165,6 +165,7 @@ from webapp_search import htmlSearchSharedItems
from webapp_search import htmlSearchEmojiTextEntry from webapp_search import htmlSearchEmojiTextEntry
from webapp_search import htmlSearch from webapp_search import htmlSearch
from webapp_hashtagswarm import getHashtagCategoriesFeed from webapp_hashtagswarm import getHashtagCategoriesFeed
from webapp_hashtagswarm import htmlSearchHashtagCategory
from shares import getSharesFeedForPerson from shares import getSharesFeedForPerson
from shares import addShare from shares import addShare
from shares import removeShare from shares import removeShare
@ -10141,6 +10142,23 @@ class PubServer(BaseHTTPRequestHandler):
'search screen shown') 'search screen shown')
return return
# show a hashtag category from the search screen
if htmlGET and '/category/' in self.path:
msg = htmlSearchHashtagCategory(self.server.cssCache,
self.server.translate,
self.server.baseDir, self.path,
self.server.domain,
self.server.defaultTimeline)
if msg:
msg = msg.encode('utf-8')
self._set_headers('text/html', len(msg), cookie, callingDomain)
self._write(msg)
self.server.GETbusy = False
self._benchmarkGETtimings(GETstartTime, GETtimings,
'hashtag category done',
'hashtag category screen shown')
return
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
'hashtag search done', 'hashtag search done',
'search screen shown done') 'search screen shown done')

View File

@ -1083,7 +1083,7 @@ def validNickname(domain: str, nickname: str) -> bool:
if nickname == domain: if nickname == domain:
return False return False
reservedNames = ('inbox', 'dm', 'outbox', 'following', reservedNames = ('inbox', 'dm', 'outbox', 'following',
'public', 'followers', 'public', 'followers', 'category',
'channel', 'calendar', 'channel', 'calendar',
'tlreplies', 'tlmedia', 'tlblogs', 'tlreplies', 'tlmedia', 'tlblogs',
'tlevents', 'tlblogs', 'tlfeatures', 'tlevents', 'tlblogs', 'tlfeatures',

View File

@ -7,10 +7,14 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
from shutil import copyfile
from datetime import datetime from datetime import datetime
# from utils import getNicknameFromActor
from utils import getHashtagCategories from utils import getHashtagCategories
from utils import getHashtagCategory from utils import getHashtagCategory
from webapp_utils import getContentWarningButton from webapp_utils import getContentWarningButton
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter
def getHashtagCategoriesFeed(baseDir: str, def getHashtagCategoriesFeed(baseDir: str,
@ -220,3 +224,37 @@ def htmlHashTagSwarm(baseDir: str, actor: str, translate: {}) -> str:
tagSwarmHtml = categorySwarmStr + tagSwarmStr.strip() + '\n' tagSwarmHtml = categorySwarmStr + tagSwarmStr.strip() + '\n'
# tagSwarmHtml += getHashtagDomainHistogram(domainHistogram, translate) # tagSwarmHtml += getHashtagDomainHistogram(domainHistogram, translate)
return tagSwarmHtml return tagSwarmHtml
def htmlSearchHashtagCategory(cssCache: {}, translate: {},
baseDir: str, path: str, domain: str) -> str:
"""Show hashtags after selecting a category on the main search screen
"""
actor = path.split('/category/')[0]
categoryStr = path.split('/category/')[1].strip()
# searchNickname = getNicknameFromActor(actor)
if os.path.isfile(baseDir + '/img/search-background.png'):
if not os.path.isfile(baseDir + '/accounts/search-background.png'):
copyfile(baseDir + '/img/search-background.png',
baseDir + '/accounts/search-background.png')
cssFilename = baseDir + '/epicyon-search.css'
if os.path.isfile(baseDir + '/search.css'):
cssFilename = baseDir + '/search.css'
htmlStr = htmlHeaderWithExternalStyle(cssFilename)
htmlStr += '<h1><a href="/search">' + categoryStr + '</a></h1>'
hashtagsDict = getHashtagCategories(baseDir, categoryStr)
if hashtagsDict:
for categoryStr2, hashtagList in hashtagsDict.items():
hashtagList.sort()
for tagName in hashtagList:
htmlStr += \
'<a href="' + actor + '/tags/' + tagName + \
'" class="hashtagswarm">' + tagName + '</a>\n'
htmlStr += htmlFooter()
return htmlStr