Skip to content

Commit

Permalink
Try force-dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Aug 4, 2023
1 parent 323e9e8 commit 330a3c3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/app/posts/[slug]/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ async function getPostTitle(slug: string) {
}

export const runtime = 'edge';
export const revalidate = false; // On-demand static generation

export const size = {
width: 1200,
Expand Down
5 changes: 1 addition & 4 deletions src/app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export async function generateMetadata({
title: frontmatter.title,
description: excerpt,
openGraph: {
title: {
default: siteMetadata.title,
template: `%s | ${siteMetadata.title}`,
},
title: frontmatter.title,
description: excerpt,
url: `${siteMetadata.origin}/posts/${slug}`,
siteName: siteMetadata.title,
Expand Down
12 changes: 6 additions & 6 deletions src/app/rss.xml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import RSS from 'rss';
import { getPosts } from '@/internals/posts';
import siteMetadata from '@/siteMetadata';

export const revalidate = false; // Cache forever like a static file
export const dynamic = 'force-dynamic';
// export const revalidate = 0; // Cache forever like a static file

export async function GET() {
const feed = new RSS({
Expand All @@ -16,11 +17,10 @@ export async function GET() {

for (const post of posts) {
const postUrl = new URL(`/posts/${post.slug}`, siteMetadata.origin).href;
const html = await fetch(postUrl, { redirect: 'follow' }).then((res) =>
res.text(),
);
const contentHtml =
html.match(/<main(?:[^>]*?)>([\s\S]+?)<\/main>/)?.[1] || '';
const html = await fetch(postUrl, {
next: { tags: ['rss'] },
}).then((response) => response.text());
const contentHtml = html.match(/<main(?:[^>]*?)>([\s\S]+?)<\/main>/)?.[1];
const image = html.match(
/<meta property="og:image" content="([\s\S]+?)"\s?\/?>/,
)?.[1];
Expand Down
3 changes: 2 additions & 1 deletion src/siteMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export default {
repo: 'https://github.com/kevin940726/kaihao.dev',
origin:
process.env.HOST ||
(process.env.VERCEL_ENV !== 'production' &&
(process.env.VERCEL_ENV &&
process.env.VERCEL_ENV !== 'production' &&
`https://${process.env.VERCEL_URL}`) ||
'https://kaihao.dev',
siteUrl: 'https://kaihao.dev',
Expand Down

0 comments on commit 330a3c3

Please sign in to comment.