feat: added article home overview

This commit is contained in:
2025-04-14 16:04:40 +02:00
parent 2dc1dfef98
commit 37974c418b
3 changed files with 15 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ from pathlib import Path
import os
import markdown
from typing import Optional, Union, Dict, Generator, List
from bs4 import BeautifulSoup
from .config import SOURCE_DIRECTORY, DIST_DIRECTORY, LANGUAGE_INFORMATION, ARTICLE_PREVIEW_LENGTH
@@ -137,6 +138,16 @@ class Article(CustomPath):
def language_code(self) -> CustomLanguageCode:
return CustomLanguageCode(self.stem)
def get_first_header_content(self, content):
soup = BeautifulSoup(content, 'html.parser')
for level in range(1, 7):
header = soup.find(f'h{level}')
if header:
return header.get_text(strip=True)
return self.language_code.native_name
def get_article_keys(self) -> Dict[str, str]:
article_content = self.get_content()
@@ -145,6 +156,7 @@ class Article(CustomPath):
"article_preview": article_content[:ARTICLE_PREVIEW_LENGTH],
"article_overview_href": "/" + str(self.path.parent),
"article_href": "/" + str(self.path.parent / self.stem),
"article_title": self.get_first_header_content(article_content),
"article_language_name": self.language_code.native_name,
"article_language_code": self.language_code.language_code,
"article_language_flag": self.language_code.flag,