Fix cover context

This commit is contained in:
Jake Howard 2017-03-31 18:12:11 +01:00
parent c458976f2a
commit 61c724243b
7 changed files with 19 additions and 12 deletions

View File

@ -5,13 +5,16 @@
</head>
<body class="cover">
<h1>{{ title }}</h1>
<h3>{{ subtitle }}</h3>
{% if subtitle %}
<h3>{{ subtitle }}</h3>
{% endif %}
{% if student_number %}
<h5>Student Number: {{ student_number }}</h5>
<h4>Student Number: {{ student_number }}</h4>
{% endif %}
{% if turnitin_number %}
<h5>TurnItIn Number: {{ turnitin_number }}</h5>
<h4>TurnItIn Number: {{ turnitin_number }}</h4>
{% endif %}
</body>
</html>

View File

@ -4,6 +4,6 @@ body.cover {
}
body.cover h1 {
font-size: 72px;
font-size: 48px;
padding-top: 400px;
}

View File

@ -11,5 +11,5 @@ def build(config):
if 'html' in config['output_formats']:
output_html(doc, os.path.abspath(config['output_dir']))
if 'pdf' in config['output_formats']:
render_cover(config['context'])
render_cover(config)
export_pdf(doc, config)

View File

@ -1,13 +1,15 @@
from jinja2 import Template
from md_pdf.consts import PROJECT_DIR
from md_pdf.consts import ASSET_DIR
import os
COVER_TEMPLATE = os.path.join(PROJECT_DIR, 'assets', 'cover-template.html')
OUTPUT_COVER_FILE = os.path.join(PROJECT_DIR, 'assets', 'cover.html')
COVER_TEMPLATE = os.path.join(ASSET_DIR, 'cover-template.html')
OUTPUT_COVER_FILE = os.path.join(ASSET_DIR, 'cover.html')
def render_cover(context={}):
def render_cover(config):
context = config['context'].copy()
context['title'] = config['title']
with open(COVER_TEMPLATE) as f:
template = Template(f.read())
with open(OUTPUT_COVER_FILE, "w") as f:

View File

@ -25,7 +25,7 @@ PDF_OPTIONS = {
def export_pdf(content, config):
PDF_OPTIONS['title'] = config.get('title', 'Output')
PDF_OPTIONS['replace'] = list(config['context'].items())
PDF_OPTIONS['replace'] = [(key, str(value)) for key, value in config['context'].items()]
return pdfkit.from_string(
content,

View File

@ -9,4 +9,6 @@ bibliography:
context:
foo: bar
bar: foo
title: test
student_number: 123456
turnitin_number: 789123
title: test title

View File

@ -1 +1 @@
# Test
# Test content