blog-markdown #31
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue