add title parameter to templates

This commit is contained in:
Sebastian Hugentobler 2015-05-12 20:18:31 +02:00
parent a49e8eb967
commit 8e3dccd637
7 changed files with 17 additions and 10 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ include/
lib/
static/
board.json
pip-selfcheck.json

View File

@ -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)

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>{{ title }}</title>
</head>
<body>
{% if board.boards |length > 0 %}

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>{{ title }}</title>
</head>
<body>
<ul>

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>{{ title }}</title>
</head>
<body>
<h1>{{ thread.title }}</h1>

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>{{ title }}</title>
</head>
<body>
<h1>{{ user.name }}</h1>

View File

@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>{{ title }}</title>
</head>
<body>
<ul>