Skip to content

Commit

Permalink
Migrate metadata to new file based metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
oBusk committed Apr 10, 2023
1 parent 900a3ee commit 04339a3
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 235 deletions.
Binary file removed public/favicon-16x16.png
Binary file not shown.
Binary file removed public/favicon-32x32.png
Binary file not shown.
17 changes: 7 additions & 10 deletions src/app/[...parts]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Button, Center, Code } from "@chakra-ui/react";
import { useEffect } from "react";
import { MetaData } from "^/lib/metaData";
import type { ErrorComponent } from "^/next";
import ErrorBox from "./_error/ErrorBox";

Expand All @@ -15,15 +14,13 @@ const DiffError: ErrorComponent = ({ error: error, reset }) => {
}, [message]);

return (
<MetaData title="Error">
<Center>
<ErrorBox>
<h3>Something Went Wrong</h3>
<Code maxWidth={700}>{`${message}`}</Code>
<Button onClick={reset}>Try Again</Button>
</ErrorBox>
</Center>
</MetaData>
<Center>
<ErrorBox>
<h3>Something Went Wrong</h3>
<Code maxWidth={700}>{`${message}`}</Code>
<Button onClick={reset}>Try Again</Button>
</ErrorBox>
</Center>
);
};

Expand Down
8 changes: 2 additions & 6 deletions src/app/[...parts]/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { FunctionComponent, ReactNode } from "react";
import DiffOptions from "^/lib/DiffOptions";
import { MetaData } from "^/lib/metaData";
import SimplePackageSpec from "^/lib/SimplePackageSpec";
import DiffIntro from "./_page/DiffIntro";

Expand All @@ -21,10 +20,7 @@ const DiffPageClient: FunctionComponent<DiffPageClientProps> = ({
services,
diffResults,
}) => (
<MetaData
title={`Comparing ${a.name}@${a.version}...${b.name}@${b.version}`}
description={`A diff between the npm packages "${a.name}@${a.version}" and "${b.name}@${b.version}"`}
>
<>
<DiffIntro
alignSelf="stretch"
a={a}
Expand All @@ -33,7 +29,7 @@ const DiffPageClient: FunctionComponent<DiffPageClientProps> = ({
options={options}
/>
{diffResults}
</MetaData>
</>
);

export default DiffPageClient;
23 changes: 17 additions & 6 deletions src/app/[...parts]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ import PackagephobiaDiff from "./_page/PackagephobiaDiff";
import { DIFF_TYPE_PARAM_NAME } from "./_page/paramNames";
import DiffPageClient from "./page.client";

export interface DiffPageProps {
params: { parts: string | string[] };
searchParams: QueryParams & { [DIFF_TYPE_PARAM_NAME]: ViewType };
}

export function generateMetadata({ params: { parts } }: DiffPageProps) {
const specs = splitParts(decodePartts(parts));

const [a, b] = specs.map((spec) => parseSimplePackageSpec(spec));

return {
title: `Comparing ${a.name}@${a.version}...${b.name}@${b.version}`,
description: `A diff between the npm packages "${a.name}@${a.version}" and "${b.name}@${b.version}"`,
};
}

// Ensure static rendering https://beta.nextjs.org/docs/api-reference/segment-config#dynamic
export const dynamic = "force-static";

Expand All @@ -26,15 +42,10 @@ export function generateStaticParams() {

// We need nodejs since we use Npm libs https://beta.nextjs.org/docs/api-reference/segment-config#runtime
export const runtime = "nodejs";
// TODO: Set title and description using `head.tsx` so that they
// are set before `useEffect()`
const DiffPage = async ({
params: { parts },
searchParams,
}: {
params: { parts: string | string[] };
searchParams: QueryParams & { [DIFF_TYPE_PARAM_NAME]: ViewType };
}): Promise<JSX.Element> => {
}: DiffPageProps): Promise<JSX.Element> => {
const { diffFiles, ...optionsQuery } = searchParams;

const specsOrVersions = splitParts(decodePartts(parts));
Expand Down
79 changes: 38 additions & 41 deletions src/app/about/api/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { Code, Heading, Text, VStack } from "@chakra-ui/react";
import ExternalLink from "^/components/ExternalLink";
import Tooltip from "^/components/Tooltip";
import { MetaData } from "^/lib/metaData";

export interface AboutApiPageClientProps {
diff: string;
Expand All @@ -15,48 +14,46 @@ const AboutApiPageClient = ({
specs,
exampleAbsoluteUrl,
}: AboutApiPageClientProps) => (
<MetaData title="API" description="API documentation for npm-diff.app">
<VStack p={5} shadow="md" borderWidth="1px" spacing={8}>
<Heading as="h2" size="lg">
npm-diff.app API
</Heading>
<Text>
npm-diff.app exposes a online API to equal{" "}
<ExternalLink href="https://docs.npmjs.com/cli/v7/commands/npm-diff">
<Code>npm diff</Code>
</ExternalLink>
, to be able to see the changes between versions of packages or
forks of packages.
</Text>
<VStack p={5} shadow="md" borderWidth="1px" spacing={8}>
<Heading as="h2" size="lg">
npm-diff.app API
</Heading>
<Text>
npm-diff.app exposes a online API to equal{" "}
<ExternalLink href="https://docs.npmjs.com/cli/v7/commands/npm-diff">
<Code>npm diff</Code>
</ExternalLink>
, to be able to see the changes between versions of packages or
forks of packages.
</Text>

<Text>
<Code>
GET{" "}
<Tooltip label="Click to view the response from the API">
<ExternalLink href={exampleAbsoluteUrl}>
{exampleAbsoluteUrl}
</ExternalLink>
</Tooltip>
</Code>
<br />
will return the same as
<br />
<Code>
npm diff --diff={specs[0]} --diff={specs[1]}
</Code>
</Text>
<Text>
a <Text as="i">diff</Text> of the two provided packages
</Text>
<Code
as="pre"
whiteSpace="pre-wrap"
display={{ base: "none", lg: "initial" }}
>
{diff}
<Text>
<Code>
GET{" "}
<Tooltip label="Click to view the response from the API">
<ExternalLink href={exampleAbsoluteUrl}>
{exampleAbsoluteUrl}
</ExternalLink>
</Tooltip>
</Code>
</VStack>
</MetaData>
<br />
will return the same as
<br />
<Code>
npm diff --diff={specs[0]} --diff={specs[1]}
</Code>
</Text>
<Text>
a <Text as="i">diff</Text> of the two provided packages
</Text>
<Code
as="pre"
whiteSpace="pre-wrap"
display={{ base: "none", lg: "initial" }}
>
{diff}
</Code>
</VStack>
);

export default AboutApiPageClient;
6 changes: 6 additions & 0 deletions src/app/about/api/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Metadata } from "next";
import destination from "^/lib/destination";
import doDiff from "^/lib/diff";
import EXAMPLES from "^/lib/examples";
Expand All @@ -13,6 +14,11 @@ const EXAMPLE_RELATIVE_LINK = `${API_PATH}/${EXAMPLE_QUERY}` as const;
const DOMAIN = "https://npm-diff.app";
const EXAMPLE_ABSOLUTE_URL = `${DOMAIN}${EXAMPLE_RELATIVE_LINK}` as const;

export const metadata = {
title: "API",
description: "API documentation for npm-diff.app",
} satisfies Metadata;

// Ensure static rendering https://beta.nextjs.org/docs/api-reference/segment-config#dynamic
export const dynamic = "force-static";
// We need nodejs since we use Npm libs https://beta.nextjs.org/docs/api-reference/segment-config#runtime
Expand Down
131 changes: 62 additions & 69 deletions src/app/about/page.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
VStack,
} from "@chakra-ui/react";
import NextImage from "next/image";
import { defaultMetaData, MetaData } from "^/lib/metaData";
import {
externalServicesDarkmode,
externalServicesLightmode,
Expand All @@ -21,74 +20,68 @@ const AboutPageClient = () => {
);

return (
<MetaData title="About">
<VStack p={5} shadow="md" borderWidth="1px" spacing={8}>
<Heading as="h2" size="lg">
About npm-diff.app
</Heading>
<Text>{defaultMetaData.description}</Text>
<Text>
The comparing matches the behaviour of the CLI by using the
official{" "}
<Link
href="https://npmjs.com/libnpmdiff"
rel="noreferrer noopener"
target="_blank"
>
<Code>libnpmdiff</Code>
</Link>{" "}
package to perform a diff between the packages you chose. We
then visualize the differance.
</Text>
<Heading as="h3" size="md">
Redirection
</Heading>
<Text>
For the URL you can use formats that are not exact, like:{" "}
<Link
href="https://npm-diff.app/[email protected]...~4.17.15"
rel="noreferrer noopener"
target="_blank"
>
<Code>
https://npm-diff.app/[email protected]...~4.17.15
</Code>
</Link>{" "}
or{" "}
<Link
href="https://npm-diff.app/[email protected]@latest"
rel="noreferrer noopener"
target="_blank"
>
<Code>
https://npm-diff.app/[email protected]@latest
</Code>
</Link>
. If you go to any URL which is not exact, and therefore can
change over time, we will redirect you to the exact URL. You
will be redirected to an exact, canonical URL. This means
you will get a cached version even if you used a unique
query.
</Text>
<Heading as="h3" size="md">
External services
</Heading>
<NextImage
src={externalServicesImage}
alt="Screenshot of external services in npm-diff.app"
priority
style={{ width: "auto", height: "auto" }}
/>
<Text>
We also use external services{" "}
<Link href="https://bundlephobia.com">bundlephobia</Link>{" "}
and{" "}
<Link href="https://packagephobia.com">packagephobia</Link>{" "}
to give an overview of the differances between the two,
measured in install and bundle size.
</Text>
</VStack>
</MetaData>
<VStack p={5} shadow="md" borderWidth="1px" spacing={8}>
<Heading as="h2" size="lg">
About npm-diff.app
</Heading>
<Text>Inspect changes between npm packages in a webapp</Text>
<Text>
The comparing matches the behaviour of the CLI by using the
official{" "}
<Link
href="https://npmjs.com/libnpmdiff"
rel="noreferrer noopener"
target="_blank"
>
<Code>libnpmdiff</Code>
</Link>{" "}
package to perform a diff between the packages you chose. We
then visualize the differance.
</Text>
<Heading as="h3" size="md">
Redirection
</Heading>
<Text>
For the URL you can use formats that are not exact, like:{" "}
<Link
href="https://npm-diff.app/[email protected]...~4.17.15"
rel="noreferrer noopener"
target="_blank"
>
<Code>https://npm-diff.app/[email protected]...~4.17.15</Code>
</Link>{" "}
or{" "}
<Link
href="https://npm-diff.app/[email protected]@latest"
rel="noreferrer noopener"
target="_blank"
>
<Code>
https://npm-diff.app/[email protected]@latest
</Code>
</Link>
. If you go to any URL which is not exact, and therefore can
change over time, we will redirect you to the exact URL. You
will be redirected to an exact, canonical URL. This means you
will get a cached version even if you used a unique query.
</Text>
<Heading as="h3" size="md">
External services
</Heading>
<NextImage
src={externalServicesImage}
alt="Screenshot of external services in npm-diff.app"
priority
style={{ width: "auto", height: "auto" }}
/>
<Text>
We also use external services{" "}
<Link href="https://bundlephobia.com">bundlephobia</Link> and{" "}
<Link href="https://packagephobia.com">packagephobia</Link> to
give an overview of the differances between the two, measured in
install and bundle size.
</Text>
</VStack>
);
};

Expand Down
5 changes: 5 additions & 0 deletions src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Metadata } from "next";
import AboutPageClient from "./page.client";

export const metadata = {
title: "About",
} satisfies Metadata;

// Ensure static rendering https://beta.nextjs.org/docs/api-reference/segment-config#dynamic
export const dynamic = "force-static";
// TODO export const runtime = "experimental-edge";
Expand Down
File renamed without changes
File renamed without changes.
Binary file added src/app/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 04339a3

Please sign in to comment.