1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 15:06:36 -04:00

attempt to make edge functions a tad bit lighter

This commit is contained in:
2023-07-06 10:37:51 -04:00
parent 2f44d8d227
commit b13c8259b3
17 changed files with 121 additions and 146 deletions

View File

@ -24,7 +24,7 @@ const App = ({ Component, pageProps }: AppProps) => {
// get this page's URL with full domain, and hack around query parameters and anchors
// NOTE: this assumes trailing slashes are enabled in next.config.js
const canonical = `${config.baseUrl}${router.pathname === "/" ? "" : router.pathname}/`;
const canonical = `${process.env.BASE_URL}${router.pathname === "/" ? "" : router.pathname}/`;
useEffect(() => {
// don't track pageviews on branch/deploy previews and localhost

View File

@ -8,8 +8,8 @@ const Document = () => {
return (
<Html lang={config.siteLocale} className={themeClassNames["light"]}>
<Head>
{/* inject a small script to set/restore the user's theme ASAP */}
<ThemeScript id="restore-theme" {...{ themeClassNames, themeStorageKey }} />
{/* inject this script (generated at build-time) to prioritize setting/restoring the user's theme. */}
<ThemeScript key="restore-theme-js" {...{ themeClassNames, themeStorageKey }} />
<style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
</Head>

View File

@ -1,6 +1,5 @@
import { NextResponse } from "next/server";
import queryString from "query-string";
import { baseUrl } from "../../lib/config";
import type { NextRequest } from "next/server";
// fallback to dummy secret for testing: https://docs.hcaptcha.com/#integration-testing-test-keys
@ -20,7 +19,7 @@ export const config = {
export default async (req: NextRequest) => {
// redirect GET requests to this endpoint to the contact form itself
if (req.method === "GET") {
return NextResponse.redirect(`${baseUrl}/contact/`);
return NextResponse.redirect(`${process.env.BASE_URL}/contact/`);
}
// possible weirdness? https://github.com/orgs/vercel/discussions/78#discussioncomment-5089059

View File

@ -32,7 +32,7 @@ const Note = ({ frontMatter, source }: InferGetStaticPropsType<typeof getStaticP
},
images: [
{
url: `${config.baseUrl}${frontMatter.image || meJpg.src}`,
url: `${process.env.BASE_URL}${frontMatter.image || meJpg.src}`,
alt: frontMatter.title,
},
],
@ -47,7 +47,7 @@ const Note = ({ frontMatter, source }: InferGetStaticPropsType<typeof getStaticP
description={frontMatter.description || config.longDescription}
datePublished={frontMatter.date}
dateModified={frontMatter.date}
images={[`${config.baseUrl}${frontMatter.image || meJpg.src}`]}
images={[`${process.env.BASE_URL}${frontMatter.image || meJpg.src}`]}
{...articleJsonLd}
/>

View File

@ -1,4 +1,3 @@
import { baseUrl } from "../lib/config";
import type { GetServerSideProps } from "next";
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
@ -12,7 +11,7 @@ ${
? `Disallow: /`
: `Allow: /
Sitemap: ${baseUrl}/sitemap.xml`
Sitemap: ${process.env.BASE_URL}/sitemap.xml`
}
`;

View File

@ -1,12 +1,10 @@
import { SitemapStream, SitemapItemLoose, EnumChangefreq } from "sitemap";
import { getAllNotes } from "../lib/helpers/parse-notes";
import { baseUrl } from "../lib/config";
import { RELEASE_DATE, NOTES_DIR } from "../lib/config/constants";
import type { GetServerSideProps } from "next";
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
const { res } = context;
const stream = new SitemapStream({ hostname: baseUrl });
const stream = new SitemapStream({ hostname: process.env.BASE_URL });
// cache on edge for 12 hours
res.setHeader("cache-control", "public, max-age=0, s-maxage=43200, stale-while-revalidate");
@ -22,7 +20,7 @@ export const getServerSideProps: GetServerSideProps<Record<string, never>> = asy
url: "/",
priority: 1.0,
changefreq: EnumChangefreq.WEEKLY,
lastmod: RELEASE_DATE, // timestamp frozen when a new build is deployed
lastmod: process.env.RELEASE_DATE, // timestamp frozen when a new build is deployed
},
{ url: "/birthday/" },
{ url: "/cli/" },
@ -42,7 +40,7 @@ export const getServerSideProps: GetServerSideProps<Record<string, never>> = asy
const notes = await getAllNotes();
notes.forEach((note) => {
pages.push({
url: `/${NOTES_DIR}/${note.slug}/`,
url: `/notes/${note.slug}/`,
// pull lastMod from front matter date
lastmod: note.date,
});
@ -50,7 +48,7 @@ export const getServerSideProps: GetServerSideProps<Record<string, never>> = asy
// set lastmod of /notes/ page to most recent post's date
pages.push({
url: `/${NOTES_DIR}/`,
url: `/notes/`,
lastmod: notes[0].date,
});