add title parameter to templates
This commit is contained in:
parent
a49e8eb967
commit
8e3dccd637
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ include/
|
|||||||
lib/
|
lib/
|
||||||
static/
|
static/
|
||||||
board.json
|
board.json
|
||||||
|
pip-selfcheck.json
|
||||||
|
21
generator.py
21
generator.py
@ -65,18 +65,18 @@ def find_unregistered_users(data):
|
|||||||
|
|
||||||
return unregistered_users
|
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:
|
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)
|
write_render(rendered_board, os.path.join('board', board['title'].replace('/', '_').replace(' ', '_').replace('?', '') + '.html'), outpath)
|
||||||
|
|
||||||
for thread in board['threads']:
|
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)
|
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:
|
with open(inputfile) as data_file:
|
||||||
data = json.load(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_board = env.get_template('board.html.j2')
|
||||||
template_thread = env.get_template('thread.html.j2')
|
template_thread = env.get_template('thread.html.j2')
|
||||||
|
|
||||||
rendered_users = template_users.render(users=data['users'])
|
rendered_users = template_users.render(users=data['users'], title=title + ' - Users')
|
||||||
rendered_boards = template_boards.render(boards=data['boards'])
|
rendered_boards = template_boards.render(boards=data['boards'], title=title + ' - Boards')
|
||||||
|
|
||||||
write_render(rendered_users, 'users.html', outpath)
|
write_render(rendered_users, 'users.html', outpath)
|
||||||
write_render(rendered_boards, 'boards.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'))
|
shutil.copytree(staticpath, os.path.join(outpath, 'board', 'thread', 'static'))
|
||||||
|
|
||||||
for user in data['users']:
|
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)
|
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__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='build a static website out of a proboard json dump')
|
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('--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('--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('--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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
render(args.data, args.static, args.out)
|
render(args.data, args.static, args.out, args.title)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<link href="styles.css" rel="stylesheet" type="text/css" />
|
<link href="styles.css" rel="stylesheet" type="text/css" />
|
||||||
|
<title>{{ title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% if board.boards |length > 0 %}
|
{% if board.boards |length > 0 %}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<link href="styles.css" rel="stylesheet" type="text/css" />
|
<link href="styles.css" rel="stylesheet" type="text/css" />
|
||||||
|
<title>{{ title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<link href="styles.css" rel="stylesheet" type="text/css" />
|
<link href="styles.css" rel="stylesheet" type="text/css" />
|
||||||
|
<title>{{ title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{ thread.title }}</h1>
|
<h1>{{ thread.title }}</h1>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<link href="styles.css" rel="stylesheet" type="text/css" />
|
<link href="styles.css" rel="stylesheet" type="text/css" />
|
||||||
|
<title>{{ title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{ user.name }}</h1>
|
<h1>{{ user.name }}</h1>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<link href="styles.css" rel="stylesheet" type="text/css" />
|
<link href="styles.css" rel="stylesheet" type="text/css" />
|
||||||
|
<title>{{ title }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<ul>
|
<ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user