mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-09-13 21:55:30 -04:00
some very minor refactoring/fixing
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -2,6 +2,9 @@
|
||||
"editor.tabSize": 2,
|
||||
"editor.insertSpaces": true,
|
||||
"editor.rulers": [120],
|
||||
"files.associations": {
|
||||
"*.mdx": "markdown"
|
||||
},
|
||||
"files.eol": "\n",
|
||||
"files.insertFinalNewline": true,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
|
@@ -1,8 +1,6 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import copy from "copy-to-clipboard";
|
||||
import trimNewlines from "trim-newlines";
|
||||
|
||||
// react components:
|
||||
import { CopyIcon, CheckIcon } from "@primer/octicons-react";
|
||||
|
||||
import styles from "./CopyButton.module.scss";
|
||||
|
@@ -2,7 +2,7 @@ import useSWR from "swr";
|
||||
import { fetcher } from "../../lib/fetcher";
|
||||
import Loading from "../loading/Loading";
|
||||
|
||||
export default function Counter({ slug }) {
|
||||
export default function Hits({ slug }) {
|
||||
// start fetching repos from API immediately
|
||||
const { data, error } = useSWR(`/api/hits/?slug=${encodeURIComponent(slug)}`, fetcher, {
|
||||
// avoid double (or more) counting views
|
||||
|
@@ -2,7 +2,7 @@ import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import TweetEmbed from "react-tweet-embed";
|
||||
import Gist from "react-gist";
|
||||
import getNodeText from "../lib/getNodeText";
|
||||
import getNodeText from "../lib/get-node-text";
|
||||
import Video from "./video/FullPageVideo";
|
||||
import CopyButton from "./clipboard/CopyButton";
|
||||
import { MarkGithubIcon } from "@primer/octicons-react";
|
||||
|
@@ -18,5 +18,7 @@ export default function List({ allNotes }) {
|
||||
);
|
||||
});
|
||||
|
||||
return <>{sections.reverse()}</>;
|
||||
const reversed = sections.reverse();
|
||||
|
||||
return <>{reversed}</>;
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ type Props = {
|
||||
title: unknown;
|
||||
};
|
||||
|
||||
export default function Content({ title }: Props) {
|
||||
export default function PageTitle({ title }: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
|
@@ -1,6 +1,4 @@
|
||||
import { intlFormat, formatDistanceToNowStrict, parseISO } from "date-fns";
|
||||
|
||||
// react components:
|
||||
import { StarIcon, RepoForkedIcon } from "@primer/octicons-react";
|
||||
|
||||
import styles from "./RepositoryCard.module.scss";
|
||||
|
@@ -4,14 +4,12 @@ import matter from "gray-matter";
|
||||
|
||||
export const NOTES_PATH = path.join(process.cwd(), "notes");
|
||||
|
||||
export function getNoteSlugs() {
|
||||
return fs.readdirSync(NOTES_PATH);
|
||||
}
|
||||
export const getNoteSlugs = () => fs.readdirSync(NOTES_PATH);
|
||||
|
||||
// Return all md(x) files in NOTES_PATH
|
||||
export const notePaths = getNoteSlugs().filter((path) => /\.mdx?$/.test(path));
|
||||
export const notePaths = getNoteSlugs().filter((notePath) => /\.mdx?$/.test(notePath));
|
||||
|
||||
export function getNoteBySlug(slug, fields = []) {
|
||||
export const getNoteBySlug = (slug, fields = []) => {
|
||||
const realSlug = slug.replace(/\.mdx$/, "");
|
||||
const fullPath = path.join(NOTES_PATH, `${realSlug}.mdx`);
|
||||
const fileContents = fs.readFileSync(fullPath, "utf8");
|
||||
@@ -34,13 +32,10 @@ export function getNoteBySlug(slug, fields = []) {
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
};
|
||||
|
||||
export function getAllNotes(fields = []) {
|
||||
const slugs = getNoteSlugs();
|
||||
const notes = slugs
|
||||
export const getAllNotes = (fields = []) =>
|
||||
getNoteSlugs()
|
||||
.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;
|
||||
}
|
@@ -7,6 +7,10 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
|
||||
});
|
||||
|
||||
module.exports = withBundleAnalyzer({
|
||||
i18n: {
|
||||
locales: ["en-us"],
|
||||
defaultLocale: "en-us",
|
||||
},
|
||||
swcMinify: true,
|
||||
reactStrictMode: true,
|
||||
trailingSlash: true,
|
||||
|
@@ -1,13 +1,10 @@
|
||||
// @ts-nocheck
|
||||
// ^ type checking causes a bunch of issues in DefaultSeo, BE CAREFUL
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import Script from "next/script";
|
||||
import type { AppProps } from "next/app";
|
||||
import { DefaultSeo, SocialProfileJsonLd } from "next-seo";
|
||||
import * as Fathom from "fathom-client";
|
||||
import * as config from "../lib/config";
|
||||
import type { AppProps } from "next/app";
|
||||
|
||||
import meJpg from "../public/static/images/me.jpg";
|
||||
import faviconIco from "../public/static/images/favicon.ico";
|
||||
@@ -41,6 +38,7 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* @ts-ignore */}
|
||||
<DefaultSeo
|
||||
defaultTitle={`${config.siteName} – ${config.shortDescription}`}
|
||||
titleTemplate={`%s – ${config.siteName}`}
|
||||
|
@@ -1,15 +0,0 @@
|
||||
import Document, { Html, Head, Main, NextScript } from "next/document";
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
render() {
|
||||
return (
|
||||
<Html lang="en-us">
|
||||
<Head />
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import { getAllNotes } from "../lib/parseNotes";
|
||||
import { buildFeed } from "../lib/buildFeed";
|
||||
import { getAllNotes } from "../lib/parse-notes";
|
||||
import { buildFeed } from "../lib/build-feed";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { getAllNotes } from "../lib/parseNotes";
|
||||
import { buildFeed } from "../lib/buildFeed";
|
||||
import { getAllNotes } from "../lib/parse-notes";
|
||||
import { buildFeed } from "../lib/build-feed";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
|
@@ -8,7 +8,7 @@ import Layout from "../../components/Layout";
|
||||
import Container from "../../components/Container";
|
||||
import Content from "../../components/Content";
|
||||
import Meta from "../../components/notes/Meta";
|
||||
import { notePaths, NOTES_PATH } from "../../lib/parseNotes";
|
||||
import { notePaths, NOTES_PATH } from "../../lib/parse-notes";
|
||||
import mdxComponents from "../../components/mdxComponents";
|
||||
import * as config from "../../lib/config";
|
||||
import type { GetStaticProps, GetStaticPaths } from "next";
|
||||
@@ -102,7 +102,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const paths = notePaths
|
||||
// Remove file extensions for page paths
|
||||
.map((path) => path.replace(/\.mdx?$/, ""))
|
||||
.map((notePath) => notePath.replace(/\.mdx?$/, ""))
|
||||
// Map the path into the static paths object required by Next.js
|
||||
.map((slug) => ({ params: { slug } }));
|
||||
|
||||
|
@@ -3,7 +3,7 @@ import groupBy from "lodash.groupby";
|
||||
import Layout from "../../components/Layout";
|
||||
import Container from "../../components/Container";
|
||||
import List from "../../components/notes/List";
|
||||
import { getAllNotes } from "../../lib/parseNotes";
|
||||
import { getAllNotes } from "../../lib/parse-notes";
|
||||
import type { GetStaticProps } from "next";
|
||||
|
||||
export default function Notes({ allNotes }) {
|
||||
|
@@ -1,3 +0,0 @@
|
||||
// Browser reset:
|
||||
// https://github.com/sindresorhus/modern-normalize
|
||||
@import "~modern-normalize/modern-normalize.css";
|
@@ -1,4 +1,7 @@
|
||||
@use "reset";
|
||||
// Browser reset:
|
||||
// https://github.com/sindresorhus/modern-normalize
|
||||
@import "~modern-normalize/modern-normalize.css";
|
||||
|
||||
@use "typography";
|
||||
@use "colors";
|
||||
@use "syntax";
|
||||
|
Reference in New Issue
Block a user