copy images and generate epub

This commit is contained in:
quenousimporte 2026-08-17 11:27:12 +02:00
parent c6c65c8c32
commit 0ecac665de
1 changed files with 11 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import yaml
import shutil
import subprocess
import unidecode
import glob
htmltemplate = """<!DOCTYPE html>
<html>
@ -76,13 +77,22 @@ for folderinfo in index['folders']:
htmlcontent = md2html(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:
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:
gmifile.write(gmicontent)
htmlhome += "<li><a href=\"{}\">{}</a></li>".format(outfilename.replace('.md', '.html'), filetitle)
htmlhome += "<li><a href=\"{}\">{}</a>&nbsp;[<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)
elif fileextension == ".wav" or fileextension == ".3gp":