1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-10 05:13:46 +02:00

publish new site

This commit is contained in:
Lukas Winkler 2022-04-26 17:31:08 +02:00
parent 80eeee92e7
commit d2c03d3751
Signed by: lukas
GPG key ID: 54DE4D798D244853
13 changed files with 104 additions and 21 deletions

View file

@ -13,7 +13,7 @@ compile:
pybabel compile -d translations --statistics
upload:
rsync -aPz --delete-after public/* lw1.at:/var/www/beta.lw1.at/
rsync -aPz --delete --delete-after public lw1.at:/var/www/lw1.at/
esbuild:
npm run build

View file

@ -15,7 +15,7 @@ export function redirect(): void {
const currentPath = l.pathname
const lang = defaultLanguage()
if (currentPath.startsWith("/i")) {
l.replace("/" + lang + "/" + imprintName[lang] + "/")
l.replace("/" + lang + "/" + imprintName[lang])
return
}

View file

@ -17,3 +17,7 @@ ul,
ol {
margin-bottom: 1.5rem
}
.simplePageHeading {
padding-top: 2rem;
}

View file

@ -15,7 +15,7 @@ body {
p {
margin-top: 0;
hyphens: auto;
//hyphens: auto;
}
h1,

12
lw1/compression.py Normal file
View file

@ -0,0 +1,12 @@
from subprocess import run
from lw1.paths import output_dir
def compress_files():
for file in output_dir.glob("**/*"):
if file.is_dir():
continue
if file.suffix not in {".html", ".css", ".js", ".xml", ".map", ".json", ".woff", ".woff2", ".ttf"}:
continue
run(["gzip", "-k", "-f", "--best", str(file)], check=True)

View file

@ -129,3 +129,41 @@ class LangRedirectGenerator(Generator):
paths.add(root / post.slug)
for url in paths:
writer.write(url, html)
class SimpleSiteGenerator(Generator):
template_name = "simple.html"
filename: str
title: str
content: str
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def generate(self, writer: Writer) -> None:
self.context["title"], self.context["content"] = self.title, self.content
url = Path("/") / self.filename
self.context["url"] = url
self.context["lanf"] = "en"
self.context["otherlang"] = "de"
self.context["otherlang_url"] = Path("/de")
html = self.template.render(**self.context)
writer.write(url, html)
class NotFoundGenerator(SimpleSiteGenerator):
filename = "404.html"
title = "Page not Found"
content = "The page you are looking for doesn't seem to exist."
class PermissionDeniedGenerator(SimpleSiteGenerator):
filename = "403.html"
title = "Permission Denied"
content = "The page you are looking for doesn't seem to be public."
class ServerErrorGenerator(SimpleSiteGenerator):
filename = "50x.html"
title = "Server Error"
content = "The seems to be an issue with the webserver at the moment. Please try again later."

View file

@ -2,9 +2,11 @@ from time import perf_counter_ns
from babel.support import Translations
from lw1.generators import PostsGenerator, HomepageGenerator, ImprintGenerator, LangRedirectGenerator
from lw1.compression import compress_files
from lw1.generators import PostsGenerator, HomepageGenerator, ImprintGenerator, LangRedirectGenerator, \
NotFoundGenerator, PermissionDeniedGenerator, ServerErrorGenerator
from lw1.loader import PostLoader, TagsLoader, AssetsLoader
from lw1.paths import output_dir
from lw1.paths import output_dir, translations_dir
from lw1.settings import LANGUAGES
from lw1.sitemap import Sitemap
from lw1.writer import Writer
@ -19,13 +21,16 @@ def main(debug=False):
context = {"debug": debug, "entrypoints": entrypoints}
writer = Writer()
for lang in LANGUAGES:
translations: Translations = Translations.load("../translations", [lang])
translations: Translations = Translations.load(translations_dir, [lang])
context["lang"] = lang
generators = [
PostsGenerator,
HomepageGenerator,
ImprintGenerator,
LangRedirectGenerator
LangRedirectGenerator,
NotFoundGenerator,
PermissionDeniedGenerator,
ServerErrorGenerator
]
for cls in generators:
g = cls(
@ -37,6 +42,8 @@ def main(debug=False):
g.generate(writer)
sitemap.dump(output_dir / "sitemap.xml")
end = perf_counter_ns()
if not debug:
compress_files()
print(f"{(end - start) / 1000 / 1000:.2f} ms")

View file

@ -5,6 +5,7 @@ basedir = Path(__file__).parent.parent
templates_dir = basedir / "templates"
content_dir = basedir / "content"
output_dir = basedir / "public"
translations_dir = basedir / "translations"
post_img_dir = output_dir / "img"
cache_dir = basedir / "cache"
cache_file = cache_dir / "cache.yaml"

View file

@ -29,3 +29,5 @@ def custom_slugify(title: str) -> str:
for delete in ["'"]:
title = title.replace(delete, "")
return slugify(title)

View file

@ -5,12 +5,15 @@ from lw1.paths import output_dir
class Writer:
def write(self, url: Path, html: str):
def write(self, url: Path, html: str, direct=False):
output_url = output_dir / url.relative_to("/")
print(url)
output_url.mkdir(exist_ok=True, parents=True)
index_file = output_url / "index.html"
with index_file.open("w") as f:
if not direct:
output_url.mkdir(exist_ok=True, parents=True)
output_file = output_url / "index.html"
else:
output_file = output_url
with output_file.open("w") as f:
f.write(html)
def writeImage(self, url: Path, image: Image):

16
templates/simple.html Normal file
View file

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}{{ title}}{% endblock %}
{% block content %}
<h1 class="simplePageHeading">{{ title }}</h1>
<p>{{ content }}</p>
{% include "contact.html" %}
<a href="/{{ lang }}/{% trans %}imprint{% endtrans %}" class="toImprint btn">{% trans %}Imprint{% endtrans %}</a>
<a href="https://keyoxide.org/63DB263BACE368B5C5F79CE494AFBE7C2656A5B5" class="gpg" target="_blank"
rel="noopener">
GPG: 63DB 263B ACE3 68B5 C5F7 9CE4 94AF BE7C 2656 A5B5
</a>
{% endblock %}

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-04-24 19:06+0200\n"
"POT-Creation-Date: 2022-04-26 15:58+0200\n"
"PO-Revision-Date: 2022-04-24 13:10+0200\n"
"Last-Translator: Lukas Winkler <translations@lw1.at>\n"
"Language: de\n"
@ -78,19 +78,19 @@ msgstr "Alle Projekte"
msgid "Search&hellip;"
msgstr "Suchen&hellip;"
#: templates/page.html:128
#: templates/page.html:134
msgid "I want to read more about this project"
msgstr "Ich möchte mehr über dieses Projekt lesen"
#: templates/page.html:131
#: templates/page.html:137
msgid "Thanks for the feedback!"
msgstr "Danke für das Feedback!"
#: templates/page.html:132
#: templates/page.html:138
msgid "When I get to it, I will try to extend this post."
msgstr "Wenn ich dazu komme, werde ich diesen Eintrag ergänzen."
#: templates/page.html:133
#: templates/page.html:139
msgid ""
"In the meantime you can contact me at\n"
" <a "

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-04-24 19:06+0200\n"
"POT-Creation-Date: 2022-04-26 15:58+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -77,19 +77,19 @@ msgstr ""
msgid "Search&hellip;"
msgstr ""
#: templates/page.html:128
#: templates/page.html:134
msgid "I want to read more about this project"
msgstr ""
#: templates/page.html:131
#: templates/page.html:137
msgid "Thanks for the feedback!"
msgstr ""
#: templates/page.html:132
#: templates/page.html:138
msgid "When I get to it, I will try to extend this post."
msgstr ""
#: templates/page.html:133
#: templates/page.html:139
msgid ""
"In the meantime you can contact me at\n"
" <a "