feat: added article home overview

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

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>STSG</title>
<title>{article_language_flag} {article_title}</title>
<link rel="stylesheet" href="/static/bulma.min.css" />
</head>
<body>
@ -15,7 +15,7 @@
>
<div class="navbar-brand">
<a class="navbar-item" href="{article_overview_href}">
<strong>{article_language_flag} Static Translated Site Generator</strong>
<strong>{article_language_flag} {article_title}</strong>
</a>
</div>
</nav>

View File

@ -1,7 +1,7 @@
<div class="card mb-4">
<a href="{article_href}" class="card mb-4" style="color: inherit; text-decoration: none;">
<div class="card-content" href="{article_href}">
<p class="title">{article_language_flag} {article_language_name}</p>
<p class="title">{article_language_flag} {article_title}</p>
<p class="content">{article_preview}</p>
</div>
</a>

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,