From d81b20e391d148460b35edd77dd44eb32b9a883f Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sat, 30 Sep 2023 19:45:07 +0200 Subject: [PATCH] file title parsing --- gawa/blog/models.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gawa/blog/models.py b/gawa/blog/models.py index 515bc8a..152f1bc 100644 --- a/gawa/blog/models.py +++ b/gawa/blog/models.py @@ -24,6 +24,7 @@ MD = markdown.Markdown(extensions=EXTENSIONS, extension_configs=EXTENSION_CONFIG import pathlib import os +import re class Category(models.Model): """ @@ -145,6 +146,8 @@ class BlogPost(Searchable): Caution: Will delete all Blog Posts """ + logger.name = logger.name + ".sync_all" + # delete all existing objects BlogPost.objects.all().delete() @@ -155,9 +158,24 @@ class BlogPost(Searchable): if not data_dir.is_dir(): logger.error(f"'{cls.DATA_DIR} is not a directory'") - files = [f for f in os.listdir(data_dir) if os.path.isfile(f)] + files = [f for f in os.listdir(data_dir) if (data_dir.joinpath(f)).is_file()] logger.debug(f"discovered files: {files}") + # finding lang and title + regex = r"^(en|de)-(.*)\.md" + + # filepath, language code, slug + files = [(f, "", "") for f in files] + for f in files: + try: + matches = re.match(regex, f[0]) + lang = matches.group(1) + titl = matches.group(2) + f = (f[0], lang, titl) + logger.debug(f"discovered file tup: {f}") + except Exception as e: + logger.debug(e) + files.remove(f) class Meta: verbose_name = _("blog post")