1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-16 19:45:33 -04:00

freeze build timestamp via an environment variable

This commit is contained in:
2022-03-18 17:41:27 -04:00
parent 5912cd1356
commit f870c5c796
6 changed files with 20 additions and 6 deletions

View File

@@ -1 +1 @@
16.14.1 16.14.2

View File

@@ -1,2 +1,5 @@
// Next.js constants (not needed in frontend) // Next.js constants (not needed in frontend)
export const NOTES_DIR = "./notes"; export const NOTES_DIR = "./notes";
// normalize the timestamp saved when building/deploying (see next.config.js) and fall back to right now:
export const RELEASE_DATE = new Date(process.env.RELEASE_DATE ?? Date.now()).toISOString();

View File

@@ -1,6 +1,7 @@
import { Feed } from "feed"; import { Feed } from "feed";
import { getAllNotes } from "./parse-notes"; import { getAllNotes } from "./parse-notes";
import * as config from "../config"; import * as config from "../config";
import { RELEASE_DATE } from "../config/constants";
import type { GetServerSidePropsContext, PreviewData } from "next"; import type { GetServerSidePropsContext, PreviewData } from "next";
import type { ParsedUrlQuery } from "querystring"; import type { ParsedUrlQuery } from "querystring";
@@ -20,7 +21,7 @@ export const buildFeed = (
title: config.siteName, title: config.siteName,
description: config.longDescription, description: config.longDescription,
copyright: "https://creativecommons.org/licenses/by/4.0/", copyright: "https://creativecommons.org/licenses/by/4.0/",
updated: new Date(), updated: new Date(RELEASE_DATE),
image: `${config.baseUrl}/static/images/me.jpg`, image: `${config.baseUrl}/static/images/me.jpg`,
feedLinks: { feedLinks: {
rss: `${config.baseUrl}/feed.xml`, rss: `${config.baseUrl}/feed.xml`,

View File

@@ -23,6 +23,9 @@ module.exports = (phase, { defaultConfig }) => {
trailingSlash: true, trailingSlash: true,
productionBrowserSourceMaps: true, productionBrowserSourceMaps: true,
env: { env: {
// freeze build timestamp for when serverless pages need a "last updated" date:
RELEASE_DATE: new Date().toISOString(),
// check if we're running locally via `next dev`:
IS_DEV_SERVER: phase === PHASE_DEVELOPMENT_SERVER, IS_DEV_SERVER: phase === PHASE_DEVELOPMENT_SERVER,
}, },
images: { images: {

View File

@@ -107,7 +107,7 @@
}, },
"packageManager": "yarn@1.22.17", "packageManager": "yarn@1.22.17",
"volta": { "volta": {
"node": "16.14.1", "node": "16.14.2",
"yarn": "1.22.17" "yarn": "1.22.17"
} }
} }

View File

@@ -1,14 +1,21 @@
import { getServerSideSitemap } from "next-sitemap"; import { getServerSideSitemap } from "next-sitemap";
import { getAllNotes } from "../lib/helpers/parse-notes"; import { getAllNotes } from "../lib/helpers/parse-notes";
import { baseUrl } from "../lib/config"; import { baseUrl } from "../lib/config";
import { RELEASE_DATE } from "../lib/config/constants";
import type { GetServerSideProps } from "next"; import type { GetServerSideProps } from "next";
import type { ISitemapField } from "next-sitemap"; import type { ISitemapField } from "next-sitemap";
export const getServerSideProps: GetServerSideProps = async (context) => { export const getServerSideProps: GetServerSideProps = async (context) => {
// TODO: make this not manual (serverless functions can't see filesystem at runtime) // TODO: make this not manual (serverless functions can't see filesystem at runtime)
const pages: ISitemapField[] = [ const pages: ISitemapField[] = [
{ loc: "/", priority: 1.0, changefreq: "weekly" }, // homepage {
{ loc: "/notes/", changefreq: "weekly" }, // homepage
loc: "/",
priority: 1.0,
changefreq: "weekly",
lastmod: RELEASE_DATE,
},
{ loc: "/notes/", changefreq: "weekly", lastmod: RELEASE_DATE },
{ loc: "/birthday/" }, { loc: "/birthday/" },
{ loc: "/cli/" }, { loc: "/cli/" },
{ loc: "/contact/" }, { loc: "/contact/" },
@@ -28,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
pages.push({ pages.push({
loc: `/notes/${note.slug}/`, loc: `/notes/${note.slug}/`,
// pull lastMod from front matter date // pull lastMod from front matter date
lastmod: note.date, lastmod: new Date(note.date).toISOString(),
priority: 0.7, priority: 0.7,
}) })
); );