v5: Revenge of the JavaScript 🦸 (#711)

Hugo ➡️ Next.js
This commit is contained in:
2021-12-30 08:18:41 -05:00
committed by GitHub
parent b7505fa260
commit 9979e1bf3f
577 changed files with 8019 additions and 11864 deletions
+42
View File
@@ -0,0 +1,42 @@
import { Feed } from "feed";
import * as config from "./config";
export const buildFeed = (notes: any[]) => {
const feed = new Feed({
id: `${config.baseURL}/`,
link: `${config.baseURL}/`,
title: config.siteName,
description: config.longDescription,
copyright: "CC-BY-4.0",
updated: new Date(),
image: `${config.baseURL}/static/images/me.jpg`,
feedLinks: {
rss: `${config.baseURL}/feed.xml`,
atom: `${config.baseURL}/feed.atom`,
},
author: {
name: config.authorName,
link: config.baseURL,
email: "jake@jarv.is",
},
});
notes.forEach((note: { title: any; slug: any; description: any; image: any; date: string | number | Date }) => {
feed.addItem({
title: note.title,
link: `${config.baseURL}/notes/${note.slug}/`,
guid: `${config.baseURL}/notes/${note.slug}/`,
description: note.description,
image: note.image ? `${config.baseURL}${note.image}` : "",
author: [
{
name: config.authorName,
link: config.baseURL,
},
],
date: new Date(note.date),
});
});
return feed;
};
+26
View File
@@ -0,0 +1,26 @@
// Site info
export const siteName = "Jake Jarvis";
export const siteDomain = "https://jarv.is";
export const shortDescription = "Front-End Web Developer in Boston, MA 👨‍💻";
export const longDescription =
"Hi there! I'm a frontend web developer based in Boston, Massachusetts specializing in the JAMstack, modern JavaScript frameworks, and progressive web apps.";
export const githubRepo = "jakejarvis/jarv.is";
let baseURL = ""; // default to relative URLs
if (process.env.NEXT_PUBLIC_VERCEL_ENV === "production") {
// vercel production (set manually above)
baseURL = siteDomain;
} else if (process.env.NEXT_PUBLIC_VERCEL_URL) {
// vercel deploy previews
baseURL = `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`;
}
export { baseURL };
// Me info
export const authorName = "Jake Jarvis";
export const twitterHandle = "jakejarvis";
export const facebookAppId = "3357248167622283";
export const webmentionId = "jarv.is";
export const monetization = "$ilp.uphold.com/BJp6d2FrEB69";
// ...note / TODO: there is still a metric poop ton of this kind of info hard-coded.
+7
View File
@@ -0,0 +1,7 @@
// very simple fetch wrapper that's passed into SWR hooks:
// https://swr.vercel.app/docs/data-fetching#fetch
// note: fetch does *not* need to be poly/ponyfilled in Next.js:
// https://nextjs.org/blog/next-9-1-7#new-built-in-polyfills-fetch-url-and-objectassign
// eslint-disable-next-line no-undef
export const fetcher = (url: RequestInfo) => fetch(url).then((res) => res.json());
+16
View File
@@ -0,0 +1,16 @@
// https://stackoverflow.com/a/60564620/1438024
const getNodeText = (node) => {
if (["string", "number"].includes(typeof node)) {
return node;
}
if (node instanceof Array) {
return node.map(getNodeText).join("");
}
if (typeof node === "object" && node) {
return getNodeText(node.props.children);
}
};
export default getNodeText;
+46
View File
@@ -0,0 +1,46 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
export const NOTES_PATH = path.join(process.cwd(), "notes");
export function getNoteSlugs() {
return fs.readdirSync(NOTES_PATH);
}
// Return all md(x) files in NOTES_PATH
export const notePaths = getNoteSlugs().filter((path) => /\.mdx?$/.test(path));
export function getNoteBySlug(slug, fields = []) {
const realSlug = slug.replace(/\.mdx$/, "");
const fullPath = path.join(NOTES_PATH, `${realSlug}.mdx`);
const fileContents = fs.readFileSync(fullPath, "utf8");
const { data, content } = matter(fileContents);
const items = {};
// Ensure only the minimal needed data is exposed
fields.forEach((field) => {
if (field === "slug") {
items[field] = realSlug;
}
if (field === "content") {
items[field] = content;
}
if (typeof data[field] !== "undefined") {
items[field] = data[field];
}
});
return items;
}
export function getAllNotes(fields = []) {
const slugs = getNoteSlugs();
const notes = slugs
.map((slug) => getNoteBySlug(slug, fields))
// sort notes by date in descending order
.sort((note1: any, note2: any) => (note1.date > note2.date ? -1 : 1));
return notes;
}