file title parsing
This commit is contained in:
parent
a687700c85
commit
d81b20e391
|
@ -24,6 +24,7 @@ MD = markdown.Markdown(extensions=EXTENSIONS, extension_configs=EXTENSION_CONFIG
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
class Category(models.Model):
|
class Category(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -145,6 +146,8 @@ class BlogPost(Searchable):
|
||||||
|
|
||||||
Caution: Will delete all Blog Posts
|
Caution: Will delete all Blog Posts
|
||||||
"""
|
"""
|
||||||
|
logger.name = logger.name + ".sync_all"
|
||||||
|
|
||||||
# delete all existing objects
|
# delete all existing objects
|
||||||
BlogPost.objects.all().delete()
|
BlogPost.objects.all().delete()
|
||||||
|
|
||||||
|
@ -155,9 +158,24 @@ class BlogPost(Searchable):
|
||||||
if not data_dir.is_dir():
|
if not data_dir.is_dir():
|
||||||
logger.error(f"'{cls.DATA_DIR} is not a directory'")
|
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}")
|
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:
|
class Meta:
|
||||||
verbose_name = _("blog post")
|
verbose_name = _("blog post")
|
||||||
|
|
Loading…
Reference in New Issue