file title parsing

This commit is contained in:
Christoph J. Scherr 2023-09-30 19:45:07 +02:00
parent a687700c85
commit b785462232

View file

@ -24,6 +24,7 @@ MD = markdown.Markdown(extensions=EXTENSIONS, extension_configs=EXTENSION_CONFIG
import pathlib
import os
import re
class Category(models.Model):
"""
@ -155,9 +156,25 @@ 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:
logger.debug(f"f: {f[0]}")
matches = re.match(regex, f[0])
lang = matches.group(1)
titl = matches.group(2)
f = (f[0], lang, titl)
logger.debug(f"file tup: {f}")
except Exception as e:
logger.debug(e)
files.remove(f)
class Meta:
verbose_name = _("blog post")