mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-01-14 10:42:56 -05:00
don't load fathom script unless on production
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user