Browse Source

More style updates and crosslinks

master
JustAnotherArchivist 3 years ago
parent
commit
f50aa7f0d8
1 changed files with 35 additions and 8 deletions
  1. +35
    -8
      irclog.py

+ 35
- 8
irclog.py View File

@@ -817,6 +817,10 @@ class WebServer:
'tr.command_NICK, tr.command_ACCOUNT, tr.command_MODE, tr.command_TOPIC, tr.command_TOPICWHO, tr.command_WHOX { color: grey; }',
'tr.command_NOTICE td:nth-child(3) { font-style: italic; }',
]) + '</style>'
generalStyleTag = '<style>' + ' '.join([
'.linkbar a { padding: 4px; border-right: black solid 1px; }',
'.linkbar a:last-of-type { border-right: none; }',
]) + '</style>'

def __init__(self, config):
self.config = config
@@ -889,11 +893,23 @@ class WebServer:

async def get_channel_info(self, request):
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.path!r}')
description = html.escape(self._paths[request.match_info["path"]][4]) if self._paths[request.match_info["path"]][4] else '<span style="font-style: italic">(not available)</span>'
return aiohttp.web.Response(
text = ''.join([
'<!DOCTYPE html><html lang="en">',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])}</title></head>',
f'<body>{html.escape(self._paths[request.match_info["path"]][4] or "")}</body>',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])}</title>{self.generalStyleTag}</head>',
'<body>',
'<p class="linkbar">',
'<a href="/">Home</a>',
f'<a href="/{html.escape(request.match_info["path"])}/today">Today&#x27;s log</a>',
f'<a href="/{html.escape(request.match_info["path"])}/search">Search</a>',
'</p>',
'<hr />',
'<p>',
f'<span style="font-weight: bold">Channel:</span> {html.escape(self._paths[request.match_info["path"]][0])}<br />',
f'<span style="font-weight: bold">Description:</span> {description}',
'</p>',
'</body>',
'</html>'
]),
content_type = 'text/html'
@@ -965,24 +981,25 @@ class WebServer:
date = datetime.datetime.strptime(request.match_info['date'], '%Y-%m-%d').replace(tzinfo = datetime.timezone.utc)
dateStart = date.timestamp()
dateEnd = (date + datetime.timedelta(days = 1)).timestamp()
channelLinks = ' '.join([
channelLinks = '<p class="linkbar">' + ''.join([
'<a href="/">Home</a>',
f'<a href="/{html.escape(request.match_info["path"])}/search">Search</a>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date - datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Previous day</a>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next day</a>',
])
]) + '</p>'
#TODO Implement this in a better way...
fn = date.strftime('%Y-%m.log')
lines = list(self._raw_to_lines(self._file_iter_with_path(os.path.join(self.config['storage']['path'], request.match_info["path"], fn), request.match_info["path"]), filter = lambda path, ts, command, content: dateStart <= ts <= dateEnd))
return aiohttp.web.Response(
text = ''.join([
'<!DOCTYPE html><html lang="en">',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])} log for {date:%Y-%m-%d}</title>{self.logStyleTag}</head>',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])} log for {date:%Y-%m-%d}</title>{self.generalStyleTag}{self.logStyleTag}</head>',
'<body>',
f'<p>{channelLinks}</p>',
channelLinks,
'<hr />',
self._render_log(lines),
'<hr />',
f'<p>{channelLinks}</p>',
channelLinks,
'</body>',
'</html>',
]),
@@ -995,6 +1012,12 @@ class WebServer:
if self._paths[request.match_info['path']][2]: # Hidden channels aren't searchable
return aiohttp.web.HTTPNotFound()

linkBar = ''.join([
'<p class="linkbar">',
'<a href="/">Home</a>',
f'<a href="/{html.escape(request.match_info["path"])}/today">Today&#x27;s log</a>',
'</p>',
])
searchForm = ''.join([
'<form>',
'<input name="q" ', f'value="{html.escape(request.query["q"])}" ' if 'q' in request.query else '', '/>',
@@ -1006,8 +1029,9 @@ class WebServer:
return aiohttp.web.Response(
text = ''.join([
'<!DOCTYPE html><html lang="en">'
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])} search</title></head>',
f'<head><title>{html.escape(self._paths[request.match_info["path"]][0])} search</title>{self.generalStyleTag}</head>',
'<body>',
linkBar,
searchForm,
'</body>',
'</html>'
@@ -1093,13 +1117,16 @@ class WebServer:
'<!DOCTYPE html><html lang="en">',
'<head>',
f'<title>{html.escape(self._paths[request.match_info["path"]][0])} search results for "{html.escape(request.query["q"])}"</title>',
self.generalStyleTag,
self.logStyleTag,
'<style>#incomplete { background-color: #FF6666; padding: 10px; }</style>',
'</head>',
'<body>',
linkBar,
searchForm,
'<p id="incomplete">Warning: output incomplete due to exceeding time or size limits</p>' if incomplete else '',
self._render_log(lines, withDate = True) or 'No results.',
linkBar,
'</body>',
'</html>'
]),


Loading…
Cancel
Save