Procházet zdrojové kódy

More style updates and crosslinks

master
JustAnotherArchivist před 3 roky
rodič
revize
f50aa7f0d8
1 změnil soubory, kde provedl 35 přidání a 8 odebrání
  1. +35
    -8
      irclog.py

+ 35
- 8
irclog.py Zobrazit soubor

@@ -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_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; }', 'tr.command_NOTICE td:nth-child(3) { font-style: italic; }',
]) + '</style>' ]) + '</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): def __init__(self, config):
self.config = config self.config = config
@@ -889,11 +893,23 @@ class WebServer:


async def get_channel_info(self, request): async def get_channel_info(self, request):
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.path!r}') 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( return aiohttp.web.Response(
text = ''.join([ text = ''.join([
'<!DOCTYPE html><html lang="en">', '<!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>' '</html>'
]), ]),
content_type = 'text/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) date = datetime.datetime.strptime(request.match_info['date'], '%Y-%m-%d').replace(tzinfo = datetime.timezone.utc)
dateStart = date.timestamp() dateStart = date.timestamp()
dateEnd = (date + datetime.timedelta(days = 1)).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"])}/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")}">Previous day</a>',
f'<a href="/{html.escape(request.match_info["path"])}/{(date + datetime.timedelta(days = 1)).strftime("%Y-%m-%d")}">Next 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... #TODO Implement this in a better way...
fn = date.strftime('%Y-%m.log') 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)) 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( return aiohttp.web.Response(
text = ''.join([ text = ''.join([
'<!DOCTYPE html><html lang="en">', '<!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>', '<body>',
f'<p>{channelLinks}</p>',
channelLinks,
'<hr />', '<hr />',
self._render_log(lines), self._render_log(lines),
'<hr />', '<hr />',
f'<p>{channelLinks}</p>',
channelLinks,
'</body>', '</body>',
'</html>', '</html>',
]), ]),
@@ -995,6 +1012,12 @@ class WebServer:
if self._paths[request.match_info['path']][2]: # Hidden channels aren't searchable if self._paths[request.match_info['path']][2]: # Hidden channels aren't searchable
return aiohttp.web.HTTPNotFound() 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([ searchForm = ''.join([
'<form>', '<form>',
'<input name="q" ', f'value="{html.escape(request.query["q"])}" ' if 'q' in request.query else '', '/>', '<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( return aiohttp.web.Response(
text = ''.join([ text = ''.join([
'<!DOCTYPE html><html lang="en">' '<!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>', '<body>',
linkBar,
searchForm, searchForm,
'</body>', '</body>',
'</html>' '</html>'
@@ -1093,13 +1117,16 @@ class WebServer:
'<!DOCTYPE html><html lang="en">', '<!DOCTYPE html><html lang="en">',
'<head>', '<head>',
f'<title>{html.escape(self._paths[request.match_info["path"]][0])} search results for "{html.escape(request.query["q"])}"</title>', f'<title>{html.escape(self._paths[request.match_info["path"]][0])} search results for "{html.escape(request.query["q"])}"</title>',
self.generalStyleTag,
self.logStyleTag, self.logStyleTag,
'<style>#incomplete { background-color: #FF6666; padding: 10px; }</style>', '<style>#incomplete { background-color: #FF6666; padding: 10px; }</style>',
'</head>', '</head>',
'<body>', '<body>',
linkBar,
searchForm, searchForm,
'<p id="incomplete">Warning: output incomplete due to exceeding time or size limits</p>' if incomplete else '', '<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.', self._render_log(lines, withDate = True) or 'No results.',
linkBar,
'</body>', '</body>',
'</html>' '</html>'
]), ]),


Načítá se…
Zrušit
Uložit