copy images and generate epub
This commit is contained in:
parent
c6c65c8c32
commit
0ecac665de
12
publish.py
12
publish.py
|
|
@ -5,6 +5,7 @@ import yaml
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import unidecode
|
import unidecode
|
||||||
|
import glob
|
||||||
|
|
||||||
htmltemplate = """<!DOCTYPE html>
|
htmltemplate = """<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
@ -76,13 +77,22 @@ for folderinfo in index['folders']:
|
||||||
htmlcontent = md2html(mdcontent)
|
htmlcontent = md2html(mdcontent)
|
||||||
gmicontent = md2gmi(mdcontent)
|
gmicontent = md2gmi(mdcontent)
|
||||||
|
|
||||||
|
# copy images
|
||||||
|
for f in glob.glob(os.path.join(folderinfo['folder'], "*.png")):
|
||||||
|
shutil.copy2(f, "out/html")
|
||||||
|
shutil.copy2(f, "out/gmi")
|
||||||
|
|
||||||
|
# generate epub
|
||||||
|
subprocess.run(["pandoc", filename, "-o", "/tmp/{}".format(outfilename.replace('.md', '.epub'))], cwd=folderinfo['folder'])
|
||||||
|
shutil.move("/tmp/{}".format(outfilename.replace('.md', '.epub')), "out/html")
|
||||||
|
|
||||||
with open("out/html/{}".format(outfilename).replace('.md', '.html'), "w", encoding="utf-8") as htmlfile:
|
with open("out/html/{}".format(outfilename).replace('.md', '.html'), "w", encoding="utf-8") as htmlfile:
|
||||||
htmlfile.write(apply_html_template(htmlcontent, "{} | {}".format(filetitle, index['title'])))
|
htmlfile.write(apply_html_template(htmlcontent, "{} | {}".format(filetitle, index['title'])))
|
||||||
|
|
||||||
with open("out/gmi/{}".format(outfilename).replace('.md', '.gmi'), "w", encoding="utf-8") as gmifile:
|
with open("out/gmi/{}".format(outfilename).replace('.md', '.gmi'), "w", encoding="utf-8") as gmifile:
|
||||||
gmifile.write(gmicontent)
|
gmifile.write(gmicontent)
|
||||||
|
|
||||||
htmlhome += "<li><a href=\"{}\">{}</a></li>".format(outfilename.replace('.md', '.html'), filetitle)
|
htmlhome += "<li><a href=\"{}\">{}</a> [<a href=\"{}\">epub</a>]</li>".format(outfilename.replace('.md', '.html'),filetitle,outfilename.replace('.md', '.epub'))
|
||||||
gmihome += "\n=> {} {}".format(outfilename.replace('.md', '.gmi').replace(' ', '%20'), filetitle)
|
gmihome += "\n=> {} {}".format(outfilename.replace('.md', '.gmi').replace(' ', '%20'), filetitle)
|
||||||
|
|
||||||
elif fileextension == ".wav" or fileextension == ".3gp":
|
elif fileextension == ".wav" or fileextension == ".3gp":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue