diff --git a/next-sitemap.config.cjs b/next-sitemap.config.cjs
index fc711b6..2dffdc0 100644
--- a/next-sitemap.config.cjs
+++ b/next-sitemap.config.cjs
@@ -1,13 +1,15 @@
const fs = require("fs");
const fm = require("front-matter");
+const siteUrl = process.env.SITE_URL || "https://www.aaronjy.me";
/** @type {import('next-sitemap').IConfig} */
module.exports = {
- siteUrl: process.env.SITE_URL || "https://www.aaronjy.me",
+ siteUrl,
changefreq: "weekly",
generateRobotsTxt: true,
autoLastmod: false,
generateIndexSitemap: false,
+ exclude: ["/server-sitemap-index.xml"], // <= exclude here
robotsTxtOptions: {
policies: [
{
@@ -15,30 +17,25 @@ module.exports = {
allow: "/",
},
],
+ additionalSitemaps: [
+ `${siteUrl}/server-sitemap-index.xml`, // <==== Add here
+ ],
},
- // transform: async (config, path) => {
- // const metadata = {
- // loc: path
- // }
+ transform: async (config, path) => {
+ const metadata = {
+ loc: path,
+ };
- // if (isHomepage(path)) {
- // metadata.priority = 1
- // } else if (isBasePage(path)) {
- // metadata.priority = 0.8
- // } else {
- // if (isArticle(path)) {
- // metadata.priority = 0.6
- // const attributes = getArticleAttibutes(`content${path}.md`)
- // if (!attributes) { return null }
+ if (isHomepage(path)) {
+ metadata.priority = 1;
+ } else if (isBasePage(path)) {
+ metadata.priority = 0.8;
+ } else if (isArticle(path)) {
+ metadata.priority = 0.6;
+ }
- // metadata.lastmod = attributes.moddate ?? attributes.pubdate ?? null
-
- // console.log('Calculated sitemap dates for article', path)
- // }
- // }
-
- // return metadata
- // }
+ return metadata;
+ },
};
function isHomepage(path) {
@@ -50,20 +47,5 @@ function isBasePage(path) {
}
function isArticle(path) {
- return path.startsWith("/writing/");
-}
-
-function getArticleAttibutes(path) {
- const fileContents = fs.readFileSync(path, {
- encoding: "utf-8",
- });
-
- // @ts-ignore
- const { attributes } = fm(fileContents);
-
- return {
- ...attributes,
- pubdate: attributes.pubdate?.toUTCString() ?? null,
- moddate: attributes.moddate?.toUTCString() ?? null,
- };
+ return path.startsWith("/writing/") || path.startsWith("/library/");
}
diff --git a/package.json b/package.json
index 543ce38..0f66528 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "www-aaronjy-me",
- "version": "2.1.2",
+ "version": "2.2.0",
"private": true,
"type": "module",
"lint-staged": {
diff --git a/public/robots.txt b/public/robots.txt
index 6a8d464..82dee3e 100644
--- a/public/robots.txt
+++ b/public/robots.txt
@@ -7,3 +7,4 @@ Host: https://www.aaronjy.me
# Sitemaps
Sitemap: https://www.aaronjy.me/sitemap.xml
+Sitemap: https://www.aaronjy.me/server-sitemap-index.xml
diff --git a/public/sitemap-0.xml b/public/sitemap-0.xml
deleted file mode 100644
index 5ddf8e5..0000000
--- a/public/sitemap-0.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
Loading...
; +} diff --git a/src/pages/[[...path]].jsx b/src/pages/[[...path]].jsx index a4e3b8e..3cc9c8c 100644 --- a/src/pages/[[...path]].jsx +++ b/src/pages/[[...path]].jsx @@ -1,16 +1,35 @@ -import { - FailedFetchBasicPageError, - FailedFetchBasicPagesError, -} from "@/errors"; +import Loading from "@/components/Loading/Loading"; +import { FailedFetchBasicPagesError } from "@/errors"; import DefaultLayout from "@/layouts/DefaultLayout/DefaultLayout"; import { mdxComponents } from "@/lib/mdx-components"; import { fetchBasicPages } from "@/services/content-service"; import { MDXClient } from "next-mdx-remote-client"; import { serialize } from "next-mdx-remote-client/serialize"; import { NextSeo } from "next-seo"; +import { useRouter } from "next/router"; -export async function getServerSideProps({ params }) { +export async function getStaticPaths() { + const res = await fetchBasicPages(["path"]); + + if (!res.ok) { + throw new FailedFetchBasicPagesError(await res.text()); + } + + const pages = (await res.json()).data; + + return { + paths: pages.map((page) => ({ + params: { + path: [page.path ?? ""], + }, + })), + fallback: true, + }; +} + +export async function getStaticProps({ params }) { const { path } = params; + const res = await fetchBasicPages([], { path: { _eq: path?.join("/") ?? null, @@ -26,6 +45,7 @@ export async function getServerSideProps({ params }) { if (!page) { return { notFound: true, + revalidate: 60, }; } @@ -37,10 +57,21 @@ export async function getServerSideProps({ params }) { title, mdxSource, }, + revalidate: 60, }; } export default function BasicPage({ title, mdxSource }) { + const { isFallback } = useRouter(); + + if (isFallback) { + return ( +Something went wrong: {mdxSource?.error ?? "???"}
; } diff --git a/src/pages/cv/index.js b/src/pages/cv/index.js index 585f75a..88e992d 100644 --- a/src/pages/cv/index.js +++ b/src/pages/cv/index.js @@ -7,7 +7,7 @@ import { FailedFetchCVError } from "@/errors"; export const Title = "CV"; -export async function getServerSideProps() { +export async function getStaticProps() { const res = await fetchCV([]); if (!res.ok) { @@ -18,6 +18,7 @@ export async function getServerSideProps() { if (!cv) { return { notFound: true, + revalidate: 60, }; } @@ -31,6 +32,7 @@ export async function getServerSideProps() { certifications, experience, }, + revalidate: 60, }; } diff --git a/src/pages/library/[slug].js b/src/pages/library/[slug].js index 03af892..35ae3aa 100644 --- a/src/pages/library/[slug].js +++ b/src/pages/library/[slug].js @@ -6,37 +6,33 @@ import { FailedFetchBookReviewError, FailedFetchBookReviewsError, } from "@/errors"; +import { useRouter } from "next/router"; +import Loading from "@/components/Loading/Loading"; -// export async function getStaticPaths () { -// const res = await fetchBookReviews(['slug'], { -// status: 'published' -// }) +export async function getStaticPaths() { + const res = await fetchBookReviews(["slug"], { + status: "published", + }); -// if (!res.ok) { -// throw new FailedFetchBookReviewsError(await res.text()) -// } - -// const reviews = (await res.json()).data - -// return { -// paths: reviews.map(post => ({ -// params: { -// slug: post.slug -// } -// })), -// fallback: false // false or "blocking" -// } -// } - -export const getServerSideProps = async ({ params }) => { - const { slug } = params; - - if (!slug) { - return { - notFound: true, - }; + if (!res.ok) { + throw new FailedFetchBookReviewsError(await res.text()); } + const reviews = (await res.json()).data; + + return { + paths: reviews.map((post) => ({ + params: { + slug: post.slug, + }, + })), + fallback: true, + }; +} + +export const getStaticProps = async ({ params }) => { + const { slug } = params; + const res = await fetchBookReviews([], { slug, status: "published", @@ -50,6 +46,7 @@ export const getServerSideProps = async ({ params }) => { if (!review) { return { notFound: true, + revalidate: 60, }; } @@ -61,13 +58,17 @@ export const getServerSideProps = async ({ params }) => { review, html, }, + revalidate: 60, }; }; export default function LibrarySingle({ review, html }) { + const { isFallback } = useRouter(); + return (