Compare commits

5 Commits

Author SHA1 Message Date
0a2dde8009 Add fallback for img src's
All checks were successful
continuous-integration/drone/push Build is passing
2024-05-19 18:59:51 +02:00
523b7c9fd7 Merge branch 'main' into t-work 2024-05-19 18:52:44 +02:00
6d213b7644 Merge branch 'main' into t-work 2024-05-19 18:30:12 +02:00
e20afa3313 Add vanilla theme switcher 2024-05-19 18:06:38 +02:00
aa7a5acf94 Constrain post summary width for EZ reading 2024-05-19 17:36:20 +02:00
6 changed files with 44 additions and 9 deletions

BIN
astro/public/not-found.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -12,7 +12,7 @@ const contentArray = getContentArray(content);
} else {
return (
<Image
src={getImageSrc(value.src)}
src={getImageSrc(value.src) || "/not-found.png"}
width={value.width}
height={value.height}
format="webp"

View File

@ -1,9 +1,11 @@
---
import { getCurrentYear } from "@/utils/date";
import ThemeSwitcher from "./ThemeSwitcher.astro";
---
<footer>
<footer class="flex justify-between">
<p class="text-lg font-semibold">
&copy; {getCurrentYear()} Example Website. All rights reserved.
</p>
<ThemeSwitcher/>
</footer>

View File

@ -8,15 +8,15 @@ const { post } = Astro.props;
href={`/posts/${post.id}/`}
>
<article class="flex px-5 py-3 gap-8">
<Image
src={post.thumbnail.url}
height="150"
aspectRatio="1"
<Image
src={post.thumbnail.url || "/not-found"}
height={150}
aspectRatio={1}
format="webp"
alt={post.thumbnail.alt}
/>
<div class="flex flex-col gap-4">
<div class="flex flex-col gap-4 w-full">
<div class="flex justify-between w-full">
<h3 class="">{post.title}</h3>
{post.publishedDate && (
@ -24,8 +24,8 @@ const { post } = Astro.props;
{new Date(post.publishedDate).toLocaleDateString("de-DE")}
</p>
)}
</div>
{post.summary && <p>
</div>
{post.summary && <p class="max-w-prose">
{post.summary}
</p>}
</div>

View File

@ -0,0 +1,12 @@
---
---
<select id="theme-selector">
<option value="autonomic">Autonomic</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
<script>
import { handleThemeChange, switchTheme, initializeThemeSelector } from "@/utils/theme"
initializeThemeSelector()
</script>

21
astro/src/utils/theme.ts Normal file
View File

@ -0,0 +1,21 @@
export function switchTheme(themeClass: string): void {
const bodyElement = document.body;
const classesToRemove = ['light', 'dark', 'autonomic'];
bodyElement.classList.remove(...classesToRemove);
bodyElement.classList.add(themeClass);
}
export function handleThemeChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const selectedTheme = selectElement.value;
switchTheme(selectedTheme);
}
export function initializeThemeSelector(): void {
const themeSelector = document.getElementById('theme-selector');
if (themeSelector) {
themeSelector.addEventListener('change', handleThemeChange);
}
}