diff --git a/README.md b/README.md index 5a9c1a3..7091c31 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,139 @@ -# Astro bilingual blog +# Code Geeks -A minimal teaching starter for a public `.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 `.github.io/blog/` requires configuring `base` and adapting internal links. ## Verification and dependency status diff --git a/public/favicon.svg b/public/favicon.svg new file mode 100644 index 0000000..7ef1424 --- /dev/null +++ b/public/favicon.svg @@ -0,0 +1 @@ + diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro new file mode 100644 index 0000000..fa3b893 --- /dev/null +++ b/src/components/PostCard.astro @@ -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; +--- +
+ {post.data.draft && {lang === 'it' ? 'Bozza · solo in sviluppo' : 'Draft · development only'}} +

{post.data.title}

+

{post.data.description}

+ + {post.data.tags.length > 0 && } +
diff --git a/src/components/SocialLinks.astro b/src/components/SocialLinks.astro new file mode 100644 index 0000000..d3d7416 --- /dev/null +++ b/src/components/SocialLinks.astro @@ -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 && ( + +)} diff --git a/src/config/site.ts b/src/config/site.ts new file mode 100644 index 0000000..bda0f2f --- /dev/null +++ b/src/config/site.ts @@ -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, +}; + +export const hasFaq = (lang: Language) => + siteConfig.features.faq && siteConfig.faq[lang].length > 0; diff --git a/src/content.config.ts b/src/content.config.ts index a845ac5..cc5a7c0 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -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(), }), diff --git a/src/content/posts/en/first-post.md b/src/content/posts/en/first-post.md index 232e3c6..3ca6ff7 100644 --- a/src/content/posts/en/first-post.md +++ b/src/content/posts/en/first-post.md @@ -5,6 +5,7 @@ pubDate: 2026-10-03 lang: en translationKey: primo-post urlSlug: first-post +tags: [ai, technology] draft: false --- diff --git a/src/content/posts/it/bozza-esempio.md b/src/content/posts/it/bozza-esempio.md index dcaadc8..4be47be 100644 --- a/src/content/posts/it/bozza-esempio.md +++ b/src/content/posts/it/bozza-esempio.md @@ -5,6 +5,7 @@ pubDate: 2026-10-03 lang: it translationKey: bozza-esempio urlSlug: bozza-esempio +tags: [ai] draft: true --- diff --git a/src/content/posts/it/primo-post.md b/src/content/posts/it/primo-post.md index 0a38d41..e0c1028 100644 --- a/src/content/posts/it/primo-post.md +++ b/src/content/posts/it/primo-post.md @@ -5,6 +5,7 @@ pubDate: 2026-10-03 lang: it translationKey: primo-post urlSlug: primo-post +tags: [ai, technology] draft: false --- diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index a929d8f..916a15a 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -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 }[]; --- - {title} | AI & Technology + + {title} | {siteConfig.name} + + + + + + {alternatives.map((item) => )} + -
- AI & Technology - + + -
-
AI & Technology · Italiano / English
+
+ + - diff --git a/src/lib/posts.ts b/src/lib/posts.ts index c11b5b3..7a20efe 100644 --- a/src/lib/posts.ts +++ b/src/lib/posts.ts @@ -5,6 +5,20 @@ export type Language = 'it' | 'en'; export const languages: Language[] = ['it', 'en']; export const postUrl = (post: Post) => `/${post.data.lang}/blog/${post.data.urlSlug}/`; +export function readingMinutes(post: Post): number { + const words = (post.body ?? '').match(/\S+/g)?.length ?? 0; + return Math.max(1, Math.ceil(words / 200)); +} + +export function formatDate(date: Date, lang: Language): string { + return new Intl.DateTimeFormat(lang === 'it' ? 'it-IT' : 'en-GB', { + day: 'numeric', + month: 'long', + year: 'numeric', + timeZone: 'UTC', + }).format(date); +} + export async function visiblePosts() { const posts = await getCollection('posts'); const routes = new Set(); diff --git a/src/lib/tags.ts b/src/lib/tags.ts new file mode 100644 index 0000000..158431e --- /dev/null +++ b/src/lib/tags.ts @@ -0,0 +1,26 @@ +import type { Language, Post } from './posts'; + +export interface Tag { + name: string; + slug: string; + count: number; +} + +/** Tag identifiers are shared across translations and validated by the content schema. */ +export function getTags(posts: readonly Post[]): Tag[] { + const counts = new Map(); + for (const post of posts) { + for (const tag of new Set(post.data.tags)) { + counts.set(tag, (counts.get(tag) ?? 0) + 1); + } + } + return [...counts.entries()] + .sort(([a], [b]) => a.localeCompare(b, 'en')) + .map(([tag, count]) => ({ name: tag, slug: tag, count })); +} + +export const tagUrl = (lang: Language, tag: string): string => `/${lang}/tags/${tag}/`; + +export function postsForTag(posts: readonly Post[], lang: Language, tag: string): Post[] { + return posts.filter((post) => post.data.lang === lang && post.data.tags.includes(tag)); +} diff --git a/src/pages/[lang]/about.astro b/src/pages/[lang]/about.astro new file mode 100644 index 0000000..720d1e4 --- /dev/null +++ b/src/pages/[lang]/about.astro @@ -0,0 +1,24 @@ +--- +import Base from '../../layouts/Base.astro'; +import { languages, type Language } from '../../lib/posts'; + +export function getStaticPaths() { + return languages.map((lang) => ({ params: { lang }, props: { lang } })); +} + +const { lang } = Astro.props as { lang: Language }; +const title = lang === 'it' ? 'Chi siamo' : 'About us'; +--- + + ({ lang: language, url: `/${language}/about/` }))} +> + + + diff --git a/src/pages/[lang]/archive.astro b/src/pages/[lang]/archive.astro new file mode 100644 index 0000000..1bcdb7f --- /dev/null +++ b/src/pages/[lang]/archive.astro @@ -0,0 +1,74 @@ +--- +import Base from '../../layouts/Base.astro'; +import { languages, visiblePosts, postUrl, type Language, type Post } from '../../lib/posts'; + +export function getStaticPaths() { + return languages.map((lang) => ({ params: { lang }, props: { lang } })); +} + +const { lang } = Astro.props as { lang: Language }; +const posts = (await visiblePosts()).filter((post) => post.data.lang === lang); +const title = lang === 'it' ? 'Archivio' : 'Archive'; +const description = lang === 'it' + ? 'Tutti gli articoli di Code Geeks, ordinati per anno e mese.' + : 'All Code Geeks articles, organized by year and month.'; +const years = new Map>(); + +for (const post of posts) { + const year = post.data.pubDate.getUTCFullYear(); + const month = post.data.pubDate.getUTCMonth(); + if (!years.has(year)) years.set(year, new Map()); + const months = years.get(year)!; + if (!months.has(month)) months.set(month, []); + months.get(month)!.push(post); +} + +const articleCount = (count: number) => lang === 'it' + ? `${count} ${count === 1 ? 'articolo' : 'articoli'}` + : `${count} ${count === 1 ? 'article' : 'articles'}`; +--- + + ({ lang: language, url: `/${language}/archive/` }))} +> + + + {posts.length === 0 && ( +

{lang === 'it' ? 'Nessun articolo pubblicato.' : 'No published articles yet.'}

+ )} + + {[...years].map(([year, months]) => ( +
+

+ {year} ({articleCount([...months.values()].reduce((count, entries) => count + entries.length, 0))}) +

+ {[...months].map(([month, entries]) => ( +
+

+ {new Date(Date.UTC(year, month, 1)).toLocaleDateString(lang, { month: 'long', timeZone: 'UTC' })} + ({entries.length}) +

+
    + {entries.map((post) => ( +
  • + + {post.data.title} + {post.data.draft && {lang === 'it' ? 'Bozza' : 'Draft'}} +
  • + ))} +
+
+ ))} +
+ ))} + diff --git a/src/pages/[lang]/blog/[slug].astro b/src/pages/[lang]/blog/[slug].astro index 6e7481e..6cfb3a0 100644 --- a/src/pages/[lang]/blog/[slug].astro +++ b/src/pages/[lang]/blog/[slug].astro @@ -2,7 +2,8 @@ import { render } from 'astro:content'; import Base from '../../../layouts/Base.astro'; import YouTube from '../../../components/YouTube.astro'; -import { visiblePosts, postUrl, type Post } from '../../../lib/posts'; +import { visiblePosts, postUrl, readingMinutes, formatDate, type Post } from '../../../lib/posts'; +import { tagUrl } from '../../../lib/tags'; export async function getStaticPaths() { return (await visiblePosts()).map((post) => ({ params: { lang: post.data.lang, slug: post.data.urlSlug }, @@ -10,19 +11,37 @@ export async function getStaticPaths() { })); } const { post } = Astro.props as { post: Post }; -const { Content } = await render(post); +const { Content, headings } = await render(post); +const { lang } = post.data; 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); --- - -
-

{post.data.title}

-

- {post.data.draft &&

{post.data.lang === 'it' ? 'Bozza: non viene pubblicata' : 'Draft: excluded from publication'}

} - {related.filter((item) => item.id !== post.id).map((item) => ( -

{item.data.lang === 'it' ? 'Leggi questo articolo in italiano' : 'Read this article in English'}

- ))} + +
+ ← {lang === 'it' ? 'Tutti gli articoli' : 'All posts'} +
+

{post.data.title}

+

{post.data.description}

+ + {post.data.draft &&

{lang === 'it' ? 'Bozza: non viene pubblicata' : 'Draft: excluded from publication'}

} + {related.filter((item) => item.id !== post.id).map((item) => ( + + ))} + {post.data.tags.length > 0 && } +
+ {toc.length > 1 &&
+ {lang === 'it' ? 'In questo articolo' : 'On this page'} + +
} {post.data.youtubeId && } - +
diff --git a/src/pages/[lang]/faq.astro b/src/pages/[lang]/faq.astro new file mode 100644 index 0000000..3b34efe --- /dev/null +++ b/src/pages/[lang]/faq.astro @@ -0,0 +1,17 @@ +--- +import Base from '../../layouts/Base.astro'; +import { siteConfig, hasFaq } from '../../config/site'; +import { languages, type Language } from '../../lib/posts'; +export function getStaticPaths() { + return languages.filter(hasFaq).map((lang) => ({ params: { lang }, props: { lang } })); +} +const { lang } = Astro.props as { lang: Language }; +const title = lang === 'it' ? 'Domande frequenti' : 'Frequently asked questions'; +--- + ({ lang: language, url: `/${language}/faq/` }))}> + +
+ {siteConfig.faq[lang].map((entry) =>
{entry.question}

{entry.answer}

)} +
+ diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index 3ac6011..fd4f082 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -1,23 +1,43 @@ --- import Base from '../../layouts/Base.astro'; -import { languages, visiblePosts, postUrl, type Language } from '../../lib/posts'; +import PostCard from '../../components/PostCard.astro'; +import SocialLinks from '../../components/SocialLinks.astro'; +import { siteConfig } from '../../config/site'; +import { languages, visiblePosts, type Language } from '../../lib/posts'; +import { getTags, tagUrl } from '../../lib/tags'; export function getStaticPaths() { return languages.map((lang) => ({ params: { lang }, props: { lang } })); } const { lang } = Astro.props as { lang: Language }; const posts = (await visiblePosts()).filter((post) => post.data.lang === lang); -const title = lang === 'it' ? 'Articoli' : 'Articles'; +const tags = getTags(posts); +const title = lang === 'it' ? 'Articoli' : 'Posts'; --- - ({ lang: language, url: `/${language}/` }))}> -

{title}

- {posts.length === 0 &&

{lang === 'it' ? 'Nessun articolo pubblicato.' : 'No published articles yet.'}

} - {posts.map((post) => ( -
-

{post.data.title}

-

- {post.data.draft &&

{lang === 'it' ? 'Bozza: visibile solo in sviluppo' : 'Draft: only visible in development'}

} -

{post.data.description}

-
- ))} +
+

{lang === 'it' ? 'AI, codice e tecnologia' : 'AI, code and technology'}

+

{lang === 'it' ? 'Benvenuti su Code Geeks.' : 'Welcome to Code Geeks.'}

+

{lang === 'it' ? 'Uno spazio per condividere idee, esplorare la tecnologia e raccontare ciò che impariamo, un esperimento alla volta.' : 'A space to share ideas, explore technology and document what we learn, one experiment at a time.'}

+ +
+
+
+

{lang === 'it' ? 'Ultimi articoli' : 'Latest posts'}

+ {lang === 'it' ? 'Archivio' : 'Archive'} +
+
+ {posts.length === 0 &&

{lang === 'it' ? 'Nessun articolo pubblicato.' : 'No published posts yet.'}

} + {posts.map((post) => )} +
+
+ {tags.length > 0 &&
+
+

{lang === 'it' ? 'Esplora per tag' : 'Explore by tag'}

+ {lang === 'it' ? 'Tutti i tag' : 'All tags'} +
+ +
} diff --git a/src/pages/[lang]/search.astro b/src/pages/[lang]/search.astro new file mode 100644 index 0000000..bc09b6c --- /dev/null +++ b/src/pages/[lang]/search.astro @@ -0,0 +1,119 @@ +--- +import Base from '../../layouts/Base.astro'; +import PostCard from '../../components/PostCard.astro'; +import { languages, visiblePosts, type Language } from '../../lib/posts'; + +export function getStaticPaths() { + return languages.map((lang) => ({ params: { lang }, props: { lang } })); +} + +const { lang } = Astro.props as { lang: Language }; +const posts = (await visiblePosts()).filter((post) => post.data.lang === lang); +const title = lang === 'it' ? 'Cerca' : 'Search'; +const description = lang === 'it' + ? 'Cerca nei titoli, nei tag e nel testo degli articoli in italiano.' + : 'Search titles, tags, and the full text of articles in English.'; +const initialCount = lang === 'it' + ? `${posts.length} ${posts.length === 1 ? 'articolo' : 'articoli'}` + : `${posts.length} ${posts.length === 1 ? 'article' : 'articles'}`; +--- + + ({ lang: language, url: `/${language}/search/` }))} +> + + +
+
+ + +
+ + + +

{initialCount}

+
+ {posts.map((post) => ( +
+ +
+ ))} +
+ +
+ + + + + diff --git a/src/pages/[lang]/tags/[tag].astro b/src/pages/[lang]/tags/[tag].astro new file mode 100644 index 0000000..bcf937a --- /dev/null +++ b/src/pages/[lang]/tags/[tag].astro @@ -0,0 +1,40 @@ +--- +import Base from '../../../layouts/Base.astro'; +import PostCard from '../../../components/PostCard.astro'; +import { languages, visiblePosts, type Language } from '../../../lib/posts'; +import { getTags, tagUrl, postsForTag } from '../../../lib/tags'; + +export async function getStaticPaths() { + const posts = await visiblePosts(); + return languages.flatMap((lang) => getTags(posts.filter((post) => post.data.lang === lang)) + .map((tag) => ({ params: { lang, tag: tag.slug }, props: { lang, tag: tag.name } }))); +} + +const { lang, tag } = Astro.props as { lang: Language; tag: string }; +const allPosts = await visiblePosts(); +const posts = postsForTag(allPosts, lang, tag); +const alternatives = languages + .filter((language) => postsForTag(allPosts, language, tag).length > 0) + .map((language) => ({ lang: language, url: tagUrl(language, tag) })); +const description = lang === 'it' + ? `Articoli di Code Geeks con il tag ${tag}.` + : `Code Geeks articles tagged ${tag}.`; +const count = lang === 'it' + ? `${posts.length} ${posts.length === 1 ? 'articolo' : 'articoli'}` + : `${posts.length} ${posts.length === 1 ? 'article' : 'articles'}`; +--- + + + + +
+ {posts.map((post) => )} +
+ {posts.length === 0 && ( +

{lang === 'it' ? 'Nessun articolo con questo tag.' : 'No articles with this tag.'}

+ )} + diff --git a/src/pages/[lang]/tags/index.astro b/src/pages/[lang]/tags/index.astro new file mode 100644 index 0000000..d6261f8 --- /dev/null +++ b/src/pages/[lang]/tags/index.astro @@ -0,0 +1,45 @@ +--- +import Base from '../../../layouts/Base.astro'; +import { languages, visiblePosts, type Language } from '../../../lib/posts'; +import { getTags, tagUrl } from '../../../lib/tags'; + +export function getStaticPaths() { + return languages.map((lang) => ({ params: { lang }, props: { lang } })); +} + +const { lang } = Astro.props as { lang: Language }; +const posts = (await visiblePosts()).filter((post) => post.data.lang === lang); +const tags = getTags(posts); +const title = 'Tag'; +const description = lang === 'it' + ? 'Esplora gli articoli di Code Geeks per argomento.' + : 'Explore Code Geeks articles by topic.'; +--- + + ({ lang: language, url: `/${language}/tags/` }))} +> + + + {tags.length === 0 ? ( +

{lang === 'it' ? 'I tag appariranno con i primi articoli.' : 'Tags will appear with the first articles.'}

+ ) : ( + + )} + diff --git a/src/pages/index.astro b/src/pages/index.astro index 888a006..81893d9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,9 +1,3 @@ --- -import Base from '../layouts/Base.astro'; +return Astro.redirect('/it/'); --- - -

AI & Technology

-

Idee, esperimenti e spiegazioni su AI e tecnologia.

-

Ideas, experiments and explanations about AI and technology.

-

Leggi in italiano · Read in English

- diff --git a/src/styles/global.css b/src/styles/global.css new file mode 100644 index 0000000..13b10c7 --- /dev/null +++ b/src/styles/global.css @@ -0,0 +1,162 @@ +:root { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; + --bg: #f5f5f5; + --surface: #fff; + --text: #242424; + --muted: #646464; + --border: #e5e5e5; + --tag: #ebebeb; + --focus: #3367a7; + color-scheme: light; + color: var(--text); + background: var(--bg); + font-synthesis: none; + -webkit-font-smoothing: antialiased; +} +:root[data-theme='dark'] { + --bg: #1d1e20; + --surface: #292a2d; + --text: #e8e8e8; + --muted: #aeafb1; + --border: #36373a; + --tag: #343538; + --focus: #94bdf0; + color-scheme: dark; +} +@media (prefers-color-scheme: dark) { + :root:not([data-theme]) { + --bg: #1d1e20; + --surface: #292a2d; + --text: #e8e8e8; + --muted: #aeafb1; + --border: #36373a; + --tag: #343538; + --focus: #94bdf0; + color-scheme: dark; + } +} +* { box-sizing: border-box; } +[hidden] { display: none !important; } +html { scroll-padding-top: 24px; } +body { margin: 0; min-height: 100svh; display: flex; flex-direction: column; font-size: 16px; line-height: 1.65; } +a { color: inherit; text-decoration: none; text-underline-offset: 4px; } +a:hover { text-decoration: underline; } +a, button, input, summary { -webkit-tap-highlight-color: transparent; } +:focus-visible { outline: 2px solid var(--focus); outline-offset: 5px; border-radius: 3px; } +button, input { font: inherit; } +button, summary { cursor: pointer; } +button { color: inherit; } +h1, h2, h3, h4 { line-height: 1.25; text-wrap: balance; } +h1 { margin: 0 0 20px; font-size: clamp(2rem, 4.5vw, 2.65rem); letter-spacing: -1.25px; } +h2 { font-size: 1.55rem; letter-spacing: -.5px; } +h3 { font-size: 1.2rem; } +p { margin: 0 0 1em; } +img { max-width: 100%; height: auto; } +svg { flex-shrink: 0; } +.muted { color: var(--muted); } +.skip-link { position: absolute; top: -100px; left: 16px; z-index: 10; background: var(--surface); border: 1px solid var(--border); padding: 10px 16px; } +.skip-link:focus { top: 8px; } +.header-inner { max-width: 1096px; min-height: 88px; margin: auto; padding: 12px 28px; display: flex; align-items: center; gap: 30px; } +.brand-tools { display: flex; align-items: center; gap: 10px; flex-shrink: 0; } +.brand { font-size: 25px; font-weight: 760; letter-spacing: -.9px; white-space: nowrap; } +.brand:hover { text-decoration: none; } +.brand-dot { color: var(--muted); } +.theme-toggle { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%; padding: 0; background: transparent; } +.theme-toggle:hover { background: var(--tag); } +.sun-icon, [data-theme='dark'] .moon-icon { display: none; } +[data-theme='dark'] .sun-icon { display: block; } +.main-nav { display: flex; align-items: center; gap: 24px; margin-left: auto; font-size: 14px; } +.main-nav a { white-space: nowrap; padding: 7px 0; } +.main-nav a[aria-current] { font-weight: 650; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 7px; } +.language-nav { display: flex; gap: 4px; border-left: 1px solid var(--border); padding-left: 18px; font-size: 12px; letter-spacing: .5px; } +.language-nav a { padding: 5px 7px; color: var(--muted); border-radius: 4px; } +.language-nav a[aria-current] { color: var(--text); background: var(--tag); font-weight: 700; } +main { flex: 1; width: min(100% - 48px, 736px); margin: 0 auto; padding: 52px 0 88px; overflow-wrap: anywhere; } +main:focus { outline: none; } +.home-intro { padding: 12px 0 50px; } +.eyebrow { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 1.6px; text-transform: uppercase; margin: 0 0 16px; } +.home-intro h1 { font-size: clamp(2rem, 4.5vw, 2.55rem); margin-bottom: 18px; } +.home-intro > p:not(.eyebrow) { max-width: 640px; font-size: 17px; line-height: 1.8; color: var(--muted); margin-bottom: 0; } +.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 18px; } +.section-heading h2 { font-size: 12px; letter-spacing: 1.3px; text-transform: uppercase; font-weight: 650; margin: 0; color: var(--muted); } +.section-heading > a { font-size: 13px; color: var(--muted); white-space: nowrap; } +.post-list { display: grid; gap: 24px; } +.post-card { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 28px; } +.post-card h2 { font-size: 24px; margin: 0 0 12px; } +.post-excerpt { font-size: 15px; line-height: 1.75; color: var(--muted); margin-bottom: 18px; } +.post-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px 9px; font-size: 12px; line-height: 1.7; color: var(--muted); } +.post-tags { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; padding: 0; font-size: 12px; } +.post-tags a { display: inline-block; background: var(--tag); border-radius: 4px; padding: 2px 9px; } +.home-topics { margin-top: 44px; padding-top: 26px; border-top: 1px solid var(--border); } +.tag-cloud { display: flex; flex-wrap: wrap; gap: 12px; list-style: none; padding: 0; margin: 0; } +.tag-pill { display: inline-flex; align-items: baseline; gap: 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 9px 16px; font-size: 15px; } +.tag-pill:hover { border-color: var(--muted); text-decoration: none; } +.tag-count { font-size: 11px; font-weight: 600; color: var(--muted); } +.page-header { margin: 12px 0 40px; } +.page-header h1 { margin-bottom: 14px; } +.page-description { color: var(--muted); margin: 0; } +.empty-state { color: var(--muted); padding: 24px 0; } +.archive-year { padding: 8px 0 24px; } +.archive-year > h2 { font-size: 28px; border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-top: 0; } +.archive-year > h2 span { font-size: 13px; font-weight: 400; letter-spacing: normal; margin-left: 8px; } +.archive-month { margin: 28px 0; } +.archive-month h3 { text-transform: capitalize; font-size: 16px; margin-bottom: 18px; } +.archive-month h3 span { font-size: 12px; font-weight: 400; } +.archive-month ul { list-style: none; padding: 0; } +.archive-entry { display: flex; align-items: baseline; gap: 20px; margin: 16px 0; } +.archive-entry time { flex-shrink: 0; min-width: 60px; font-size: 12px; } +.archive-entry a { font-weight: 550; } +[role='search'] label { display: block; font-size: 14px; font-weight: 550; margin-bottom: 8px; } +.search-field { width: 100%; padding: 16px 18px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; } +.search-field::placeholder { color: var(--muted); opacity: 1; } +#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-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; } +.table-of-contents summary, .faq-list summary { font-weight: 600; } +.table-of-contents ul { padding-left: 18px; font-size: 14px; margin-bottom: 0; } +.toc-subheading { margin-left: 18px; } +.faq-list p { margin: 16px 0 0; } +.prose { font-size: 18px; line-height: 1.85; } +.prose h2 { margin: 40px 0 20px; font-size: 28px; } +.prose h3 { margin: 32px 0 16px; font-size: 22px; } +.prose a { text-decoration: underline; } +.prose blockquote { margin: 28px 0; padding-left: 22px; border-left: 3px solid var(--muted); color: var(--muted); } +.prose pre { max-width: 100%; overflow-x: auto; border-radius: 6px; padding: 20px; line-height: 1.7; } +.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82em; } +.prose :not(pre) > code { background: var(--tag); padding: 3px 6px; border-radius: 4px; } +.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 15px; } +.prose th, .prose td { border: 1px solid var(--border); padding: 10px 14px; } +.prose hr { border: 0; border-top: 1px solid var(--border); margin: 36px 0; } +.draft { display: inline-block; font-size: 12px; color: #704805; background: #ffebbd; border-radius: 4px; padding: 3px 8px; margin-bottom: 12px; } +.archive-entry .draft { margin-bottom: 0; } +.social-links { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 24px; font-size: 14px; } +.site-footer { max-width: 736px; width: calc(100% - 48px); margin: 0 auto; padding: 24px 0 30px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; font-size: 12px; color: var(--muted); } +@media (max-width: 850px) { + .header-inner { flex-wrap: wrap; gap: 10px 20px; padding: 16px 24px 8px; } + .brand-tools { flex: 1; } + .language-nav { margin-left: auto; border-left: 0; padding-left: 0; } + .main-nav { order: 3; width: 100%; justify-content: center; flex-wrap: wrap; gap: 8px 24px; padding: 12px 0 4px; } + main { padding-top: 34px; } +} +@media (max-width: 480px) { + .brand { font-size: 23px; } + .header-inner { padding-inline: 20px; } + .main-nav { font-size: 13px; gap: 6px 20px; } + main { width: calc(100% - 40px); padding-bottom: 60px; } + h1 { letter-spacing: -.9px; } + .home-intro { padding-top: 8px; padding-bottom: 36px; } + .home-intro > p:not(.eyebrow) { font-size: 16px; } + .post-card { padding: 22px; } + .post-card h2 { font-size: 22px; } + .post-meta { gap: 4px 7px; } + .post-excerpt { font-size: 14px; } + .archive-entry { flex-wrap: wrap; gap: 5px 12px; } + .prose { font-size: 17px; } + .site-footer { width: calc(100% - 40px); } +} +@media (prefers-reduced-motion: no-preference) { + .tag-pill, .theme-toggle { transition: border-color .15s, background-color .15s; } +}