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