diff --git a/generator.py b/generator.py index c919fac..87dd68d 100755 --- a/generator.py +++ b/generator.py @@ -15,8 +15,11 @@ from jinja2 import Environment, FileSystemLoader def fromunixtime(value): return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S') +def url_replacer(value): + return value.replace('/', '_').replace(' ', '_').replace('?', '').replace('<', '').replace('>', '') + def user_replacer(match): - return '[url=../../user/' + match.group(2).replace('/', '_').replace(' ', '_').replace('?', '') + '.html]' + match.group(2) + '[/url]' + return '[url=../../user/' +url_replacer(match.group(2)) + '.html]' + match.group(2) + '[/url]' def tohtml(value): value = value.replace('{{baseurl}}', 'static') @@ -68,11 +71,11 @@ def find_unregistered_users(data): def render_boards(boards, template_board, template_thread, outpath, title): for board in boards: rendered_board = template_board.render(board=board, title=title + ' - ' + board['title']) - write_render(rendered_board, os.path.join('board', board['title'].replace('/', '_').replace(' ', '_').replace('?', '') + '.html'), outpath) + write_render(rendered_board, os.path.join('board', url_replacer(board['title']) + '.html'), outpath) for thread in board['threads']: rendered_thread = template_thread.render(thread=thread, title=title + ' - ' + thread['title']) - write_render(rendered_thread, os.path.join('board', 'thread', thread['title'].replace('/', '_').replace(' ', '_').replace('?', '') + '.html'), outpath) + write_render(rendered_thread, os.path.join('board', 'thread', url_replacer(thread['title']) + '.html'), outpath) render_boards(board['boards'], template_board, template_thread, outpath, title) @@ -87,6 +90,7 @@ def render(inputfile, staticpath, outpath, title): env = Environment(loader=FileSystemLoader('./templates')) env.filters['fromunixtime'] = fromunixtime env.filters['tohtml'] = tohtml + env.filters['url_replacer'] = url_replacer template_users = env.get_template('users.html.j2') template_user = env.get_template('user.html.j2') @@ -105,7 +109,7 @@ def render(inputfile, staticpath, outpath, title): for user in data['users']: rendered_user = template_user.render(user=user, title=title + ' - ' + user['name']) - write_render(rendered_user, os.path.join('user', user['name'].replace('/', '_').replace(' ', '_').replace('?', '') + '.html'), outpath) + write_render(rendered_user, os.path.join('user', url_replacer(user['name']) + '.html'), outpath) render_boards(data['boards'], template_board, template_thread, outpath, title) diff --git a/templates/board.html.j2 b/templates/board.html.j2 index d9f105d..7a93291 100644 --- a/templates/board.html.j2 +++ b/templates/board.html.j2 @@ -10,14 +10,14 @@ {% if board.boards |length > 0 %}
{{ post.message | tohtml }}
{% for attachment in post.attachments %} --