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
135 changes: 118 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,139 @@
# Astro bilingual blog
# Code Geeks

A minimal teaching starter for a public `<username>.github.io` repository.
A bilingual Italian/English blog about AI, code, and technology, built with Astro
and published as static files, with a reading-focused layout, chronological
archive, and browsing by topic.

The site includes light/dark themes, article metadata and tables of contents,
language-aware navigation, full-text search, and an empty About page. FAQ and
social links are prepared in the code and disabled until their content is ready.

## Setup

1. Install Node.js 24 and Git.
2. Replace `YOUR_USERNAME` in `astro.config.mjs` with your GitHub username.
3. Run `npm ci` and `npm run dev`.
4. Visit http://localhost:4321/it/ or http://localhost:4321/en/.
5. Run `npm run verify` before committing.
6. Commit all sources, including `package-lock.json` and `.github/workflows/site.yml`.
7. In repository Settings > Pages, choose GitHub Actions as source.
2. Run `npm ci` and `npm run dev`.
3. Visit http://localhost:4321/it/ or http://localhost:4321/en/.
4. Run `npm run verify` before committing; it runs Astro checks and a production build.
5. Use `npm run preview` to inspect the production output locally.
6. Include all sources, `package-lock.json`, and `.github/workflows/site.yml` in pull requests.
7. In repository Settings > Pages, choose GitHub Actions as the source.

The configured production URL in `astro.config.mjs` is
`https://CodeGeeksAI.github.io`. The root URL redirects to `/it/`.

## Pages and languages

Each language has these routes, where `lang` is `it` or `en`:

| Route | Content |
| --- | --- |
| `/{lang}/` | Articles, newest first |
| `/{lang}/blog/{urlSlug}/` | Individual article |
| `/{lang}/archive/` | Articles grouped by year and month |
| `/{lang}/tags/` | Alphabetical tag list with article counts |
| `/{lang}/tags/{tag}/` | Articles with a specific tag |
| `/{lang}/search/` | Search within the current language |
| `/{lang}/about/` | Chi siamo / About us |

The header language switch opens the corresponding page or article translation
when it exists. If no visible counterpart exists, it opens the selected language's
home page. Articles also link directly to their available translation. Publishing
one language before the other is supported.

## Content

Write Markdown in `src/content/posts/it/` and `src/content/posts/en/`.
Use the same `translationKey` for translations, and a distinct `urlSlug` in each language.
Set `draft: false` to include a post in production. Development includes drafts.
The repository includes one published example in each language and one Italian
draft; replace these with your own articles when ready.
For example, an Italian article can start with:

```yaml
---
title: "Capire i modelli linguistici"
description: "Un'introduzione ai modelli linguistici con esempi verificabili."
pubDate: 2026-10-03
lang: it
translationKey: understanding-language-models
urlSlug: capire-i-modelli-linguistici
tags: [ai, language-models]
author: Code Geeks
draft: false
---
```

Use the same `translationKey` for the English translation, set `lang: en`, and
choose an English `urlSlug`, such as `understanding-language-models`. The `lang`
value must match the containing folder. Article URLs and translation keys must
be unique within each language; these checks also apply to drafts.

Titles, descriptions, dates, language, translation keys, and URL slugs are required.
`author` defaults to `Code Geeks`, `tags` defaults to an empty list, and `draft`
defaults to `true`. Set `draft: false` to include an article in production.
Development includes drafts; production excludes them from article routes,
lists, archives, search, and tags.
Dates are metadata; they do not schedule publication or hide future-dated posts.
Set `youtubeId` to an 11-character YouTube video ID to show a player.
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.

### Tags

Use canonical English tag identifiers shared across both languages, for example
`ai`, `machine-learning`, and `language-models`. Identifiers must contain only
lowercase ASCII letters, digits, and single hyphens between words; spaces,
uppercase letters, leading/trailing hyphens, and repeated hyphens are rejected.
Duplicate tags on one article are removed automatically.

The identifier is both the displayed label and its URL slug. Reuse the same tags
on an article and its translation so the language switch can open the matching
tag page. Tag counts and listings include only visible articles in the current
language; an Italian article and its English translation do not inflate either
language's count. A tag page is generated only when that language has a visible
article using the tag.

### Search

Search runs in the browser against a static index embedded in the search page.
It includes titles, descriptions, tags, and the Markdown body of visible articles
in that page's language. Queries are case- and accent-insensitive; all search
terms must match. The query is reflected in `?q=` so searches can be bookmarked.
Without JavaScript, the page still lists all articles in the current language.

## About, FAQ, and social links

`src/pages/[lang]/about.astro` contains the shared About page template. Its body is
intentionally empty after the localized heading; replace the source comment with
the team introduction when ready, using `lang` to select Italian or English text.

Site identity, descriptions, and future feature settings live in
`src/config/site.ts`:

- **FAQ:** add `{ question, answer }` entries to `siteConfig.faq.it` and
`siteConfig.faq.en`, then set `siteConfig.features.faq` to `true`. The
`/{lang}/faq/` route and navigation link appear only for languages with entries.
- **Social links:** add `{ label, url }` entries to `siteConfig.socialLinks`, using
`https://` URLs, then set `siteConfig.features.social` to `true`. The same links
appear on both language homepages.

The language links in the header open the language index. A separate link inside
each post opens its translation when a visible counterpart exists.
The starter permits publishing one language before the other.
Both features are currently disabled and their content lists are empty.
Content and configuration changes take effect after rebuilding and deploying
the static site.

## Workflow

Pull requests run type checks and a production build. Pushes to `main` run the
same checks and then deploy to Pages. No pull request preview is hosted.
Make changes on a feature branch, push it, and open a pull request into `main`.
Merging the pull request starts the publishing workflow.
Reviews are configured on GitHub. No AI/editorial review is included.
Protect `main` and require the `Verify` check after its first successful run.
If you work alone, do not require another person's approval.
The active GitHub ruleset requires a pull request for every change to `main`,
including changes by administrators. Only squash merging is enabled; direct
pushes, force pushes, and branch deletion are blocked. No approving review is
required, so a solo maintainer can merge their own pull requests.
The `Verify` workflow runs on every pull request but is not currently configured
as a required status check in the ruleset.

This starter assumes the site is served at the domain root. A project URL such
This site is served at the domain root. A project URL such
as `<username>.github.io/blog/` requires configuring `base` and adapting internal links.

## Verification and dependency status
Expand Down
1 change: 1 addition & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/components/PostCard.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
import { postUrl, formatDate, readingMinutes, type Post } from '../lib/posts';
import { tagUrl } from '../lib/tags';
interface Props { post: Post; }
const { post } = Astro.props;
const { lang } = post.data;
---
<article class="post-card">
{post.data.draft && <span class="draft">{lang === 'it' ? 'Bozza · solo in sviluppo' : 'Draft · development only'}</span>}
<h2><a href={postUrl(post)}>{post.data.title}</a></h2>
<p class="post-excerpt">{post.data.description}</p>
<div class="post-meta">
<time datetime={post.data.pubDate.toISOString()}>{formatDate(post.data.pubDate, lang)}</time>
<span aria-hidden="true">·</span>
<span>{readingMinutes(post)} {lang === 'it' ? 'min di lettura' : 'min read'}</span>
<span aria-hidden="true">·</span>
<span>{post.data.author}</span>
</div>
{post.data.tags.length > 0 && <ul class="post-tags" aria-label="Tags">
{post.data.tags.map((tag) => <li><a href={tagUrl(lang, tag)} rel="tag">{tag}</a></li>)}
</ul>}
</article>
11 changes: 11 additions & 0 deletions src/components/SocialLinks.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
import { siteConfig } from '../config/site';
import type { Language } from '../lib/posts';
interface Props { lang: Language; }
const { lang } = Astro.props;
---
{siteConfig.features.social && siteConfig.socialLinks.length > 0 && (
<nav class="social-links" aria-label={lang === 'it' ? 'Seguici' : 'Follow us'}>
{siteConfig.socialLinks.map((link) => <a href={link.url} rel="me">{link.label}<span aria-hidden="true"> ↗</span></a>)}
</nav>
)}
19 changes: 19 additions & 0 deletions src/config/site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Language } from '../lib/posts';

type SocialLink = { label: string; url: `https://${string}` };
type FaqEntry = { question: string; answer: string };

export const siteConfig = {
name: 'Code Geeks',
description: {
it: 'Idee, esperimenti e appunti su intelligenza artificiale, codice e tecnologia.',
en: 'Ideas, experiments and notes on artificial intelligence, code and technology.',
},
// Enable these when their content is ready. No empty links are rendered.
features: { faq: false, social: false },
socialLinks: [] as SocialLink[],
faq: { it: [], en: [] } as Record<Language, FaqEntry[]>,
};

export const hasFaq = (lang: Language) =>
siteConfig.features.faq && siteConfig.faq[lang].length > 0;
9 changes: 9 additions & 0 deletions src/content.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const posts = defineCollection({
lang: z.enum(['it', 'en']),
translationKey: z.string().min(1),
urlSlug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
tags: z
.array(
z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, {
message: 'Tags must use lowercase kebab-case, for example: machine-learning.',
}),
)
.default([])
.transform((tags) => [...new Set(tags)]),
author: z.string().trim().min(1).default('Code Geeks'),
draft: z.boolean().default(true),
youtubeId: z.string().regex(/^[A-Za-z0-9_-]{11}$/).optional(),
}),
Expand Down
1 change: 1 addition & 0 deletions src/content/posts/en/first-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pubDate: 2026-10-03
lang: en
translationKey: primo-post
urlSlug: first-post
tags: [ai, technology]
draft: false
---

Expand Down
1 change: 1 addition & 0 deletions src/content/posts/it/bozza-esempio.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pubDate: 2026-10-03
lang: it
translationKey: bozza-esempio
urlSlug: bozza-esempio
tags: [ai]
draft: true
---

Expand Down
1 change: 1 addition & 0 deletions src/content/posts/it/primo-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pubDate: 2026-10-03
lang: it
translationKey: primo-post
urlSlug: primo-post
tags: [ai, technology]
draft: false
---

Expand Down
103 changes: 76 additions & 27 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
@@ -1,49 +1,98 @@
---
import type { Language } from '../lib/posts';
import { languages, type Language } from '../lib/posts';
import { siteConfig, hasFaq } from '../config/site';
import '../styles/global.css';

interface Props {
title: string;
description: string;
lang: Language;
alternatives?: { lang: Language; url: string }[];
activeNav?: 'posts' | 'archive' | 'search' | 'tags' | 'about' | 'faq';
}
const { title, description, lang, alternatives = [] } = Astro.props;
const { title, description, lang, alternatives = [], activeNav } = Astro.props;
const canonical = new URL(Astro.url.pathname, Astro.site);
const labels = lang === 'it'
? { posts: 'Articoli', archive: 'Archivio', search: 'Cerca', tags: 'Tags', about: 'Chi siamo', faq: 'FAQ', nav: 'Navigazione principale', languages: 'Lingua', skip: 'Vai al contenuto', theme: 'Tema scuro' }
: { posts: 'Posts', archive: 'Archive', search: 'Search', tags: 'Tags', about: 'About us', faq: 'FAQ', nav: 'Main navigation', languages: 'Language', skip: 'Skip to content', theme: 'Dark theme' };
const navigation = [
{ key: 'posts', url: `/${lang}/` },
{ key: 'archive', url: `/${lang}/archive/` },
{ key: 'search', url: `/${lang}/search/` },
{ key: 'tags', url: `/${lang}/tags/` },
{ key: 'about', url: `/${lang}/about/` },
...(hasFaq(lang) ? [{ key: 'faq', url: `/${lang}/faq/` }] : []),
] as { key: keyof typeof labels; url: string }[];
---
<!doctype html>
<html lang={lang}>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title} | AI & Technology</title>
<meta name="color-scheme" content="light dark" />
<title>{title} | {siteConfig.name}</title>
<meta name="description" content={description} />
<meta property="og:site_name" content={siteConfig.name} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:url" content={canonical} />
<meta property="og:locale" content={lang === 'it' ? 'it_IT' : 'en_US'} />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="canonical" href={canonical} />
{alternatives.map((item) => <link rel="alternate" hreflang={item.lang} href={new URL(item.url, Astro.site)} />)}
<script is:inline>
(() => {
let theme;
try { theme = localStorage.getItem('code-geeks-theme'); } catch {}
document.documentElement.dataset.theme = theme === 'dark' || theme === 'light'
? theme : (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
})();
</script>
</head>
<body>
<header>
<a href={`/${lang}/`}><strong>AI & Technology</strong></a>
<nav aria-label={lang === 'it' ? 'Lingue' : 'Languages'}>
<a href="/it/" lang="it">Italiano</a>
<a href="/en/" lang="en">English</a>
</nav>
<a class="skip-link" href="#main">{labels.skip}</a>
<header class="site-header">
<div class="header-inner">
<div class="brand-tools">
<a class="brand" href={`/${lang}/`}>{siteConfig.name}<span class="brand-dot" aria-hidden="true">.</span></a>
<button id="theme-toggle" class="theme-toggle" type="button" aria-label={labels.theme} aria-pressed="false" hidden>
<svg class="moon-icon" width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="M20.7 13.1A9 9 0 0 1 10.9 3.3 9 9 0 1 0 20.7 13.1Z" /></svg>
<svg class="sun-icon" width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><circle cx="12" cy="12" r="4" /><path d="M12 2v2m0 16v2M2 12h2m16 0h2M5 5l1.5 1.5m11 11L19 19M5 19l1.5-1.5m11-11L19 5" /></svg>
</button>
</div>
<nav class="main-nav" aria-label={labels.nav}>
{navigation.map((item) => <a href={item.url} aria-current={activeNav === item.key ? (Astro.url.pathname === item.url ? 'page' : 'true') : undefined}>{labels[item.key]}</a>)}
</nav>
<nav class="language-nav" aria-label={labels.languages}>
{languages.map((language) => {
const translation = alternatives.find((item) => item.lang === language);
const url = translation?.url ?? `/${language}/`;
const name = language === 'it' ? 'Italiano' : 'English';
return <a href={url} lang={language} hreflang={language} aria-label={name}
title={translation ? name : `${name} · ${language === 'it' ? 'Pagina iniziale' : 'Home page'}`}
aria-current={language === lang ? 'true' : undefined}>{language.toUpperCase()}</a>;
})}
</nav>
</div>
</header>
<main><slot /></main>
<footer>AI & Technology · Italiano / English</footer>
<main id="main" tabindex="-1"><slot /></main>
<footer class="site-footer">
<span>© {new Date().getFullYear()} <a href={`/${lang}/`}>{siteConfig.name}</a></span>
<span>Italiano / English</span>
</footer>
<script>
const toggle = document.querySelector<HTMLButtonElement>('#theme-toggle');
if (toggle) {
toggle.hidden = false;
const syncToggle = () => toggle.setAttribute('aria-pressed', String(document.documentElement.dataset.theme === 'dark'));
syncToggle();
toggle.addEventListener('click', () => {
const theme = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
document.documentElement.dataset.theme = theme;
try { localStorage.setItem('code-geeks-theme', theme); } catch {}
syncToggle();
});
}
</script>
</body>
</html>
<style is:global>
:root { font-family: system-ui, sans-serif; color: #172335; background: #fafbfc; }
body { max-width: 800px; margin: auto; padding: 24px; line-height: 1.75; }
header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; border-bottom: 1px solid #dce2ea; padding-bottom: 20px; }
nav { display: flex; gap: 18px; }
main { min-height: 65vh; padding: 32px 0; }
a { color: #185eb4; text-underline-offset: 4px; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: clamp(2rem, 5vw, 3rem); }
img { max-width: 100%; height: auto; }
pre { overflow-x: auto; padding: 16px; border-radius: 8px; }
code { font-size: 0.9em; }
footer { border-top: 1px solid #dce2ea; padding-top: 20px; color: #536078; }
.muted { color: #536078; }
.draft { color: #8a4800; background: #fff1d6; padding: 8px 12px; }
</style>
Loading
Loading