Allow changing of title

This commit is contained in:
Jake Howard 2017-03-30 08:52:35 +01:00
parent e4692dbfc0
commit 06fec04c72
2 changed files with 8 additions and 8 deletions

View File

@ -13,4 +13,4 @@ def build(config):
output_html(doc, os.path.abspath(config.output_dir)) output_html(doc, os.path.abspath(config.output_dir))
if 'pdf' in config.output_formats: if 'pdf' in config.output_formats:
render_cover() render_cover()
export_pdf(doc, os.path.abspath(config.output_dir)) export_pdf(doc, config)

View File

@ -1,12 +1,12 @@
import pdfkit import pdfkit
from md_pdf.consts import PROJECT_DIR from md_pdf.consts import ASSET_DIR
from md_pdf.build.cover import OUTPUT_COVER_FILE from md_pdf.build.cover import OUTPUT_COVER_FILE
import os import os
STYLE_FILE = os.path.join(PROJECT_DIR, 'assets', 'style.css') STYLE_FILE = os.path.join(ASSET_DIR, 'style.css')
HEADER_FILE = os.path.join(PROJECT_DIR, 'assets', 'header.html') HEADER_FILE = os.path.join(ASSET_DIR, 'header.html')
FOOTER_FILE = os.path.join(PROJECT_DIR, 'assets', 'footer.html') FOOTER_FILE = os.path.join(ASSET_DIR, 'footer.html')
PDF_OPTIONS = { PDF_OPTIONS = {
"quiet": "", "quiet": "",
"no-pdf-compression": "", "no-pdf-compression": "",
@ -21,17 +21,17 @@ PDF_OPTIONS = {
"footer-spacing": 5, "footer-spacing": 5,
"header-spacing": 5, "header-spacing": 5,
"title": "Title thing",
"replace": [ "replace": [
] ]
} }
def export_pdf(content, out_dir): def export_pdf(content, config):
PDF_OPTIONS['title'] = getattr(config, 'title', 'output')
return pdfkit.from_string( return pdfkit.from_string(
content, content,
os.path.join(out_dir, 'output.pdf'), os.path.join(os.path.abspath(config.output_dir), 'output.pdf'),
options=PDF_OPTIONS, options=PDF_OPTIONS,
css=STYLE_FILE, css=STYLE_FILE,
cover=OUTPUT_COVER_FILE cover=OUTPUT_COVER_FILE