X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=html_generator.py;h=c16f033552cb80094befa995b04645fa1d612ba6;hb=d443dffc599f0f858068bd22dcf289fcbe4d64f3;hp=de1265c147863589494b39148bdb929ad454d49d;hpb=a6bcc3600c1b2e66757f18e6c4572987897088fb;p=turbot-web
diff --git a/html_generator.py b/html_generator.py
index de1265c..c16f033 100644
--- a/html_generator.py
+++ b/html_generator.py
@@ -16,10 +16,16 @@ Requires sorttable.js, which should be included
"""
import boto3
from boto3.dynamodb.conditions import Key
+import re
website = "https://halibut.cworth.org/"
#change this if we're using AWS or some other subdomain instead
+def filename_from_name(name):
+ """Returns a string derived from name, but with all spaces and slashes
+ replaced with underscores, (for making a clean filename)"""
+ return re.sub(r'[ /]', '_', name)
+
def channel_url(channel_id):
"""Given a channel ID, return the URL for that channel."""
@@ -166,7 +172,7 @@ def overview(puzzles, rounds):
expanding += [
'
\n'.format(i, status),
'
x\n',
- '
{}
\n'.format(link(website + "_".join(rnd.split()) + "_round.html", rnd)),
+ '
{}
\n'.format(link(website + filename_from_name(rnd) + "_round.html", rnd)),
'
\n',
' \n',
' Puzzle | \n',
@@ -180,12 +186,12 @@ def overview(puzzles, rounds):
meta = ''
if puzzle['status'] == 'solved':
expanding += ['
\n',
- ' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + ".html", puzzle['name']+meta)),
+ ' {} | \n'.format(link(website + filename_from_name(puzzle['name']) + ".html", puzzle['name']+meta)),
' {} | \n'.format(puzzle['solution']),
'
\n']
else:
expanding += [' \n',
- ' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + ".html", puzzle['name']+meta)),
+ ' {} | \n'.format(link(website + filename_from_name(puzzle['name']) + ".html", puzzle['name']+meta)),
' | \n',
'
\n']
expanding.append('
\n')
@@ -245,22 +251,22 @@ def round_overview(rnd, puzzles):
if puzzle['status'] == 'solved':
puzzle_list += [ '
\n',
' {} | \n'.format(elink(slack_url, puzzle['name']+meta)),
- ' {} | \n'.format(elink(puzzle['url'], 'Puzzle')),
+ ' {} | \n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' {} | \n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' {} | \n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' {} | \n'.format(puzzle['solution']),
# ' | \n',
- ' {} | \n'.format("".join(puzzle['tags'])),
+ ' {} | \n'.format("".join(puzzle.get('tags',[]))),
'
\n']
else:
puzzle_list += [ '
\n',
' {} | \n'.format(elink(slack_url, puzzle['name']+meta)),
- ' {} | \n'.format(elink(puzzle['url'], 'Puzzle')),
+ ' {} | \n'.format(elink(puzzle.get('url',''), 'Puzzle')),
' {} | \n'.format(elink(puzzle['sheet_url'], 'Sheet')),
- ' {} | \n'.format(link(website + "_".join(puzzle['name'].split()) + '.html', 'Overview')),
+ ' {} | \n'.format(link(website + filename_from_name(puzzle['name']) + '.html', 'Overview')),
' | \n',
# ' | \n',
- ' {} | \n'.format(" ".join(puzzle['tags'])),
+ ' {} | \n'.format(" ".join(puzzle.get('tags',[]))),
'
\n']
end = [' \n',
' \n',
@@ -268,7 +274,7 @@ def round_overview(rnd, puzzles):
'