Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,43 @@ Dates display in the selected language using UTC. Reading time is estimated at
200 words per minute, with a minimum of one minute.
Set optional `youtubeId` to an 11-character YouTube video ID to show a player.

### Article covers

Add a single WebP file to `public/images/posts/`, named after the article's
`translationKey`. The article template automatically displays it above the title
in both languages. No frontmatter image field or Markdown image is needed.
Articles without a matching file display normally, without an empty placeholder.
File names are case-sensitive; use the exact translation key and `.webp` extension.

For example, both translations of the grill-me article use
`translationKey: grill-me-before-coding`, so their shared cover is:

```text
public/images/posts/grill-me-before-coding.webp
```

Prepare all covers at **1600 × 900 pixels (16:9)** and export as WebP, ideally
under 300 KB. Verify dimensions after AI generation and resize or crop before
adding the file. The template reserves a 16:9 area to prevent layout shifts,
scales it to the article width on every screen, and crops other aspect ratios
to fit. It does not convert files or enforce their source pixel dimensions.
Keep important elements away from the edges. Use a consistent illustration
style and palette, without text, logos, or watermarks, so one image works in
both languages. These covers are decorative introductions to the article;
their empty alternative text avoids repeating the adjacent article title.
Keep any information needed to understand the article in its text.

Reusable generation prompt (replace the bracketed subjects):

> Crea una copertina editoriale per un articolo su [ARGOMENTO]. Illustrazione
> vettoriale con contorni netti, forme semplici, palette coerente e composizione
> orizzontale. Rappresenta visivamente [CONCETTO PRINCIPALE]. Nessun testo,
> lettering, logo o watermark. Rapporto 16:9, dimensioni finali 1600 × 900 pixel.

Run `npm run dev` to inspect the cover, then `npm run verify`. Adding or replacing
a cover on the published site requires a new build and deployment, like other
content changes. Covers appear on individual articles; list cards remain text-only.

### Article contents

Articles with at least one Markdown `##` or `###` heading automatically show an
Expand Down
Empty file added public/images/posts/.gitkeep
Empty file.
Binary file added public/images/posts/grill-me-before-coding.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/lib/covers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const covers = import.meta.glob<string>('/public/images/posts/*.webp', {
eager: true,
query: '?url&no-inline',
import: 'default',
});

/** Resolve one shared cover for all translations from the build's asset list. */
export function postCoverUrl(translationKey: string): string | undefined {
const filename = `${translationKey}.webp`;
return covers[`/public/images/posts/${filename}`];
}
3 changes: 3 additions & 0 deletions src/pages/[lang]/blog/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TableOfContents from '../../../components/TableOfContents.astro';
import AuthorLink from '../../../components/AuthorLink.astro';
import { visiblePosts, postUrl, readingMinutes, formatDate, type Post } from '../../../lib/posts';
import { tagUrl } from '../../../lib/tags';
import { postCoverUrl } from '../../../lib/covers';
export async function getStaticPaths() {
return (await visiblePosts()).map((post) => ({
params: { lang: post.data.lang, slug: post.data.urlSlug },
Expand All @@ -15,6 +16,7 @@ export async function getStaticPaths() {
const { post } = Astro.props as { post: Post };
const { Content, headings } = await render(post);
const { lang } = post.data;
const coverUrl = postCoverUrl(post.data.translationKey);
const related = (await visiblePosts()).filter((item) => item.data.translationKey === post.data.translationKey);
const alternatives = related.map((item) => ({ lang: item.data.lang, url: postUrl(item) }));
const toc = headings.filter((heading) => heading.depth === 2 || heading.depth === 3);
Expand All @@ -25,6 +27,7 @@ const tocLabel = lang === 'it' ? 'Indice' : 'Contents';
<article class="post-single">
<a class="back-link" href={`/${lang}/`}>← {lang === 'it' ? 'Tutti gli articoli' : 'All posts'}</a>
<header class="post-header">
{coverUrl && <img class="post-cover" src={coverUrl} alt="" width="1600" height="900" loading="eager" fetchpriority="high" />}
<h1>{post.data.title}</h1>
<p class="post-description">{post.data.description}</p>
<div class="post-meta">
Expand Down
1 change: 1 addition & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ main:focus { outline: none; }
#search-count { margin: 16px 0 24px; font-size: 13px; }
.back-link { display: inline-block; color: var(--muted); font-size: 13px; margin-bottom: 32px; }
.post-header { margin-bottom: 36px; }
.post-cover { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; margin-bottom: 24px; }
.post-description { color: var(--muted); font-size: 18px; margin-bottom: 20px; }
.translation-link { font-size: 13px; margin: 14px 0 0; }
.table-of-contents, .faq-list details { border: 1px solid var(--border); background: var(--surface); padding: 18px 22px; border-radius: 8px; margin: 24px 0; }
Expand Down
Loading