Add skeleton of mvp code
This commit is contained in:
parent
0097d50767
commit
953efa7c35
5 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
import click
|
||||||
|
|
||||||
|
@click.command('build', short_help="Build document")
|
||||||
|
def cli():
|
||||||
|
pass
|
9
src/build/cover.py
Normal file
9
src/build/cover.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
|
def render_cover(context):
|
||||||
|
with open("cover-template.html") as f:
|
||||||
|
template = Template(f.read())
|
||||||
|
with open("cover.html", "w") as f:
|
||||||
|
cover = template.render(context)
|
||||||
|
f.write(cover)
|
||||||
|
return cover
|
11
src/build/md.py
Normal file
11
src/build/md.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import glob
|
||||||
|
|
||||||
|
def get_files_content(filenames):
|
||||||
|
for filename in filenames:
|
||||||
|
with open(filename) as f:
|
||||||
|
yield f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def read_files(files_glob):
|
||||||
|
filenames = glob.glob(files_glob)
|
||||||
|
return '\n'.join(list(get_files_content(filenames)))
|
25
src/build/pandoc.py
Normal file
25
src/build/pandoc.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import pypandoc
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
def fix_references_title(content):
|
||||||
|
soup = BeautifulSoup(content, 'html.parser')
|
||||||
|
title = soup.new_tag('h1')
|
||||||
|
title.string = "References"
|
||||||
|
soup.find('div', class_="references").insert_before(title)
|
||||||
|
return soup.prettify()
|
||||||
|
|
||||||
|
|
||||||
|
def build_document(files_content):
|
||||||
|
html = pypandoc.convert_text(files_content, 'html', format='md',
|
||||||
|
extra_args=[
|
||||||
|
'-s',
|
||||||
|
'--bibliography=bib.yml',
|
||||||
|
'--csl=harvard.csl'
|
||||||
|
],
|
||||||
|
filters=[
|
||||||
|
'pandoc-citeproc'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
return fix_references_title(html)
|
31
src/build/pdf.py
Normal file
31
src/build/pdf.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import pdfkit
|
||||||
|
|
||||||
|
pdf_options = {
|
||||||
|
"quiet": "",
|
||||||
|
"no-pdf-compression": "",
|
||||||
|
|
||||||
|
"margin-top": '0.6in',
|
||||||
|
"margin-bottom": '0.6in',
|
||||||
|
"margin-left": '0.4in',
|
||||||
|
"margin-right": '0.4in',
|
||||||
|
|
||||||
|
"header-html": "header.html",
|
||||||
|
"footer-html": "footer.html",
|
||||||
|
"footer-spacing": 5,
|
||||||
|
"header-spacing": 5,
|
||||||
|
|
||||||
|
"title": "Title thing",
|
||||||
|
"replace": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def export_pdf(content):
|
||||||
|
return pdfkit.from_string(
|
||||||
|
content,
|
||||||
|
'out.pdf',
|
||||||
|
options=pdf_options,
|
||||||
|
css="style.css",
|
||||||
|
cover="cover.html"
|
||||||
|
)
|
Reference in a new issue