remove accents from output file names
This commit is contained in:
parent
cdc6923a25
commit
54dce14934
27
publish.py
27
publish.py
|
@ -4,6 +4,7 @@ import markdown
|
|||
import yaml
|
||||
import shutil
|
||||
import subprocess
|
||||
import unidecode
|
||||
|
||||
htmltemplate = """<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -53,10 +54,12 @@ for folderinfo in index['folders']:
|
|||
|
||||
for fileinfo in folderinfo['files']:
|
||||
|
||||
filename = fileinfo['file']
|
||||
filetitle = fileinfo['title']
|
||||
filename = fileinfo['file']
|
||||
fileroot, fileextension = os.path.splitext(filename)
|
||||
|
||||
outfilename = unidecode.unidecode(filename)
|
||||
|
||||
if fileextension == '.md':
|
||||
|
||||
with open(os.path.join(folderinfo['folder'], filename), "r", encoding="utf-8") as mdfile:
|
||||
|
@ -68,30 +71,28 @@ for folderinfo in index['folders']:
|
|||
htmlcontent = md2html(mdcontent)
|
||||
gmicontent = md2gmi(mdcontent)
|
||||
|
||||
with open("out/html/{}".format(filename).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'])))
|
||||
|
||||
with open("out/gmi/{}".format(filename).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)
|
||||
|
||||
htmlhome += "<li><a href=\"{}\">{}</a></li>".format(filename.replace('.md', '.html'), filetitle)
|
||||
gmihome += "\n=> {} {}".format(filename.replace('.md', '.gmi').replace(' ', '%20'), filetitle)
|
||||
htmlhome += "<li><a href=\"{}\">{}</a></li>".format(outfilename.replace('.md', '.html'), filetitle)
|
||||
gmihome += "\n=> {} {}".format(outfilename.replace('.md', '.gmi').replace(' ', '%20'), filetitle)
|
||||
|
||||
elif fileextension == ".wav" or fileextension == ".3gp":
|
||||
|
||||
# sounds
|
||||
# todo: add a property for dest file (to remove accents)
|
||||
|
||||
# todo use builtin library
|
||||
# todo use builtin python library
|
||||
outfilename = unidecode.unidecode(fileroot) + ".mp3"
|
||||
subprocess.run(["ffmpeg",
|
||||
"-i",
|
||||
os.path.join(folderinfo['folder'], filename),
|
||||
os.path.join('out/html', fileroot + ".mp3")])
|
||||
htmlhome += "<li>{}</li><audio controls><source src=\"{}\"></audio>".format(filetitle, filename)
|
||||
os.path.join('out/html', outfilename)])
|
||||
htmlhome += "<li>{}</li><audio controls><source src=\"{}\"></audio>".format(filetitle, outfilename)
|
||||
|
||||
elif fileextension == ".mp3":
|
||||
shutil.copy(os.path.join(folderinfo['folder'], filename), 'out/html')
|
||||
htmlhome += "<li>{}</li><audio controls><source src=\"{}\"></audio>".format(filetitle, filename)
|
||||
shutil.copy(os.path.join(folderinfo['folder'], filename), os.path.join('out/html', outfilename))
|
||||
htmlhome += "<li>{}</li><audio controls><source src=\"{}\"></audio>".format(filetitle, outfilename)
|
||||
|
||||
htmlhome += "\n</ul>"
|
||||
|
||||
|
|
|
@ -7,4 +7,5 @@ requires-python = ">=3.12"
|
|||
dependencies = [
|
||||
"markdown>=3.7",
|
||||
"pyyml>=0.0.2",
|
||||
"unidecode>=1.3.8",
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue