From 54dce14934e776eb9692b2bbdddcae900ebd4c3f Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Thu, 20 Feb 2025 10:36:00 +0100 Subject: [PATCH] remove accents from output file names --- publish.py | 27 ++++++++++++++------------- pyproject.toml | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/publish.py b/publish.py index 051ea25..35e40dc 100644 --- a/publish.py +++ b/publish.py @@ -4,6 +4,7 @@ import markdown import yaml import shutil import subprocess +import unidecode htmltemplate = """ @@ -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 += "
  • {}
  • ".format(filename.replace('.md', '.html'), filetitle) - gmihome += "\n=> {} {}".format(filename.replace('.md', '.gmi').replace(' ', '%20'), filetitle) + htmlhome += "
  • {}
  • ".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 += "
  • {}
  • ".format(filetitle, filename) + os.path.join('out/html', outfilename)]) + htmlhome += "
  • {}
  • ".format(filetitle, outfilename) elif fileextension == ".mp3": - shutil.copy(os.path.join(folderinfo['folder'], filename), 'out/html') - htmlhome += "
  • {}
  • ".format(filetitle, filename) + shutil.copy(os.path.join(folderinfo['folder'], filename), os.path.join('out/html', outfilename)) + htmlhome += "
  • {}
  • ".format(filetitle, outfilename) htmlhome += "\n" diff --git a/pyproject.toml b/pyproject.toml index 05206a6..b165d36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,5 @@ requires-python = ">=3.12" dependencies = [ "markdown>=3.7", "pyyml>=0.0.2", + "unidecode>=1.3.8", ]