generate unique board identifiers...
This commit is contained in:
parent
73e1b58923
commit
fcdb33f6c0
11
generator.py
11
generator.py
@ -12,9 +12,6 @@ import argparse, json, os, re, shutil
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
import sys
|
|
||||||
#reload(sys); sys.setdefaultencoding('utf-8')
|
|
||||||
|
|
||||||
def fromunixtime(value):
|
def fromunixtime(value):
|
||||||
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
|
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
@ -71,14 +68,17 @@ def find_unregistered_users(data):
|
|||||||
|
|
||||||
return unregistered_users
|
return unregistered_users
|
||||||
|
|
||||||
|
def find_board_id(board):
|
||||||
|
return board['link'].split('/')[-2]
|
||||||
|
|
||||||
def render_boards(boards, template_board, template_thread, outpath, title):
|
def render_boards(boards, template_board, template_thread, outpath, title):
|
||||||
for board in boards:
|
for board in boards:
|
||||||
rendered_board = template_board.render(board=board, title=title + ' - ' + board['title'])
|
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']:
|
for thread in board['threads']:
|
||||||
rendered_thread = template_thread.render(board=board, thread=thread, title=title + ' - ' + thread['title'])
|
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)
|
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['fromunixtime'] = fromunixtime
|
||||||
env.filters['tohtml'] = tohtml
|
env.filters['tohtml'] = tohtml
|
||||||
env.filters['url_replacer'] = url_replacer
|
env.filters['url_replacer'] = url_replacer
|
||||||
|
env.filters['find_board_id'] = find_board_id
|
||||||
|
|
||||||
template_users = env.get_template('users.html.j2')
|
template_users = env.get_template('users.html.j2')
|
||||||
template_user = env.get_template('user.html.j2')
|
template_user = env.get_template('user.html.j2')
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
{% if board.boards |length > 0 %}
|
{% if board.boards |length > 0 %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for board in board.boards %}
|
{% for board in board.boards %}
|
||||||
<li><a href={{ "../board/" + board.title |url_replacer + ".html" }}>{{ board.title }}</a></li>
|
<li><a href={{ "../board/" + board |find_board_id + '_' + board.title |url_replacer + ".html" }}>{{ board.title }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for thread in board.threads %}
|
{% for thread in board.threads %}
|
||||||
<li><a href={{ "thread/" + thread.title |url_replacer + ".html" }}>{{ thread.title }}</a></li>
|
<li><a href={{ "thread/" + thread.id + '_' + thread.title |url_replacer + ".html" }}>{{ thread.title }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
|
@ -8,13 +8,14 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="index.html">Home</a></li>
|
||||||
<li><a href="users.html">Users</a></li>
|
<li><a href="users.html">Users</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
<ul>
|
<ul>
|
||||||
{% for board in boards %}
|
{% for board in boards %}
|
||||||
<li>
|
<li>
|
||||||
<a href={{ "board/" + board.title |url_replacer + ".html" }}>{{ board.title }}</a><br>
|
<a href={{ "board/" + board |find_board_id + '_' + board.title |url_replacer + ".html" }}>{{ board.title }}</a><br>
|
||||||
<i>{{ board.description }}</i>
|
<i>{{ board.description }}</i>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href={{ "../" + board.title |url_replacer + ".html" }}>{{ board.title }}</a></li>
|
<li><a href={{ "../" + board |find_board_id + '_' + board.title |url_replacer + ".html" }}>{{ board.title }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
<h1>{{ thread.title }}</h1>
|
<h1>{{ thread.title }}</h1>
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="index.html">Home</a></li>
|
||||||
<li><a href="boards.html">Boards</a></li>
|
<li><a href="boards.html">Boards</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<hr>
|
<hr>
|
||||||
|
Loading…
Reference in New Issue
Block a user