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

don't load fathom script unless on production

This commit is contained in:
Jake Jarvis 2022-05-16 09:40:36 -04:00
parent cf4f2fe442
commit 2f695be18f
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
12 changed files with 40 additions and 46 deletions

View File

@ -9,7 +9,7 @@ const Block = styled("div", {
margin: "1em auto",
color: "$codeText",
[`& ${Code}`]: {
[`${Code}`]: {
display: "block",
overflowX: "auto",
padding: "1em",

View File

@ -9,7 +9,7 @@ const Title = styled("h1", {
lineHeight: 1.3,
fontWeight: 700,
"& code": {
code: {
margin: "0 0.075em",
},

View File

@ -12,10 +12,10 @@ const Display = styled(
maxWidth: "800px",
// these are injected by noVNC after connection, so we can't target them directly:
"& div": {
div: {
background: "none !important",
"& canvas": {
canvas: {
cursor: "inherit !important",
},
},

View File

@ -13,7 +13,7 @@ const Player = styled(ReactPlayer, {
top: 0,
left: 0,
"& video": {
video: {
borderRadius: "$rounded",
},
});

View File

@ -14,7 +14,7 @@ const Player = styled(ReactPlayer, {
left: 0,
// target both the lazy thumbnail preview *and* the actual YouTube embed
"& .react-player__preview, & iframe": {
".react-player__preview, iframe": {
borderRadius: "$rounded",
},
});

View File

@ -1,11 +1,9 @@
// Next.js constants (not needed in frontend)
import path from "path";
// directory containing .mdx files relative to project root
export const NOTES_DIR = "./notes";
export const NOTES_DIR = path.join(process.cwd(), "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.NEXT_PUBLIC_RELEASE_DATE ?? Date.now()).toISOString();
// detect current backend environment
export const IS_PROD = process.env.NEXT_PUBLIC_VERCEL_ENV === "production";
export const IS_DEV_SERVER = !!process.env.IS_DEV_SERVER;

View File

@ -2,6 +2,7 @@ import fs from "fs/promises";
import path from "path";
import { renderToStaticMarkup } from "react-dom/server";
import { serialize } from "next-mdx-remote/serialize";
import glob from "fast-glob";
import pMap from "p-map";
import matter from "gray-matter";
import urlJoin from "url-join";
@ -9,7 +10,6 @@ import { minify } from "uglify-js";
import { compiler } from "markdown-to-jsx";
import removeMarkdown from "remove-markdown";
import sanitizeHtml from "sanitize-html";
import readingTime from "reading-time";
import { formatDateISO } from "./format-date";
import { baseUrl } from "../config";
import { NOTES_DIR } from "../config/constants";
@ -23,15 +23,14 @@ import rehypePrism from "rehype-prism-plus";
import type { Note, NoteFrontMatter } from "../../types";
const ABSOLUTE_NOTES_DIR = path.join(process.cwd(), NOTES_DIR);
// returns all .mdx files in NOTES_DIR (without .mdx extension)
export const getNoteSlugs = async (): Promise<string[]> => {
// get all files in NOTES_DIR
const files = await fs.readdir(ABSOLUTE_NOTES_DIR);
// list all .mdx files in NOTES_DIR
const mdxFiles = await glob("*.mdx", { cwd: NOTES_DIR });
// narrow to only the .mdx files and strip the .mdx extension
return files.filter((file) => /\.mdx$/.test(file)).map((noteFile) => noteFile.replace(/\.mdx$/, ""));
// strip the .mdx extensions from filenames
const slugs = mdxFiles.map((fileName) => fileName.replace(/\.mdx$/, ""));
return slugs;
};
// returns front matter and/or *raw* markdown contents of a given slug
@ -41,7 +40,7 @@ export const getNoteData = async (
frontMatter: NoteFrontMatter;
content: string;
}> => {
const fullPath = path.join(ABSOLUTE_NOTES_DIR, `${slug}.mdx`);
const fullPath = path.join(NOTES_DIR, `${slug}.mdx`);
const rawContent = await fs.readFile(fullPath, "utf8");
const { data, content } = matter(rawContent);
@ -69,7 +68,6 @@ export const getNoteData = async (
slug,
permalink: urlJoin(baseUrl, "notes", slug, "/"),
date: formatDateISO(data.date), // validate/normalize the date string provided from front matter
readingMins: Math.ceil(readingTime(content).minutes),
},
content,
};

View File

@ -151,7 +151,7 @@ export const globalStyles = globalCss(
fontVariationSettings: `"ital" 1, "slnt" -10`,
// Roboto Mono doesn't have this problem, but the above fix breaks it, of course.
"& code, & kbd, & samp, & pre": {
"code, kbd, samp, pre": {
fontStyle: "italic !important",
fontVariationSettings: "initial !important",
},

View File

@ -32,6 +32,7 @@
"@stitches/react": "^1.2.8",
"copy-to-clipboard": "^3.3.1",
"dayjs": "^1.11.2",
"fast-glob": "^3.2.11",
"fathom-client": "^3.4.1",
"faunadb": "^4.5.4",
"feather-icons": "^4.29.0",
@ -62,7 +63,6 @@
"react-textarea-autosize": "^8.3.3",
"react-twitter-embed": "^4.0.4",
"react-use": "^17.3.2",
"reading-time": "^1.5.0",
"rehype-prism-plus": "^1.4.0",
"rehype-slug": "^5.0.1",
"remark-gfm": "^3.0.1",
@ -70,7 +70,7 @@
"remark-unwrap-images": "^3.0.1",
"remove-markdown": "^0.5.0",
"sanitize-html": "^2.7.0",
"simple-icons": "^6.21.0",
"simple-icons": "^6.22.0",
"sitemap": "^7.1.1",
"stitches-normalize": "^2.0.0",
"swr": "^1.3.0",

View File

@ -28,10 +28,14 @@ const App = ({ Component, pageProps }: AppProps) => {
const canonical = urlJoin(config.baseUrl, router.pathname === "/" ? "" : router.pathname, "/");
useEffect(() => {
// don't track pageviews on branch/deploy previews and localhost
if (process.env.NEXT_PUBLIC_VERCEL_ENV !== "production") {
return;
}
// https://usefathom.com/docs/integrations/next
// https://vercel.com/guides/deploying-nextjs-using-fathom-analytics-with-vercel
Fathom.load(config.fathomSiteId, {
// don't track branch/deploy previews and localhost
includedDomains: [config.siteDomain],
// we trigger pageview sending manually below, don't also do it on script load
auto: false,

1
types/note.d.ts vendored
View File

@ -9,7 +9,6 @@ export type NoteFrontMatter = {
description?: string;
image?: string;
tags?: string[];
readingMins?: number;
noComments?: boolean;
};

View File

@ -1623,7 +1623,7 @@
"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==
"@types/mdast@^3.0.0":
version "3.0.10"
@ -1638,9 +1638,9 @@
integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==
"@types/mdx@^2.0.0":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.1.tgz#e4c05d355d092d7b58db1abfe460e53f41102ac8"
integrity sha512-JPEv4iAl0I+o7g8yVWDwk30es8mfVrjkvh5UeVR2sYPpZCK44vrAPsbJpIS+rJAUxLgaSAMKTEH5Vn5qd9XsrQ==
version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.2.tgz#64be19baddba4323ae7893e077e98759316fe279"
integrity sha512-mJGfgj4aWpiKb8C0nnJJchs1sHBHn0HugkVfqqyQi7Wn6mBRksLeQsPOFvih/Pu8L1vlDzfe/LidhVHBeUk3aQ==
"@types/ms@*":
version "0.7.31"
@ -1993,7 +1993,7 @@ array.prototype.flatmap@^1.2.5:
ast-types-flow@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ast-types-flow/-/ast-types-flow-0.0.7.tgz#f70b735c6bca1a5c9c22d982c3e39e7feba3bdad"
integrity sha1-9wtzXGvKGlycItmCw+Oef+ujva0=
integrity sha512-eBvWn1lvIApYMhzQMsu9ciLfkBY499mFZlNqG+/9WR7PVlroQw0vG30cOQQbaKz3sCEc44TAOu2ykzqXSNnwag==
astral-regex@^2.0.0:
version "2.0.0"
@ -2069,7 +2069,7 @@ base64-js@^1.2.0:
boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24=
integrity sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==
boxen@^5.0.1:
version "5.1.2"
@ -2114,7 +2114,7 @@ browserslist@^4.20.2, browserslist@^4.20.3:
btoa-lite@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=
integrity sha512-gvW7InbIyF8AicrqWoptdW08pUxuhq8BEgowNajy9RhiE86fmGAGl+bLKo6oB8QP0CkqHLowfN0oJdKC/J6LbA==
call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2"
@ -3023,7 +3023,7 @@ fast-diff@^1.1.2:
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
fast-glob@^3.2.9:
fast-glob@^3.2.11, fast-glob@^3.2.9:
version "3.2.11"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
@ -3265,9 +3265,9 @@ glob@7.1.7:
path-is-absolute "^1.0.0"
glob@^7.1.3, glob@^7.2.0:
version "7.2.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.2.tgz#29deb38e1ef90f132d5958abe9c3ee8e87f3c318"
integrity sha512-NzDgHDiJwKYByLrL5lONmQFpK/2G78SMMfo+E9CuGlX4IkvfKDsiQSNPwAYxEy+e6p7ZQ3uslSLlwlJcqezBmQ==
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
@ -5244,11 +5244,6 @@ react@18.1.0:
dependencies:
loose-envify "^1.1.0"
reading-time@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/reading-time/-/reading-time-1.5.0.tgz#d2a7f1b6057cb2e169beaf87113cc3411b5bc5bb"
integrity sha512-onYyVhBNr4CmAxFsKS7bz+uTLRakypIe4R+5A824vBSkQy/hB3fZepoVEf8OVAxzLvK+H/jm9TzpI3ETSm64Kg==
refractor@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/refractor/-/refractor-4.7.0.tgz#aad649d7857acdc0d5792f1a7900867256941ac0"
@ -5707,10 +5702,10 @@ simple-git-hooks@^2.7.0:
resolved "https://registry.yarnpkg.com/simple-git-hooks/-/simple-git-hooks-2.7.0.tgz#121a5c3023663b8abcc5648c8bfe8619dc263705"
integrity sha512-nQe6ASMO9zn5/htIrU37xEIHGr9E6wikXelLbOeTcfsX2O++DHaVug7RSQoq+kO7DvZTH37WA5gW49hN9HTDmQ==
simple-icons@^6.21.0:
version "6.21.0"
resolved "https://registry.yarnpkg.com/simple-icons/-/simple-icons-6.21.0.tgz#96f675f68076e7b42575d7e4c7afaeb798b05c1b"
integrity sha512-+DRxJwF66C5ZOgYUIy4BfD+algfVaRKfKT7Qs8TtvPSCfc7+BUoKh5Udfa0zPHsUc8BmAuflcTrQqVv+5XpY6g==
simple-icons@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/simple-icons/-/simple-icons-6.22.0.tgz#7f3856094da86c62e2f859fb28a9bec6dd858387"
integrity sha512-OJJEPpb6WJjT7imJaZT31knu2Q2fb/JJ42xbwA7jC9WUZAbEtmFmaNlQ4L2jzCda5TfVx1SR+1K89evWaokseg==
sirv@^1.0.7:
version "1.0.19"