Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.0 #7

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9979af2
Bump @mui/icons-material from 5.15.19 to 5.15.20
dependabot[bot] Jun 13, 2024
25c66d5
Bump next-mdx-remote from 4.4.1 to 5.0.0
dependabot[bot] Jun 13, 2024
eb48da9
💄 (components/Hero) Adjust primary button color based on current scro…
simonwoerpel Jun 14, 2024
05fb146
Bump docker/build-push-action from 5 to 6
dependabot[bot] Jun 17, 2024
7b86af3
Merge pull request #5 from investigativedata/dependabot/github_action…
simonwoerpel Jun 18, 2024
e631c59
Merge pull request #3 from investigativedata/dependabot/npm_and_yarn/…
simonwoerpel Jun 18, 2024
ed9606f
Bump typescript from 5.4.5 to 5.5.3
dependabot[bot] Jul 2, 2024
616c083
Bump @types/node from 20.14.2 to 20.14.10
dependabot[bot] Jul 8, 2024
b771d00
Bump @mui/icons-material from 5.15.20 to 5.16.1
dependabot[bot] Jul 11, 2024
10bc3b0
🔐 Add security.txt
simonwoerpel Jul 12, 2024
b4f56ed
Merge pull request #19 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 12, 2024
a43b0a2
Merge pull request #18 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 12, 2024
5139c46
Merge pull request #16 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 12, 2024
63c7044
Merge pull request #4 from investigativedata/dependabot/npm_and_yarn/…
simonwoerpel Jul 12, 2024
626c452
Bump eslint-config-next from 14.2.4 to 14.2.5
dependabot[bot] Jul 12, 2024
78b4fdb
Bump @mui/joy from 5.0.0-beta.36 to 5.0.0-beta.48
dependabot[bot] Jul 12, 2024
b726a01
Bump @next/mdx from 14.2.4 to 14.2.5
dependabot[bot] Jul 12, 2024
0082c7e
Bump @directus/sdk from 16.1.0 to 16.1.1
dependabot[bot] Jul 15, 2024
595e0d9
✨ Newsletter sign-up
simonwoerpel Jul 18, 2024
f42c5e4
Merge pull request #23 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 18, 2024
03fb855
Merge pull request #22 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 18, 2024
9d1a4a0
Merge branch 'develop' into dependabot/npm_and_yarn/develop/mui/joy-5…
simonwoerpel Jul 18, 2024
b6c99c7
Merge pull request #21 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 18, 2024
361feab
Merge pull request #20 from investigativedata/dependabot/npm_and_yarn…
simonwoerpel Jul 18, 2024
0bdbc84
⬆️ Upgrade next.js
simonwoerpel Jul 30, 2024
17b40c9
💄 (components) Improve NewsletterForm
simonwoerpel Nov 28, 2024
4578400
✨ (components) File
simonwoerpel Jan 23, 2025
83c14b8
✨ (mdx) Add table support via remark-gfm
simonwoerpel Jan 23, 2025
a208752
⬆️ All the things
simonwoerpel Jan 23, 2025
59fb4a5
⚡️ (next) Dynamic APIs are Asynchronous
simonwoerpel Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push release
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
secrets: |
Expand Down
2 changes: 1 addition & 1 deletion _api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function GET(request: Request) {
return new Response("Invalid id", { status: 401 });
}

draftMode().enable();
(await draftMode()).enable();

return new Response(null, {
status: 307,
Expand Down
22 changes: 12 additions & 10 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ type IParams = {
readonly slug?: string[];
};

export async function generateMetadata({
params,
}: {
params: IParams;
}): Promise<Metadata> {
export async function generateMetadata(
props: {
params: Promise<IParams>;
}
): Promise<Metadata> {
const params = await props.params;
const data = await getPage(params.slug || ["index"]);
return {
title: `${data.title} – ${DEFAULT_TITLE}`,
Expand All @@ -28,11 +29,12 @@ const getPageMenu = (screens: IScreen[]): IPageMenuItem[] =>
.filter(({ item }) => !!item.anchor)
.map(({ item }) => ({ label: item.name, href: `#${slugify(item.name)}` }));

export default async function SlugPage({
params,
}: {
params: { slug: string[] };
}) {
export default async function SlugPage(
props: {
params: Promise<{ slug: string[] }>;
}
) {
const params = await props.params;
if (params.slug.length === 1 && params.slug[0] === "index") {
return permanentRedirect("/");
}
Expand Down
11 changes: 6 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ type IParams = {
readonly slug?: string[];
};

export async function generateMetadata({
params,
}: {
params: IParams;
}): Promise<Metadata> {
export async function generateMetadata(
props: {
params: Promise<IParams>;
}
): Promise<Metadata> {
const params = await props.params;
const data = await getPage(params.slug || ["index"]);
return {
title: `${data.title} – ${DEFAULT_TITLE}`,
Expand Down
13 changes: 10 additions & 3 deletions components/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useContext } from "react";
import { TContent } from "@/lib/types";
import Image from "next/image";
import AspectRatio from "@mui/joy/AspectRatio";
Expand All @@ -7,16 +7,20 @@ import Stack from "@mui/joy/Stack";
import Typography from "@mui/joy/Typography";
import {
Animation,
BACKGROUNDS,
BLACK,
Hero,
MARGINS,
WHITE,
PageContext,
} from "@investigativedata/style";
import { getFileUrl } from "@/lib/directus";
import Card from "./Card";
import File from "./File";
import NewsletterForm from "./NewsletterForm";
import Project from "./Project";

export default function Content(data: TContent): React.ReactNode {
const { currentColor } = useContext(PageContext);
if (data.collection === "heroes") {
let action;
if (!!data.item.mediaSrc) {
Expand Down Expand Up @@ -50,7 +54,7 @@ export default function Content(data: TContent): React.ReactNode {
component="a"
href={data.item.primaryActionHref}
sx={{
color: WHITE,
color: BACKGROUNDS[currentColor],
backgroundColor: BLACK,
"&:hover": {
backgroundColor: BLACK,
Expand Down Expand Up @@ -122,8 +126,11 @@ export default function Content(data: TContent): React.ReactNode {
)}
</Stack>
);
if (data.collection === "files") return <File {...data.item} />;
if (data.collection === "projects") return <Project {...data.item} />;
if (data.collection === "cards") return <Card {...data.item} />;
if (data.collection === "newsletters")
return <NewsletterForm {...data.item} />;
if (data.collection === "animations") {
const { height, width, src, children } = data.item;
const props = { height, width, src: getFileUrl(src) };
Expand Down
16 changes: 16 additions & 0 deletions components/File.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IFileItem } from "@/lib/types";
import Link from "next/link";
import { getFileUrl } from "@/lib/directus";

export default function File({
file,
name,
mimetype,
}: React.PropsWithChildren<IFileItem>) {
const url = getFileUrl(file);
return (
<Link href={url}>
{name} ({mimetype.toUpperCase()})
</Link>
);
}
43 changes: 43 additions & 0 deletions components/NewsletterForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useContext } from "react";
import { INewsletterItem } from "@/lib/types";
import Button from "@mui/joy/Button";
import Input from "@mui/joy/Input";
import Stack from "@mui/joy/Stack";
import { BACKGROUNDS, BLACK, PageContext } from "@investigativedata/style";

export default function NewsletterForm({
action,
listUid,
}: React.PropsWithChildren<INewsletterItem>) {
const { currentColor } = useContext(PageContext);
return (
<form action={action} method="post">
<Stack
spacing={1}
direction="row"
// justifyContent="space-between"
alignSelf="center"
sx={{ w: "100%" }}
>
<Input placeholder="email@example.org" required name="email" />
<input type="hidden" name="l" value={listUid} />
<Button
color="success"
type="submit"
sx={{
color: BACKGROUNDS[currentColor],
backgroundColor: BLACK,
"&:hover": {
backgroundColor: BLACK,
},
"&:active": (theme) => ({
backgroundColor: theme.colorSchemes.dark.palette.text,
}),
}}
>
Subscribe
</Button>
</Stack>
</form>
);
}
13 changes: 11 additions & 2 deletions lib/directus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DIRECTUS_DEFAULT_PAGE_FILTER,
DIRECTUS_URL,
} from "@/config";
import MDX_COMPONENTS from "./markdown";
import MDX_COMPONENTS, { MDX_OPTIONS } from "./markdown";

const directus = createDirectus(DIRECTUS_URL)
.with(rest())
Expand Down Expand Up @@ -40,7 +40,11 @@ function serializeMdx(child: TContent): TContent {
const { collection, item } = cleanProps(child);
if (collection === "mdx" && item.content) {
item.renderedContent = (
<MDXRemote source={item.content} components={MDX_COMPONENTS} />
<MDXRemote
source={item.content}
components={MDX_COMPONENTS}
options={MDX_OPTIONS}
/>
);
}
if (collection === "heroes" && item.teaser) {
Expand All @@ -51,6 +55,7 @@ function serializeMdx(child: TContent): TContent {
...MDX_COMPONENTS,
p: (props: React.PropsWithChildren) => <span>{props.children}</span>,
}}
options={MDX_OPTIONS}
/>
);
}
Expand All @@ -64,6 +69,7 @@ function serializeMdx(child: TContent): TContent {
<Typography level="body-md">{props.children}</Typography>
),
}}
options={MDX_OPTIONS}
/>
);
}
Expand All @@ -77,6 +83,7 @@ function serializeMdx(child: TContent): TContent {
<Typography level="body-sm">{props.children}</Typography>
),
}}
options={MDX_OPTIONS}
/>
);
}
Expand All @@ -90,6 +97,7 @@ function serializeMdx(child: TContent): TContent {
<Typography level="body-md">{props.children}</Typography>
),
}}
options={MDX_OPTIONS}
/>
);
}
Expand All @@ -98,6 +106,7 @@ function serializeMdx(child: TContent): TContent {
<MDXRemote
source={item.content}
components={{ ...MDX_COMPONENTS, p: (props) => <span {...props} /> }}
options={MDX_OPTIONS}
/>
);
}
Expand Down
11 changes: 11 additions & 0 deletions lib/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import remarkGfm from "remark-gfm";
import { MDXComponents } from "mdx/types";
import Image, { ImageProps } from "next/image";
import NLink from "next/link";
import { Table } from "@mui/joy";
import Button, { ButtonProps } from "@mui/joy/Button";
import MLink from "@mui/joy/Link";
import List, { ListProps } from "@mui/joy/List";
Expand Down Expand Up @@ -30,6 +32,9 @@ const MDX_COMPONENTS: MDXComponents = {
// img: (props: { src: string }) => <Image fill={true} {...props} alt="" />,
// @ts-ignore
// a: (props: React.PropsWithChildren<{ href: string }>) => <Link {...props} />,
table: (props: React.PropsWithChildren) => (
<Table {...{ size: "lg", ...props }} />
),
ul: (props: React.PropsWithChildren) => <List {...props} />,
ol: (props: React.PropsWithChildren) => (
<List component="ol" marker="decimal" {...props} />
Expand All @@ -43,3 +48,9 @@ const MDX_COMPONENTS: MDXComponents = {
};

export default MDX_COMPONENTS;

export const MDX_OPTIONS = {
mdxOptions: {
remarkPlugins: [remarkGfm],
},
};
30 changes: 27 additions & 3 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { TypographyProps } from "@mui/joy/Typography";
import { ColorPaletteProp } from "@mui/joy/styles";
import {
IAnimation,
ICard,
IHero,
IMediaScreen as Style_IMediaScreen,
IScreen as Style_IScreen,
TMarginSizes,
} from "@investigativedata/style";
import { ICard } from "@investigativedata/style";

// PAGES

Expand Down Expand Up @@ -54,18 +54,22 @@ export type TCollection =
| "typography"
| "mdx"
| "images"
| "files"
| "cards"
| "projects"
| "animations";
| "animations"
| "newsletters";

export type TContent =
| IHeroContent
| IMdxContent
| IImageContent
| IFileContent
| ITypographyContent
| ICardContent
| IProjectContent
| IAnimationContent;
| IAnimationContent
| INewsletterContent;

interface BaseItem {
readonly id: string;
Expand Down Expand Up @@ -123,6 +127,17 @@ export interface IImageContent {
};
}

export interface IFileItem extends BaseItem {
readonly name: string;
readonly file: string;
readonly mimetype: string;
}

export interface IFileContent {
readonly collection: "files";
readonly item: IFileItem;
}

export interface IProjectItem {
readonly partner: string;
readonly title: string;
Expand Down Expand Up @@ -159,3 +174,12 @@ export interface IAnimationContent {
readonly collection: "animations";
readonly item: BaseItem & IAnimationItem;
}
export interface INewsletterItem {
readonly action: string;
readonly listUid: string;
}

export interface INewsletterContent {
readonly collection: "newsletters";
readonly item: BaseItem & INewsletterItem;
}
7 changes: 1 addition & 6 deletions next.config.js → next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const withMDX = require("@next/mdx")();

/** @type {import('next').NextConfig} */
const nextConfig = {
output: process.env.EXPORT === "1" ? "export" : "standalone",
trailingSlash: true,
transpilePackages: ["next-mdx-remote"], // FIXME: https://github.com/hashicorp/next-mdx-remote/issues/381
// Configure `pageExtensions` to include MDX files
pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
// Optionally, add any other Next.js config below
images: {
loader: "custom",
loaderFile: "./image-loader.ts",
Expand All @@ -23,4 +18,4 @@ const nextConfig = {
},
};

module.exports = withMDX(nextConfig);
export default nextConfig;
Loading
Loading