From fcdb33f6c000e1409216346c189d963127a35c78 Mon Sep 17 00:00:00 2001
From: Sebastian Hugentobler
Date: Mon, 18 May 2015 17:55:38 +0200
Subject: [PATCH] generate unique board identifiers...
---
generator.py | 11 ++++++-----
templates/board.html.j2 | 4 ++--
templates/boards.html.j2 | 3 ++-
templates/thread.html.j2 | 2 +-
templates/users.html.j2 | 1 +
5 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/generator.py b/generator.py
index fd2dcc4..1301957 100755
--- a/generator.py
+++ b/generator.py
@@ -12,9 +12,6 @@ import argparse, json, os, re, shutil
from datetime import datetime
from jinja2 import Environment, FileSystemLoader
-import sys
-#reload(sys); sys.setdefaultencoding('utf-8')
-
def fromunixtime(value):
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
@@ -71,14 +68,17 @@ def find_unregistered_users(data):
return unregistered_users
+def find_board_id(board):
+ return board['link'].split('/')[-2]
+
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', url_replacer(board['title']) + '.html'), outpath)
+ write_render(rendered_board, os.path.join('board', find_board_id(board) + '_' + url_replacer(board['title']) + '.html'), outpath)
for thread in board['threads']:
rendered_thread = template_thread.render(board=board, thread=thread, title=title + ' - ' + thread['title'])
- write_render(rendered_thread, os.path.join('board', 'thread', url_replacer(thread['title']) + '.html'), outpath)
+ write_render(rendered_thread, os.path.join('board', 'thread', thread['id'] + '_' + url_replacer(thread['title']) + '.html'), outpath)
render_boards(board['boards'], template_board, template_thread, outpath, title)
@@ -94,6 +94,7 @@ def render(inputfile, staticpath, outpath, title):
env.filters['fromunixtime'] = fromunixtime
env.filters['tohtml'] = tohtml
env.filters['url_replacer'] = url_replacer
+ env.filters['find_board_id'] = find_board_id
template_users = env.get_template('users.html.j2')
template_user = env.get_template('user.html.j2')
diff --git a/templates/board.html.j2 b/templates/board.html.j2
index b279fc9..f7bc752 100644
--- a/templates/board.html.j2
+++ b/templates/board.html.j2
@@ -14,14 +14,14 @@
{% if board.boards |length > 0 %}
{% endif %}
{% for board in boards %}
-
- {{ board.title }}
+ {{ board.title }}
{{ board.description }}
{% endfor %}
diff --git a/templates/thread.html.j2 b/templates/thread.html.j2
index 5382ad9..e339678 100644
--- a/templates/thread.html.j2
+++ b/templates/thread.html.j2
@@ -8,7 +8,7 @@
{{ thread.title }}
diff --git a/templates/users.html.j2 b/templates/users.html.j2
index 44706e5..55c4b6c 100644
--- a/templates/users.html.j2
+++ b/templates/users.html.j2
@@ -8,6 +8,7 @@