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
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 4 additions & 0 deletions WEBSITE_CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
23 changes: 21 additions & 2 deletions app/authors/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,10 +30,12 @@ export async function generateMetadata({
params,
}: AuthorPageProps): Promise<Metadata> {
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) {
Expand All @@ -40,6 +44,21 @@ export default async function AuthorPage({ params }: AuthorPageProps) {

return (
<Container className='flex flex-col gap-6'>
<JsonLd
data={{
'@type': 'ProfilePage',
url: absoluteUrl(`/authors/${author.id}`),
mainEntity: {
'@type': 'Person',
name: author.name,
description: author.bio ?? undefined,
image: author.avatar ? absoluteUrl(author.avatar) : undefined,
sameAs: author.links
.filter((link) => link.href.startsWith('https://'))
.map((link) => link.href),
},
}}
/>
<Breadcrumbs
items={[
{ label: 'Blog', href: '/blog' },
Expand Down
8 changes: 7 additions & 1 deletion app/authors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import AuthorCard from '@/components/authors/AuthorCard';
import Breadcrumbs from '@/components/common/Breadcrumbs';
import Container from '@/components/common/Container';
import { getAllAuthors } from '@/lib/content/authors';
import { pageMetadata } from '@/lib/seo';
import { siteName } from '@/lib/site';

export const metadata: Metadata = { title: 'Authors' };
export const metadata: Metadata = pageMetadata({
title: 'Authors',
description: `The people who write for the ${siteName} blog.`,
path: '/authors',
});

export default async function AuthorsPage() {
const authors = await getAllAuthors();
Expand Down
30 changes: 30 additions & 0 deletions app/blog/[uid]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { notFound } from 'next/navigation';
import { resolveAuthors } from '@/lib/content/authors';
import { getPost, getPublishedPosts } from '@/lib/content/posts';
import { formatDate } from '@/lib/format';
import { ogContentType, ogImage, ogSize } from '@/lib/og';

export const alt = 'Blog post preview';
export const size = ogSize;
export const contentType = ogContentType;

export async function generateStaticParams() {
return (await getPublishedPosts()).map((post) => ({ 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}`,
});
}
56 changes: 46 additions & 10 deletions app/blog/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
};
}

Expand All @@ -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.
<article data-wide className='flex w-full flex-col gap-6'>
<JsonLd
data={{
'@type': 'BlogPosting',
'@id': `${url}#article`,
mainEntityOfPage: url,
url,
headline: post.title,
description: post.description ?? undefined,
image: absoluteUrl(
post.coverImage ?? `/blog/${post.id}/opengraph-image`
),
datePublished: post.publishDate,
keywords: post.tags.length ? post.tags.join(', ') : undefined,
inLanguage: 'en',
author: authors.map((author) => ({
'@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'),
},
}}
/>
<Container>
<Breadcrumbs
items={[{ label: 'Blog', href: '/blog' }, { label: post.title }]}
Expand Down
65 changes: 65 additions & 0 deletions app/blog/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { resolveAuthors } from '@/lib/content/authors';
import { getPublishedPosts } from '@/lib/content/posts';
import { absoluteUrl, feedPath } from '@/lib/seo';
import { siteDescription, siteName } from '@/lib/site';

export const dynamic = 'force-static';

const escapeXml = (value: string) =>
value.replace(
/[<>&'"]/g,
(char) =>
({ '<': '&lt;', '>': '&gt;', '&': '&amp;', "'": '&apos;', '"': '&quot;' }[
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 ` <item>
<title>${escapeXml(post.title)}</title>
<link>${url}</link>
<guid isPermaLink="true">${url}</guid>
<pubDate>${toRfc822(post.publishDate)}</pubDate>
<dc:creator>${escapeXml(
authors.map((a) => a.name).join(', ')
)}</dc:creator>${
post.description
? `\n <description>${escapeXml(post.description)}</description>`
: ''
}${post.tags
.map((tag) => `\n <category>${escapeXml(tag)}</category>`)
.join('')}
</item>`;
})
);

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>${escapeXml(`${siteName} Blog`)}</title>
<link>${absoluteUrl('/blog')}</link>
<description>${escapeXml(siteDescription)}</description>
<language>en</language>
<atom:link href="${absoluteUrl(
feedPath
)}" rel="self" type="application/rss+xml"/>${
posts[0]
? `\n <lastBuildDate>${toRfc822(posts[0].publishDate)}</lastBuildDate>`
: ''
}
${items.join('\n')}
</channel>
</rss>
`;

return new Response(xml, {
headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' },
});
}
8 changes: 7 additions & 1 deletion app/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 33 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand All @@ -20,6 +49,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<Layout header={<Header />} footer={<Footer />}>
{children}
</Layout>
<SpeedInsights />
</body>
</html>
);
Expand Down
15 changes: 15 additions & 0 deletions app/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { MetadataRoute } from 'next';
import { siteDescription, siteName } from '@/lib/site';

export default function manifest(): MetadataRoute.Manifest {
return {
name: siteName,
short_name: 'OSF',
description: siteDescription,
start_url: '/',
display: 'browser',
background_color: '#1e1e2e',
theme_color: '#1e1e2e',
icons: [{ src: '/logo.png', sizes: '576x512', type: 'image/png' }],
};
}
13 changes: 13 additions & 0 deletions app/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ogContentType, ogImage, ogSize } from '@/lib/og';
import { siteDescription, siteName } from '@/lib/site';

export const alt = siteName;
export const size = ogSize;
export const contentType = ogContentType;

export default function Image() {
return ogImage({
title: `Hello, we are ${siteName}`,
subtitle: siteDescription,
});
}
Loading
Loading