cleanup
This commit is contained in:
parent
8488b7d9f6
commit
aa7d9b42e6
1 changed files with 17 additions and 27 deletions
|
@ -23,39 +23,29 @@ class Article(BaseModel):
|
||||||
date: date
|
date: date
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
def walk_for_md(path: str):
|
|
||||||
buf = []
|
|
||||||
|
|
||||||
for root, _, files in os.walk(path):
|
def get_articles_from_path(path: str) -> list[Article]:
|
||||||
print(files)
|
md = markdown.Markdown(extensions=["meta"]);
|
||||||
mdeez = [f"{root}/{filename}" for filename in files if filename[-2:] == "md"]
|
|
||||||
|
|
||||||
if mdeez:
|
|
||||||
buf.extend(mdeez)
|
|
||||||
|
|
||||||
return buf
|
|
||||||
|
|
||||||
def get_articles_from_dir(root_path: str) -> list[Article]:
|
|
||||||
md = markdown.Markdown(extensions=['meta'])
|
|
||||||
articles: list[Article] = []
|
articles: list[Article] = []
|
||||||
|
|
||||||
for file_path in walk_for_md(root_path):
|
for root, _, filenames in os.walk(path):
|
||||||
with open(file_path) as file:
|
for filename in filenames:
|
||||||
|
if filename[-2:] == "md":
|
||||||
|
with open(f"{root}/{filename}") as file:
|
||||||
html: str = md.convert(file.read());
|
html: str = md.convert(file.read());
|
||||||
meta: dict = md.Meta;
|
meta: dict = md.Meta;
|
||||||
|
|
||||||
articles.append(
|
articles.append(
|
||||||
Article(
|
Article(
|
||||||
content_type=meta.get('content_type')[0],
|
content_type=meta.get("content_type")[0],
|
||||||
title=meta.get('title')[0],
|
title=meta.get("title")[0],
|
||||||
date=datetime.strptime( meta.get( 'date')[0], '%Y %m %d'),
|
date=datetime.strptime(meta.get("date")[0], "%Y %m %d"),
|
||||||
content=html,
|
content=html,
|
||||||
));
|
));
|
||||||
|
|
||||||
return articles;
|
return articles;
|
||||||
|
|
||||||
DB = sorted(
|
DB = sorted(
|
||||||
get_articles_from_dir(STATIC_PATH),
|
get_articles_from_path(STATIC_PATH),
|
||||||
key=lambda article: article.date,
|
key=lambda article: article.date,
|
||||||
reverse=True
|
reverse=True
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue