Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port /blog to App router; add blog preview cards [#134] #1059

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
49 changes: 49 additions & 0 deletions static-site/app/blog/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Metadata } from "next";
import { redirect } from "next/navigation";
import React from "react";

import { BigSpacer } from "../../../components/spacers";
import {
siteLogo,
siteTitle,
siteTitleAlt,
siteUrl,
} from "../../../data/BaseConfig";

import { getBlogPosts, markdownToHtml } from "../utils";

Expand All @@ -20,6 +27,48 @@ export function generateStaticParams(): BlogPostParams[] {
});
}

// generate opengraph and other metadata tags
export async function generateMetadata({
params,
}: {
params: BlogPostParams;
}): Promise<Metadata> {
const { id } = params;

// set up some defaults that are independent of the specific blog post
const baseUrl = new URL(siteUrl);
const metadata: Metadata = {
metadataBase: baseUrl,
openGraph: {
description: siteTitleAlt,
images: [
{
url: `${siteUrl}${siteLogo}`,
},
],
siteName: siteTitle,
title: siteTitle,
type: "website",
url: baseUrl,
},
};

// this is the specific post we're rendering
const blogPost = getBlogPosts().find((post) => post.blogUrlName === id);

if (blogPost) {
const description = `Nextstrain blog post from ${blogPost.date}; author(s): ${blogPost.author}`;

metadata.title = blogPost.title;
metadata.description = description;
metadata.openGraph!.description = description;
metadata.openGraph!.title = `${siteTitle}: ${blogPost.title}`;
metadata.openGraph!.url = `/blog/${blogPost.blogUrlName}`;
}

return metadata;
genehack marked this conversation as resolved.
Show resolved Hide resolved
}

export default async function BlogPost({
params,
}: {
Expand Down