From a7a5be958aa9fa9143aba2f94d66bebbf768aa30 Mon Sep 17 00:00:00 2001 From: n Date: Sat, 20 Jul 2024 19:02:19 +0200 Subject: [PATCH] fix filename generation --- blog/index.gen.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blog/index.gen.py b/blog/index.gen.py index 828e32d..f7ef2e8 100755 --- a/blog/index.gen.py +++ b/blog/index.gen.py @@ -40,7 +40,8 @@ with open("index.gmi", "w", encoding="utf-8") as f: for x in myresult: path = path_regex.findall(x[0])[0] path_with_dashes = path.replace("/","-") - filename = quote(quote(filename_regex.findall(x[0])[0])) + title = filename_regex.findall(x[0])[0] + filename = re.sub('\W+','', title) with open("index.gmi", "a", encoding="utf-8") as f: f.write(f'=> {path}/{filename}.gmi {path_with_dashes} - {x[1]}\n') @@ -51,9 +52,9 @@ for x in myresult: except OSError: print (f"Creation of the directory {path} failed") - if not os.path.isfile(f'{path}/"{filename}".gmi'): - print(f"creating {path}/\"{filename}\".gmi") - with open(f'{path}/"{filename}".gmi', "w", encoding="utf-8") as f: + if not os.path.isfile(f'{path}/{filename}.gmi'): + print(f"creating {path}/{filename}.gmi") + with open(f'{path}/{filename}.gmi', "w", encoding="utf-8") as f: f.write(f"# {x[1]}\n\n") f.write(f"PubliƩ le {path}\n\n") f.write(html2markdown.convert(x[2]))