mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-10-27 21:25:48 -04:00
add getStaticProps types
This commit is contained in:
@@ -26,7 +26,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
// these are both backups to client-side validations just in case someone squeezes through without them. the codes
|
||||
// are identical so they're caught in the same fashion.
|
||||
if (!body || !body.name || !body.email || !body.message) {
|
||||
if (!body.name || !body.email || !body.message) {
|
||||
// all fields are required
|
||||
throw new Error("USER_MISSING_DATA");
|
||||
}
|
||||
@@ -63,7 +63,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
};
|
||||
|
||||
const validateCaptcha = async (formResponse: unknown) => {
|
||||
const validateCaptcha = async (formResponse: unknown): Promise<unknown> => {
|
||||
const response = await fetch(HCAPTCHA_API_ENDPOINT, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -76,13 +76,12 @@ const validateCaptcha = async (formResponse: unknown) => {
|
||||
}),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const result: any = await response.json();
|
||||
const result = await response.json();
|
||||
|
||||
return result.success as boolean;
|
||||
return result.success;
|
||||
};
|
||||
|
||||
const sendToAirtable = async (data: unknown) => {
|
||||
const sendToAirtable = async (data: unknown): Promise<boolean> => {
|
||||
const response = await fetch(`${AIRTABLE_API_ENDPOINT}${AIRTABLE_BASE}/Messages`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -54,7 +54,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
await logServerError(error);
|
||||
|
||||
// 500 Internal Server Error
|
||||
return res.status(500).json({ success: false, message });
|
||||
return res.status(500).json({ message });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,7 +75,7 @@ const getAccessToken = async () => {
|
||||
|
||||
const { access_token: token } = await response.json();
|
||||
|
||||
return token as string;
|
||||
return token;
|
||||
};
|
||||
|
||||
const getNowPlaying = async (token: string): Promise<Track | false> => {
|
||||
@@ -120,7 +120,7 @@ const getTopTracks = async (token: string): Promise<Track[]> => {
|
||||
|
||||
const { items } = (await response.json()) as { items: SpotifyTrackSchema[] };
|
||||
|
||||
const tracks: Track[] = items.map((track: SpotifyTrackSchema) => ({
|
||||
const tracks = items.map<Track>((track) => ({
|
||||
artist: track.artists.map((artist) => artist.name).join(", "),
|
||||
title: track.name,
|
||||
album: track.album.name,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { buildFeed } from "../lib/helpers/build-feed";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
|
||||
return buildFeed(context, "atom");
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { buildFeed } from "../lib/helpers/build-feed";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
|
||||
return buildFeed(context, "rss");
|
||||
};
|
||||
|
||||
|
||||
@@ -69,8 +69,14 @@ const Note = ({ frontMatter, source }: NoteWithSource) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
const { frontMatter, source } = await compileNote((params as Pick<NoteFrontMatter, "slug">).slug);
|
||||
export const getStaticProps: GetStaticProps<NoteWithSource, Pick<NoteFrontMatter, "slug">> = async ({ params }) => {
|
||||
if (!params || !params.slug) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const { frontMatter, source } = await compileNote(params.slug);
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import { NextSeo } from "next-seo";
|
||||
import Content from "../../components/Content";
|
||||
import NotesList, { NotesListProps } from "../../components/NotesList";
|
||||
import NotesList from "../../components/NotesList";
|
||||
import { getAllNotes } from "../../lib/helpers/parse-notes";
|
||||
import { authorName } from "../../lib/config";
|
||||
import type { GetStaticProps } from "next";
|
||||
import type { NotesByYear } from "../../types";
|
||||
|
||||
const Notes = ({ notesByYear }: NotesListProps) => {
|
||||
type StaticProps = {
|
||||
notesByYear: NotesByYear;
|
||||
};
|
||||
|
||||
const Notes = ({ notesByYear }: StaticProps) => {
|
||||
return (
|
||||
<>
|
||||
<NextSeo
|
||||
title="Notes"
|
||||
description="Recent posts by Jake Jarvis."
|
||||
description={`Recent posts by ${authorName}.`}
|
||||
openGraph={{
|
||||
title: "Notes",
|
||||
}}
|
||||
@@ -22,10 +28,10 @@ const Notes = ({ notesByYear }: NotesListProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps = async () => {
|
||||
export const getStaticProps: GetStaticProps<StaticProps> = async () => {
|
||||
// parse the year of each note and group them together
|
||||
const notes = await getAllNotes();
|
||||
const notesByYear: NotesListProps["notesByYear"] = {};
|
||||
const notesByYear: NotesByYear = {};
|
||||
|
||||
notes.forEach((note) => {
|
||||
const year = new Date(note.date).getUTCFullYear();
|
||||
|
||||
@@ -42,7 +42,11 @@ const GitHubLogo = styled(OctocatOcticon, {
|
||||
fill: "$text",
|
||||
});
|
||||
|
||||
const Projects = ({ repos }: { repos: Project[] }) => {
|
||||
type StaticProps = {
|
||||
repos: Project[];
|
||||
};
|
||||
|
||||
const Projects = ({ repos }: StaticProps) => {
|
||||
return (
|
||||
<>
|
||||
<NextSeo
|
||||
@@ -71,7 +75,7 @@ const Projects = ({ repos }: { repos: Project[] }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps = async () => {
|
||||
export const getStaticProps: GetStaticProps<StaticProps> = async () => {
|
||||
// don't fail the entire site build if the required API key for this page is missing
|
||||
if (typeof process.env.GH_PUBLIC_TOKEN === "undefined" || process.env.GH_PUBLIC_TOKEN === "") {
|
||||
console.warn(`ERROR: I can't fetch any GitHub projects without "GH_PUBLIC_TOKEN" set! Skipping for now...`);
|
||||
@@ -130,11 +134,11 @@ export const getStaticProps: GetStaticProps = async () => {
|
||||
const repos = results.map<Project>(({ node: repo }) => ({
|
||||
name: repo.name,
|
||||
url: repo.url,
|
||||
description: repo.description as string | undefined,
|
||||
description: repo.description as string,
|
||||
updatedAt: repo.pushedAt,
|
||||
stars: repo.stargazerCount,
|
||||
forks: repo.forkCount,
|
||||
language: repo.primaryLanguage as Project["language"] | undefined,
|
||||
language: repo.primaryLanguage as Project["language"],
|
||||
}));
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as config from "../lib/config";
|
||||
import { favicons } from "../lib/config/seo";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
|
||||
const manifest = {
|
||||
name: config.siteName,
|
||||
short_name: config.siteDomain,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { baseUrl } from "../lib/config";
|
||||
import { RELEASE_DATE } from "../lib/config/constants";
|
||||
import type { GetServerSideProps } from "next";
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
export const getServerSideProps: GetServerSideProps<Record<string, never>> = async (context) => {
|
||||
const stream = new SitemapStream({ hostname: baseUrl });
|
||||
|
||||
// TODO: make this not manual (serverless functions can't see filesystem at runtime)
|
||||
|
||||
Reference in New Issue
Block a user