1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-13 21:55:30 -04:00

publish sitemap.xml with getServerSideProps instead of next-sitemap (#720)

very VERY hacky right now but I still prefer this
This commit is contained in:
2022-01-03 20:53:17 -05:00
committed by GitHub
parent 78d17c6337
commit a5a602d385
5 changed files with 75 additions and 38 deletions

3
.gitignore vendored
View File

@@ -2,9 +2,6 @@
/.next/
/out/
# generated at build-time by next-sitemap
public/sitemap.xml
# node/npm/yarn
node_modules/
package-lock.json

View File

@@ -1,7 +0,0 @@
const config = require("./lib/config");
module.exports = {
siteUrl: config.baseUrl || "",
changefreq: "weekly",
exclude: ["/feed.xml", "/feed.atom", "/site.webmanifest"],
};

View File

@@ -16,7 +16,6 @@
"scripts": {
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"postbuild": "next-sitemap",
"analyze": "cross-env ANALYZE=true next build",
"lint": "run-s lint:*",
"lint:next": "next lint",
@@ -47,7 +46,6 @@
"next": "v12.0.8-canary.15",
"next-mdx-remote": "^3.0.8",
"next-seo": "^4.28.1",
"next-sitemap": "^1.6.203",
"node-fetch": "^3.1.0",
"p-retry": "^5.0.0",
"prop-types": "^15.8.0",

70
pages/sitemap.xml.ts Normal file
View File

@@ -0,0 +1,70 @@
// WARNING: THIS FILE CONTAINS HISTORICAL LEVELS OF HACKINESS AND SHOULD NOT BE REPLICATED NOR ADMIRED.
import { getAllNotes } from "../lib/parse-notes";
import { baseUrl } from "../lib/config";
import type { GetServerSideProps } from "next";
const Sitemap = () => null;
type Page = {
relUrl: string;
priority?: number;
changeFreq?: string;
lastMod?: string | Date;
};
export const getServerSideProps: GetServerSideProps = async (context) => {
// TODO: make this not manual (serverless functions can't see /pages at runtime)
const pages: Page[] = [
{ relUrl: "/", priority: 1.0, changeFreq: "weekly" }, // homepage
{ relUrl: "/notes/" },
{ relUrl: "/birthday/" },
{ relUrl: "/cli/" },
{ relUrl: "/contact/" },
{ relUrl: "/hillary/" },
{ relUrl: "/leo/" },
{ relUrl: "/license/", priority: 0.1, changeFreq: "yearly" },
{ relUrl: "/previously/" },
{ relUrl: "/privacy/", priority: 0.1, changeFreq: "yearly" },
{ relUrl: "/projects/", changeFreq: "daily" },
{ relUrl: "/uses/" },
];
// push notes separately and use their metadata
getAllNotes().map((note) =>
pages.push({
relUrl: `/notes/${note.slug}/`,
// pull lastMod from front matter date
lastMod: note.date,
})
);
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${pages
.map(
(page) => `
<url>
<loc>${baseUrl}${page.relUrl}</loc>
<priority>${page.priority ? page.priority.toFixed(1) : 0.7}</priority>
<changefreq>${page.changeFreq || "monthly"}</changefreq>
<lastmod>${page.lastMod || new Date().toISOString()}</lastmod>
</url>`
)
.join("")
.trim()}
</urlset>`;
const { res } = context;
res.setHeader("content-type", "application/xml; charset=utf-8");
// cache on edge for one hour
res.setHeader("cache-control", "s-maxage=3600, stale-while-revalidate");
res.write(xml);
res.end();
return {
props: {},
};
};
export default Sitemap;

View File

@@ -1038,11 +1038,6 @@
"@babel/helper-validator-identifier" "^7.16.7"
to-fast-properties "^2.0.0"
"@corex/deepmerge@^2.6.34":
version "2.6.148"
resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-2.6.148.tgz#8fa825d53ffd1cbcafce1b6a830eefd3dcc09dd5"
integrity sha512-6QMz0/2h5C3ua51iAnXMPWFbb1QOU1UvSM4bKBw5mzdT+WtLgjbETBBIQZ+Sh9WvEcGwlAt/DEdRpIC3XlDBMA==
"@eslint/eslintrc@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.0.5.tgz#33f1b838dbf1f923bfa517e008362b78ddbbf318"
@@ -3734,16 +3729,16 @@ lint-staged@^12.1.5:
yaml "^1.10.2"
listr2@^3.13.5:
version "3.13.5"
resolved "https://registry.yarnpkg.com/listr2/-/listr2-3.13.5.tgz#105a813f2eb2329c4aae27373a281d610ee4985f"
integrity sha512-3n8heFQDSk+NcwBn3CgxEibZGaRzx+pC64n3YjpMD1qguV4nWus3Al+Oo3KooqFKTQEJ1v7MmnbnyyNspgx3NA==
version "3.14.0"
resolved "https://registry.yarnpkg.com/listr2/-/listr2-3.14.0.tgz#23101cc62e1375fd5836b248276d1d2b51fdbe9e"
integrity sha512-TyWI8G99GX9GjE54cJ+RrNMcIFBfwMPxc3XTFiAYGN4s10hWROGtOg7+O6u6LE3mNkyld7RSLE6nrKBvTfcs3g==
dependencies:
cli-truncate "^2.1.0"
colorette "^2.0.16"
log-update "^4.0.0"
p-map "^4.0.0"
rfdc "^1.3.0"
rxjs "^7.4.0"
rxjs "^7.5.1"
through "^2.3.8"
wrap-ansi "^7.0.0"
@@ -3880,13 +3875,6 @@ markdown-escapes@^1.0.0:
resolved "https://registry.yarnpkg.com/markdown-escapes/-/markdown-escapes-1.0.4.tgz#c95415ef451499d7602b91095f3c8e8975f78535"
integrity sha512-8z4efJYk43E0upd0NbVXwgSTQs6cT3T06etieCMEg7dRbzCbxUCK/GHlX8mhHRDcp+OLlHkPKsvqQTCvsRl2cg==
matcher@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/matcher/-/matcher-4.0.0.tgz#a42a05a09aaed92e2d241eb91fddac689461ea51"
integrity sha512-S6x5wmcDmsDRRU/c2dkccDwQPXoFczc5+HpQ2lON8pnvHlnvHAHj5WlLVvw6n6vNyHuVugYrFohYxbS+pvFpKQ==
dependencies:
escape-string-regexp "^4.0.0"
mathml-tag-names@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/mathml-tag-names/-/mathml-tag-names-2.1.3.tgz#4ddadd67308e780cf16a47685878ee27b736a0a3"
@@ -4056,15 +4044,6 @@ next-seo@^4.28.1:
resolved "https://registry.yarnpkg.com/next-seo/-/next-seo-4.28.1.tgz#c98ee559c8ab7196c62d0f6903afd7a8cde47a03"
integrity sha512-WZgwdM+UhpNF3A37zFllzmPhnOVJ9vYeYlc0n3Z/kYfz/QQgy8NEdncNNggS9dU4JD8xriaCcyknhy5OsrFsJw==
next-sitemap@^1.6.203:
version "1.6.203"
resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-1.6.203.tgz#bfa2e67fea2bab1efed60cda743e7f98dc00bb46"
integrity sha512-WigcoqIUNbXQa2GnwOiCOydGx/XHCS4kRtIPNEsc8DGX2XvJtbAJKRxcidZZ2KihTAtwwCu1XQ4Hbof4mJbvLg==
dependencies:
"@corex/deepmerge" "^2.6.34"
matcher "^4.0.0"
minimist "^1.2.5"
next@v12.0.8-canary.15:
version "12.0.8-canary.15"
resolved "https://registry.yarnpkg.com/next/-/next-12.0.8-canary.15.tgz#afe3aafac9eda2d7f5de81c1fac9a75b80a799d6"
@@ -4919,7 +4898,7 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"
rxjs@^7.4.0:
rxjs@^7.5.1:
version "7.5.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.1.tgz#af73df343cbcab37628197f43ea0c8256f54b157"
integrity sha512-KExVEeZWxMZnZhUZtsJcFwz8IvPvgu4G2Z2QyqjZQzUGr32KDYuSxrEYO4w3tFFNbfLozcrKUTvTPi+E9ywJkQ==