diff --git a/.gitignore b/.gitignore index 255468d..8016b0b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ include/ lib/ static/ board.json +pip-selfcheck.json diff --git a/generator.py b/generator.py index 90cbe5b..c919fac 100755 --- a/generator.py +++ b/generator.py @@ -65,18 +65,18 @@ def find_unregistered_users(data): return unregistered_users -def render_boards(boards, template_board, template_thread, outpath): +def render_boards(boards, template_board, template_thread, outpath, title): for board in boards: - rendered_board = template_board.render(board=board) + 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) for thread in board['threads']: - rendered_thread = template_thread.render(thread=thread) + 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) - render_boards(board['boards'], template_board, template_thread, outpath) + render_boards(board['boards'], template_board, template_thread, outpath, title) -def render(inputfile, staticpath, outpath): +def render(inputfile, staticpath, outpath, title): with open(inputfile) as data_file: data = json.load(data_file) @@ -94,8 +94,8 @@ def render(inputfile, staticpath, outpath): template_board = env.get_template('board.html.j2') template_thread = env.get_template('thread.html.j2') - rendered_users = template_users.render(users=data['users']) - rendered_boards = template_boards.render(boards=data['boards']) + rendered_users = template_users.render(users=data['users'], title=title + ' - Users') + rendered_boards = template_boards.render(boards=data['boards'], title=title + ' - Boards') write_render(rendered_users, 'users.html', outpath) write_render(rendered_boards, 'boards.html', outpath) @@ -104,17 +104,18 @@ def render(inputfile, staticpath, outpath): shutil.copytree(staticpath, os.path.join(outpath, 'board', 'thread', 'static')) for user in data['users']: - rendered_user = template_user.render(user=user) + 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) - render_boards(data['boards'], template_board, template_thread, outpath) + render_boards(data['boards'], template_board, template_thread, outpath, title) if __name__ == "__main__": parser = argparse.ArgumentParser(description='build a static website out of a proboard json dump') parser.add_argument('--data', default='board.json', help='board data (json file)') parser.add_argument('--static', default='static', help='path to the static files (images, attachments)') parser.add_argument('--out', default='rendered', help='path where the website gets rendered to') + parser.add_argument('--title', default='Proboard', help='title for your pages') args = parser.parse_args() - render(args.data, args.static, args.out) + render(args.data, args.static, args.out, args.title) diff --git a/templates/board.html.j2 b/templates/board.html.j2 index bf48f72..d9f105d 100644 --- a/templates/board.html.j2 +++ b/templates/board.html.j2 @@ -4,6 +4,7 @@ +