Compare commits
6 Commits
feature/is
...
7d1ceded8d
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d1ceded8d | |||
| b3e23a53d9 | |||
| b2513f7caf | |||
| 4743456bd8 | |||
| 6994662bb4 | |||
| db23ceac78 |
@@ -7,7 +7,6 @@
|
|||||||
<link rel="stylesheet" href="/static/bulma.min.css" />
|
<link rel="stylesheet" href="/static/bulma.min.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- Header (Navbar) -->
|
|
||||||
<nav
|
<nav
|
||||||
class="navbar is-primary"
|
class="navbar is-primary"
|
||||||
role="navigation"
|
role="navigation"
|
||||||
@@ -23,22 +22,31 @@
|
|||||||
<section class="section">
|
<section class="section">
|
||||||
{% if translations|length %}
|
{% if translations|length %}
|
||||||
<div class="container content">
|
<div class="container content">
|
||||||
<div class="column is-half is-offset-one-quarter">
|
<div class="content">
|
||||||
<h1>Translations</h1>
|
<h1>Translations</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-half is-offset-one-quarter">
|
<div class="columns is-multiline">
|
||||||
{% for t in translations %}
|
{% for t in translations %}
|
||||||
<div class="card mb-4" lang="{{t.language.code}}">
|
<div class="column is-half">
|
||||||
<a href="{{t.url}}" hreflang="{{t.language.code}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
<div class="card mb-4" lang="{{t.language.code}}" style="height: 100%;">
|
||||||
<div class="card-content">
|
<a href="{{t.url}}" hreflang="{{t.language.code}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
||||||
<p class="title">{{t.language.flag}} {{t.title}} </p>
|
<div class="card-header">
|
||||||
<p class="content">
|
<div class="card-header-title">{{t.title}} </div>
|
||||||
{{t.preview}}
|
<div class="card-header-icon">{{t.language.flag}}</div>
|
||||||
<br />
|
|
||||||
<time datetime="{{iso_date}}">{{date}}</time>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</a>
|
|
||||||
|
<div class="card-content">
|
||||||
|
<hr />
|
||||||
|
<p class="content">
|
||||||
|
{{t.preview}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card-footer">
|
||||||
|
<time datetime="{{iso_date}}">{{date}}</time>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@@ -49,7 +57,7 @@
|
|||||||
{% if children|length %}
|
{% if children|length %}
|
||||||
<div class="container content">
|
<div class="container content">
|
||||||
<div class="column is-half is-offset-one-quarter">
|
<div class="column is-half is-offset-one-quarter">
|
||||||
<h1>Child Articles</h1>
|
<h1>Further reading</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-half is-offset-one-quarter">
|
<div class="column is-half is-offset-one-quarter">
|
||||||
{% for c in children %}
|
{% for c in children %}
|
||||||
@@ -57,9 +65,14 @@
|
|||||||
<a href="{{c.url}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
<a href="{{c.url}}" class="card mb-4" style="color: inherit; text-decoration: none;">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<p class="title">{{c.slug}} </p>
|
<p class="title">{{c.slug}} </p>
|
||||||
<p class="content">
|
<hr />
|
||||||
<time datetime="{{iso_date}}">{{date}}</time>
|
<p class="content is-flex is-flex-direction-column" style="gap: 10px;">
|
||||||
|
{% for ct in c.translations %}
|
||||||
|
<a href="{{ct.url}}" hreflang="{{ct.language.code}}">{{ct.language.flag}}: {{ct.title}}</a>
|
||||||
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
|
<hr />
|
||||||
|
<time datetime="{{iso_date}}">{{date}}</time>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ source_directory = "src"
|
|||||||
dist_directory = "dist"
|
dist_directory = "dist"
|
||||||
|
|
||||||
[formatting]
|
[formatting]
|
||||||
article_preview_length = 400
|
preview_length = 400
|
||||||
|
preview_header_shift = 2
|
||||||
datetime_format = "%d. %B %Y"
|
datetime_format = "%d. %B %Y"
|
||||||
default_language = "de"
|
default_language = "de"
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ class config:
|
|||||||
dist_directory = "dist"
|
dist_directory = "dist"
|
||||||
|
|
||||||
class formatting:
|
class formatting:
|
||||||
article_preview_length = 200
|
|
||||||
datetime_format = "%d. %B %Y"
|
datetime_format = "%d. %B %Y"
|
||||||
fallback_language = "en"
|
fallback_language = "en"
|
||||||
|
preview_length = 400
|
||||||
|
preview_header_shift = 2
|
||||||
|
|
||||||
languages = {
|
languages = {
|
||||||
"af": {
|
"af": {
|
||||||
|
|||||||
@@ -14,13 +14,6 @@ import jinja2
|
|||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
|
|
||||||
def replace_values(template: str, values: Dict[str, str]) -> str:
|
|
||||||
for key, value in values.items():
|
|
||||||
template = template.replace("{" + key + "}", value)
|
|
||||||
|
|
||||||
return template
|
|
||||||
|
|
||||||
|
|
||||||
def get_first_header_content(content, fallback: str = ""):
|
def get_first_header_content(content, fallback: str = ""):
|
||||||
soup = BeautifulSoup(content, 'html.parser')
|
soup = BeautifulSoup(content, 'html.parser')
|
||||||
for level in range(1, 7):
|
for level in range(1, 7):
|
||||||
@@ -31,7 +24,7 @@ def get_first_header_content(content, fallback: str = ""):
|
|||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
|
|
||||||
def shorten_text_and_clean(html_string, max_length=config.formatting.article_preview_length):
|
def shorten_text_and_clean(html_string, max_length=config.formatting.preview_length):
|
||||||
soup = BeautifulSoup(html_string, 'html.parser')
|
soup = BeautifulSoup(html_string, 'html.parser')
|
||||||
|
|
||||||
# Keep track of total characters added
|
# Keep track of total characters added
|
||||||
@@ -69,6 +62,23 @@ def shorten_text_and_clean(html_string, max_length=config.formatting.article_pre
|
|||||||
return str(soup)
|
return str(soup)
|
||||||
|
|
||||||
|
|
||||||
|
def shift_headings(html_string, header_shift=config.formatting.preview_header_shift):
|
||||||
|
soup = BeautifulSoup(html_string, 'html.parser')
|
||||||
|
|
||||||
|
for level in range(6, 0, -1): # Start from h6 to h1 to avoid overwriting
|
||||||
|
old_tag = f'h{level}'
|
||||||
|
for tag in soup.find_all(old_tag):
|
||||||
|
new_level = min(level + header_shift, 6) # Cap at h6
|
||||||
|
new_tag = f'h{new_level}'
|
||||||
|
tag.name = new_tag
|
||||||
|
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
|
|
||||||
|
def get_preview_text(html_string: str):
|
||||||
|
return shift_headings(shorten_text_and_clean(html_string))
|
||||||
|
|
||||||
|
|
||||||
def stem_to_language_code(stem: str) -> str:
|
def stem_to_language_code(stem: str) -> str:
|
||||||
language_code = stem.lower().replace("-", "_")
|
language_code = stem.lower().replace("-", "_")
|
||||||
|
|
||||||
@@ -83,7 +93,6 @@ def stem_to_language_code(stem: str) -> str:
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TemplateDict(dict):
|
class TemplateDict(dict):
|
||||||
def __init__(self, folder: Path):
|
def __init__(self, folder: Path):
|
||||||
self.folder = folder
|
self.folder = folder
|
||||||
@@ -99,8 +108,10 @@ class TemplateDict(dict):
|
|||||||
self[name] = t
|
self[name] = t
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE: Dict[str, jinja2.Template] = TemplateDict(Path(config.setup.source_directory, "templates"))
|
TEMPLATE: Dict[str, jinja2.Template] = TemplateDict(Path(config.setup.source_directory, "templates"))
|
||||||
|
|
||||||
|
|
||||||
class LanguageDict(dict):
|
class LanguageDict(dict):
|
||||||
def __missing__(self, key: str):
|
def __missing__(self, key: str):
|
||||||
if key not in config.languages:
|
if key not in config.languages:
|
||||||
@@ -116,6 +127,7 @@ class LanguageDict(dict):
|
|||||||
|
|
||||||
return lang_dict
|
return lang_dict
|
||||||
|
|
||||||
|
|
||||||
LANGUAGES = LanguageDict()
|
LANGUAGES = LanguageDict()
|
||||||
|
|
||||||
|
|
||||||
@@ -135,15 +147,6 @@ class ArticleTranslation:
|
|||||||
self.priority = LANGUAGES[self.language_code]["priority"]
|
self.priority = LANGUAGES[self.language_code]["priority"]
|
||||||
self.real_language_code = LANGUAGES[self.language_code]["code"]
|
self.real_language_code = LANGUAGES[self.language_code]["code"]
|
||||||
|
|
||||||
# TODO remove
|
|
||||||
self.article_content = self.file.read_text()
|
|
||||||
self.article_preview = self.article_content[:config.formatting.article_preview_length] + "..."
|
|
||||||
if self.file.suffix == ".md":
|
|
||||||
self.article_content = markdown.markdown(self.article_content)
|
|
||||||
self.article_preview = markdown.markdown(self.article_preview)
|
|
||||||
|
|
||||||
self.title = get_first_header_content(self.article_content, fallback="")
|
|
||||||
|
|
||||||
def __init_context__(self):
|
def __init_context__(self):
|
||||||
self.context["meta"] = self.article.context_shared
|
self.context["meta"] = self.article.context_shared
|
||||||
self.context["url"] = self.url
|
self.context["url"] = self.url
|
||||||
@@ -156,7 +159,10 @@ class ArticleTranslation:
|
|||||||
|
|
||||||
self.context["title"] = get_first_header_content(html_content, fallback=LANGUAGES[self.language_code]["native_name"])
|
self.context["title"] = get_first_header_content(html_content, fallback=LANGUAGES[self.language_code]["native_name"])
|
||||||
self.context["content"] = html_content
|
self.context["content"] = html_content
|
||||||
self.context["preview"] = shorten_text_and_clean(html_string=html_content)
|
self.context["preview"] = get_preview_text(html_string=html_content)
|
||||||
|
|
||||||
|
# get children
|
||||||
|
self.context["children"] = [c.article_translations_map[self.language_code].context for c in self.article.child_articles if self.language_code in c.article_translations_map]
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.dist_path.mkdir(parents=True, exist_ok=True)
|
self.dist_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user