Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from SocialGouv/maxgfr/oklmzer
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr authored Mar 21, 2022
2 parents 087c108 + e3dc26e commit cfc05c5
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 50 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"extends": ["next/core-web-vitals", "plugin:storybook/recommended"]
"extends": [
"next/core-web-vitals",
"plugin:storybook/recommended",
"plugin:jsx-a11y/recommended"
]
}
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
git add -A
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,3 @@ yarn
yarn build
yarn export
```

## Todo

- Ajouter des CSP
- Husky pour avant de commit faire des verifications
- Finir la documentation, en mode si vous créez un fichier faut le mettre là, etc.
- Rajouter une config sur <https://github.com/SocialGouv/linters> un linter pour next 12 et accessibilité plugin
13 changes: 13 additions & 0 deletions csp.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const ContentSecurityPolicy = `
default-src 'self' *.fabrique.social.gouv.fr;
img-src 'self' data: *.fabrique.social.gouv.fr https://dummyimage.com/;
script-src 'self' *.fabrique.social.gouv.fr ${
process.env.NODE_ENV !== "production" && "'unsafe-eval'"
};
frame-src 'self' *.fabrique.social.gouv.fr;
style-src 'self' 'unsafe-inline';
font-src 'self' data: blob:;
prefetch-src 'self' *.fabrique.social.gouv.fr;
`;

module.exports = ContentSecurityPolicy;
11 changes: 11 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require("path");

const buildEslintCommand = filenames =>
`next lint --fix --file ${filenames
.map(f => path.relative(process.cwd(), f))
.join(" --file ")}`;

module.exports = {
"**/*.ts?(x)": () => "tsc -p tsconfig.json --noEmit",
"*.{js,ts,tsx,jsx}": ["jest --bail --findRelatedTests", buildEslintCommand],
};
18 changes: 18 additions & 0 deletions next-seo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ContentSecurityPolicy from "./csp.config";

const DEFAULT_SEO_CONFIG = {
additionalLinkTags: [
{
rel: "icon",
href: "/favicon.ico",
},
],
additionalMetaTags: [
{
httpEquiv: "Content-Security-Policy",
content: ContentSecurityPolicy.replace(/\n/g, " ").trim(),
},
],
};

export default DEFAULT_SEO_CONFIG;
25 changes: 24 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { withSentryConfig } = require("@sentry/nextjs");

const { version } = require("./package.json");

const ContentSecurityPolicy = require("./csp.config");

/** @type {import('next').NextConfig} */
const moduleExports = {
reactStrictMode: true,
Expand All @@ -16,4 +18,25 @@ const moduleExports = {
},
};

module.exports = withSentryConfig(moduleExports, { silent: true });
module.exports = {
async headers() {
return [
{
source: "/:path*",
headers: [
{
key: "Content-Security-Policy",
value: ContentSecurityPolicy.replace(/\n/g, " ").trim(),
},
{
key: "X-Robots-Tag",
value: process.env.NEXT_PUBLIC_IS_PRODUCTION_DEPLOYMENT
? "all"
: "noindex, nofollow, nosnippet",
},
],
},
];
},
...withSentryConfig(moduleExports, { silent: true }),
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"prepare": "husky install",
"lint-staged": "lint-staged",
"export": "next export",
"build:export": "npm run build && npm run export",
"e2e": "cypress open",
Expand Down Expand Up @@ -49,9 +51,12 @@
"cypress": "^9.4.1",
"eslint": "8.10.0",
"eslint-config-next": "12.1.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-storybook": "^0.5.7",
"gh-pages": "^3.2.3",
"husky": "^7.0.4",
"jest": "^27.5.1",
"lint-staged": "^12.3.7",
"start-server-and-test": "^1.14.0",
"typescript": "4.6.2"
}
Expand Down
90 changes: 57 additions & 33 deletions src/components/footer/bottom.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
import { FooterBottom, FooterCopy, FooterLink } from "@dataesr/react-dsfr";
import {
FooterBottom,
FooterCopy,
FooterLink,
SwitchTheme,
} from "@dataesr/react-dsfr";
import { useState } from "react";
import { FooterBottomSectionProps } from "./type";

export const Bottom = (props: FooterBottomSectionProps): JSX.Element => (
<FooterBottom>
{props.links.map((link, index) => (
<FooterLink key={`${index}-${link.title}`} href={link.href}>
{link.title}
</FooterLink>
))}
<FooterCopy>
<p>
Sauf mention contraire, tous les contenus de ce site sont sous{" "}
<a
href="https://github.com/etalab/licence-ouverte/blob/master/LO.md"
rel="noreferrer"
target="_blank"
>
licence etalab-2.0
</a>
</p>
<p>
Version {props.version} (
<a
target="_blank"
href={`${props.repositoryUrl}/tree/${props.commitHash}`}
rel="noreferrer"
>
{props.commitHash.substring(0, 8)}
</a>
)
</p>
</FooterCopy>
</FooterBottom>
);
export const Bottom = (props: FooterBottomSectionProps): JSX.Element => {
const [isOpen, setIsOpen] = useState(false);

return (
<FooterBottom>
{props.links.map((link, index) => (
<FooterLink key={`${index}-${link.title}`} href={link.href}>
{link.title}
</FooterLink>
))}
{props.hasSwitchMode && (
<FooterLink onClick={() => setIsOpen(true)} href="/">
<span
className="fr-fi-theme-fill fr-link--icon-left"
aria-controls="fr-theme-modal"
data-fr-opened={isOpen}
>
Paramètres d’affichage
</span>
</FooterLink>
)}
<FooterCopy>
<p>
Sauf mention contraire, tous les contenus de ce site sont sous{" "}
<a
href="https://github.com/etalab/licence-ouverte/blob/master/LO.md"
rel="noreferrer"
target="_blank"
>
licence etalab-2.0
</a>
</p>
<p>
Version {props.version} (
<a
target="_blank"
href={`${props.repositoryUrl}/tree/${props.commitHash}`}
rel="noreferrer"
>
{props.commitHash.substring(0, 8)}
</a>
)
</p>
</FooterCopy>
{props.hasSwitchMode && (
<SwitchTheme isOpen={isOpen} setIsOpen={setIsOpen} />
)}
</FooterBottom>
);
};
1 change: 1 addition & 0 deletions src/components/footer/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type FooterBottomSectionProps = {
version: string;
repositoryUrl: string;
commitHash: string;
hasSwitchMode: boolean;
};

export type FooterTopSectionProps = {
Expand Down
22 changes: 22 additions & 0 deletions src/components/landing/head.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { Head } from "./head";

export default {
title: "Header",
component: Head,
} as ComponentMeta<typeof Head>;

const Template: ComponentStory<typeof Head> = args => <Head {...args} />;

export const Default = Template.bind({});
Default.args = {
title: "Random title",
textLead: "Random text lead",
description: "Random description",
image: {
src: "https://via.placeholder.com/600x400",
alt: "Random image",
},
};
25 changes: 25 additions & 0 deletions src/components/landing/testimonial.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { Testimonial } from "./testimonial";

export default {
title: "Testimonial",
component: Testimonial,
} as ComponentMeta<typeof Testimonial>;

const Template: ComponentStory<typeof Testimonial> = args => (
<Testimonial {...args} />
);

export const Default = Template.bind({});
Default.args = {
description: "Random description",
image: {
src: "https://via.placeholder.com/600x400",
alt: "Random image",
},
link: {
href: "https://www.google.com",
title: "Random link",
},
};
21 changes: 21 additions & 0 deletions src/components/landing/tile.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import { ComponentStory, ComponentMeta } from "@storybook/react";
import { Tile } from "./tile";

export default {
title: "Tile",
component: Tile,
} as ComponentMeta<typeof Tile>;

const Template: ComponentStory<typeof Tile> = args => <Tile {...args} />;

export const Default = Template.bind({});
Default.args = {
title: "Random title",
description: "Random description",
image: {
src: "https://via.placeholder.com/600x400",
alt: "Random image",
},
href: "https://www.fabrique.social.gouv.fr/",
};
6 changes: 4 additions & 2 deletions src/components/landing/tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export const Tile = (props: TileProps): JSX.Element => {
<div className="fr-card fr-enlarge-link fr-pt-3w">
<div className="fr-card__body">
<h2 className="fr-card__title">
<Link href={props.href} passHref>
<a className="fr-card__link">{props.title}</a>
<Link href={props.href}>
<a className="fr-card__link" href={props.href}>
{props.title}
</a>
</Link>
</h2>
<p className="fr-card__desc">{props.description}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Template: ComponentStory<typeof StatsTile> = args => (
export const Default = Template.bind({});
Default.args = {
title: "Nombre de visites",
stats: "1.000.000"
stats: "1.000.000",
};

export const WithDescription = Template.bind({});
Expand Down
1 change: 1 addition & 0 deletions src/config/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const footerPartnerSection: FooterPartnerSectionProps = {
};

export const footerBottomSection: FooterBottomSectionProps = {
hasSwitchMode: true,
links: [
{
title: "Accessibilité : non conforme",
Expand Down
3 changes: 3 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "@gouvfr/dsfr/dist/dsfr/dsfr.min.css";
import type { AppProps } from "next/app";
import SEO from "../../next-seo.config";
import { Layout } from "@components";
import {
footerBodySection,
Expand All @@ -10,6 +11,7 @@ import {
} from "@config";
import { useEffect } from "react";
import { init } from "@socialgouv/matomo-next";
import { DefaultSeo } from "next-seo";

function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => {
Expand All @@ -29,6 +31,7 @@ function MyApp({ Component, pageProps }: AppProps) {
topSection: footerTopSection,
}}
>
<DefaultSeo {...(SEO as any)} />
<Component {...pageProps} />
</Layout>
);
Expand Down
14 changes: 14 additions & 0 deletions src/pages/cgu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ const Cgu: NextPage = () => {
href: "/favicon.ico",
},
]}
additionalMetaTags={[
{
property: "dc:creator",
content: "Jane Doe",
},
{
name: "application-name",
content: "NextSeo",
},
{
httpEquiv: "x-ua-compatible",
content: "IE=edge; chrome=1",
},
]}
/>
<div className="fr-container fr-my-6w">
<h1>Conditions générales d&apos;utilisation</h1>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@lib": ["./src/lib"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "jest-setup.ts"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": [
"node_modules",
"next-sitemap.js",
Expand Down
Loading

0 comments on commit cfc05c5

Please sign in to comment.