diff --git a/README.md b/README.md index 9dbd4c5..6ebf10f 100644 --- a/README.md +++ b/README.md @@ -85,10 +85,6 @@ Add server endpoints as Route Handlers in `app/**/route.ts`, using the Web `Requ Use a deployment that supports the Next.js Node.js runtime when adding Route Handlers or request-time server rendering. -## Page transitions - -Internal site links use `components/common/TransitionLink` and `next-transition-router` to finish the current page's exit animation before navigating, then reset scroll and animate the new page in. The shared header and footer stay mounted. Browser Back/Forward uses native navigation and scroll restoration without page transitions. Use the transition-aware Link with `scroll={false}` when adding site navigation; external links and Markdown anchors retain normal browser behavior. - ## Contributing React, Next.js, TypeScript, Tailwind CSS, and basic HTML knowledge are useful. Contributions to content and bug reports are welcome too. diff --git a/WEBSITE_CONFIG.md b/WEBSITE_CONFIG.md index 07c29b6..3228809 100644 --- a/WEBSITE_CONFIG.md +++ b/WEBSITE_CONFIG.md @@ -8,6 +8,10 @@ The home page is a bento grid (`app/page.tsx`, laid out by the `.bento` rules in The map uses [MapLibre](https://maplibre.org/) with [OpenFreeMap](https://openfreemap.org/) tiles; edit `regions` in `components/home/KarnatakaMap.tsx` to change the places in its menu. +## SEO + +It's added now + ## Write a blog post Create `content/posts/your-post.md`: diff --git a/app/authors/[id]/page.tsx b/app/authors/[id]/page.tsx index 795d31f..4a3287d 100644 --- a/app/authors/[id]/page.tsx +++ b/app/authors/[id]/page.tsx @@ -4,8 +4,10 @@ import AuthorCard from '@/components/authors/AuthorCard'; import PostList from '@/components/blog/PostList'; import Breadcrumbs from '@/components/common/Breadcrumbs'; import Container from '@/components/common/Container'; +import JsonLd from '@/components/common/JsonLd'; import { getAllAuthors, getAuthor } from '@/lib/content/authors'; import { getPostsByAuthor } from '@/lib/content/posts'; +import { absoluteUrl, pageMetadata } from '@/lib/seo'; // reference: https://pranavu.dev @@ -28,10 +30,12 @@ export async function generateMetadata({ params, }: AuthorPageProps): Promise { const author = await loadAuthor(params); - return { + return pageMetadata({ title: author.name, description: author.bio ?? `Posts by ${author.name}.`, - }; + path: `/authors/${author.id}`, + openGraph: { type: 'profile' }, + }); } export default async function AuthorPage({ params }: AuthorPageProps) { @@ -40,6 +44,21 @@ export default async function AuthorPage({ params }: AuthorPageProps) { return ( + link.href.startsWith('https://')) + .map((link) => link.href), + }, + }} + /> ({ uid: post.id })); +} + +export default async function Image({ + params, +}: { + params: Promise<{ uid: string }>; +}) { + const post = await getPost((await params).uid); + if (!post) notFound(); + const authors = await resolveAuthors(post.authors); + return ogImage({ + eyebrow: 'Blog', + title: post.title, + subtitle: `${authors + .map((author) => author.name) + .join(', ')} · ${formatDate(post.publishDate)} · ${post.readingTime}`, + }); +} diff --git a/app/blog/[uid]/page.tsx b/app/blog/[uid]/page.tsx index 34fd0a7..96998bc 100644 --- a/app/blog/[uid]/page.tsx +++ b/app/blog/[uid]/page.tsx @@ -9,12 +9,15 @@ import MobileTableOfContents from '@/components/blog/MobileTableOfContents'; import { TableOfContentsSidebar } from '@/components/blog/TableOfContents'; import Breadcrumbs from '@/components/common/Breadcrumbs'; import Container from '@/components/common/Container'; +import JsonLd from '@/components/common/JsonLd'; import { resolveAuthors } from '@/lib/content/authors'; import { getAdjacentPosts, getPost, getPublishedPosts, } from '@/lib/content/posts'; +import { absoluteUrl, pageMetadata } from '@/lib/seo'; +import { siteName, siteUrl } from '@/lib/site'; export const dynamicParams = false; @@ -38,20 +41,23 @@ export async function generateMetadata({ const authors = await resolveAuthors(post.authors); const description = post.description ?? undefined; return { - title: post.title, - description, + ...pageMetadata({ + title: post.title, + description, + path: `/blog/${post.id}`, + image: `/blog/${post.id}/opengraph-image`, + openGraph: { + type: 'article', + publishedTime: post.publishDate, + authors: authors.map((author) => author.name), + tags: post.tags, + }, + }), authors: authors.map((author) => ({ name: author.name, url: author.isRegistered ? `/authors/${author.id}` : undefined, })), - openGraph: { - type: 'article', - title: post.title, - description, - publishedTime: post.publishDate, - authors: authors.map((author) => author.name), - tags: post.tags, - }, + keywords: post.tags, }; } @@ -61,10 +67,40 @@ export default async function PostPage({ params }: PostPageProps) { resolveAuthors(post.authors), getAdjacentPosts(post.id), ]); + const url = absoluteUrl(`/blog/${post.id}`); return ( // data-wide widens the site's main column so the sidebar fits beside the text.
+ ({ + '@type': 'Person', + name: author.name, + url: author.isRegistered + ? absoluteUrl(`/authors/${author.id}`) + : undefined, + })), + publisher: { + '@type': 'Organization', + '@id': `${siteUrl}/#organization`, + name: siteName, + logo: absoluteUrl('/logo.png'), + }, + }} + /> + value.replace( + /[<>&'"]/g, + (char) => + ({ '<': '<', '>': '>', '&': '&', "'": ''', '"': '"' }[ + char + ]!) + ); + +const toRfc822 = (date: string) => new Date(`${date}T00:00:00Z`).toUTCString(); + +export async function GET() { + const posts = await getPublishedPosts(); + const items = await Promise.all( + posts.map(async (post) => { + const url = absoluteUrl(`/blog/${post.id}`); + const authors = await resolveAuthors(post.authors); + return ` + ${escapeXml(post.title)} + ${url} + ${url} + ${toRfc822(post.publishDate)} + ${escapeXml( + authors.map((a) => a.name).join(', ') + )}${ + post.description + ? `\n ${escapeXml(post.description)}` + : '' + }${post.tags + .map((tag) => `\n ${escapeXml(tag)}`) + .join('')} + `; + }) + ); + + const xml = ` + + + ${escapeXml(`${siteName} Blog`)} + ${absoluteUrl('/blog')} + ${escapeXml(siteDescription)} + en + ${ + posts[0] + ? `\n ${toRfc822(posts[0].publishDate)}` + : '' + } +${items.join('\n')} + + +`; + + return new Response(xml, { + headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' }, + }); +} diff --git a/app/blog/page.tsx b/app/blog/page.tsx index 5f363e4..b0ba754 100644 --- a/app/blog/page.tsx +++ b/app/blog/page.tsx @@ -3,8 +3,14 @@ import PostList from '@/components/blog/PostList'; import Breadcrumbs from '@/components/common/Breadcrumbs'; import Container from '@/components/common/Container'; import { getPublishedPosts } from '@/lib/content/posts'; +import { pageMetadata } from '@/lib/seo'; +import { siteName } from '@/lib/site'; -export const metadata: Metadata = { title: 'Blog' }; +export const metadata: Metadata = pageMetadata({ + title: 'Blog', + description: `Articles, guides, and stories from the ${siteName} community.`, + path: '/blog', +}); export default async function BlogPage() { const posts = await getPublishedPosts(); diff --git a/app/layout.tsx b/app/layout.tsx index c232082..95bd965 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,15 +1,44 @@ -import type { Metadata } from 'next'; +import { SpeedInsights } from '@vercel/speed-insights/next'; +import type { Metadata, Viewport } from 'next'; import type { ReactNode } from 'react'; import ThemeScript from '@/components/common/ThemeScript'; import Footer from '@/components/layout/Footer'; import Header from '@/components/layout/Header'; import Layout from '@/components/layout/Layout'; -import { siteName } from '@/lib/site'; +import { baseOpenGraph, feedPath } from '@/lib/seo'; +import { siteDescription, siteName, siteUrl } from '@/lib/site'; import '@/styles/globals.css'; export const metadata: Metadata = { + metadataBase: new URL(siteUrl), title: { template: `%s | ${siteName}`, default: siteName }, - icons: { icon: { url: '/logo.png', type: 'image/png' } }, + description: siteDescription, + applicationName: siteName, + icons: { + icon: { url: '/logo.png', type: 'image/png' }, + apple: { url: '/logo.png', type: 'image/png' }, + }, + alternates: { types: { 'application/rss+xml': feedPath } }, + openGraph: { + ...baseOpenGraph, + title: siteName, + description: siteDescription, + }, + twitter: { card: 'summary_large_image' }, + robots: { + index: true, + follow: true, + googleBot: { 'max-image-preview': 'large', 'max-snippet': -1 }, + }, +}; + +// Matches the light (Nord) and dark (Catppuccin) backgrounds in globals.css. +export const viewport: Viewport = { + colorScheme: 'light dark', + themeColor: [ + { media: '(prefers-color-scheme: light)', color: '#eceff4' }, + { media: '(prefers-color-scheme: dark)', color: '#1e1e2e' }, + ], }; export default function RootLayout({ children }: { children: ReactNode }) { @@ -20,6 +49,7 @@ export default function RootLayout({ children }: { children: ReactNode }) { } footer={