Skip to content

Commit

Permalink
feat: add image component for mdx content
Browse files Browse the repository at this point in the history
  • Loading branch information
pom421 committed Dec 2, 2024
1 parent a37a997 commit 8f8ca8f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 1 addition & 3 deletions content/blog/part-batiment-ges-en-france.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ Le secteur du bâtiment représente aujourd'hui environ 18 % des émissions de g

Pour atteindre la neutralité carbone d'ici 2050, la France doit drastiquement réduire les émissions de GES provenant des bâtiments, en les faisant passer de 75 millions de tonnes de CO2 (MtCO2) à 30 MtCO2 d'ici 2030.

<div className="mb-8 relative w-full h-[400px]">
<Image src={"/img/blog/aaron-burden-bcn5fhJGtD8-unsplash.jpg"} alt="Image de décoration de l'article" fill className="rounded-lg" />
</div>
<Image src="aaron-burden-bcn5fhJGtD8-unsplash.jpg" />

### L’état actuel des bâtiments en France

Expand Down
22 changes: 22 additions & 0 deletions src/components/mdx/MdxImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Image from "next/image";

type Props = {
alt?: string;
src: string;
};

/**
* Image component for MDX file.
*
* NB: the images must be in the `public/img/blog` folder.
*
* Ex:
* <MdxImage src="aaron-burden-bcn5fhJGtD8-unsplash.jpg" alt="Photo of project X"/>
*/
export const MdxImage = ({ src, alt }: Props) => {
return (
<div className="mb-8 relative w-full h-[400px]">
<Image src={"/img/blog/" + src} alt={alt ?? "Image de décoration de l'article"} fill className="rounded-lg" />
</div>
);
};
6 changes: 3 additions & 3 deletions src/mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type MDXComponents } from "mdx/types";
import Image from "next/image";
import { Fragment } from "react";

import { MdxLink } from "@/components/mdx/Link";
Expand All @@ -9,6 +8,7 @@ import { slugify } from "@/utils/string";
import { CTA } from "./components/CTA";
import { MdxCard } from "./components/mdx/MdxCard";
import { MdxDetails } from "./components/mdx/MdxDetails";
import { MdxImage } from "./components/mdx/MdxImage";
import { MdxSpacer } from "./components/mdx/MdxSpacer";
import { AnchorLink } from "./dsfr/client";

Expand All @@ -31,8 +31,8 @@ export const defaultMdxComponents: MDXComponents = {
Card: MdxCard,
Details: MdxDetails,
Spacer: MdxSpacer,
// eslint-disable-next-line jsx-a11y/alt-text
Image: props => <Image {...props} />,

Image: props => <MdxImage {...props} />,
...anchorHeadingMDXComponents,
};

Expand Down

0 comments on commit 8f8ca8f

Please sign in to comment.