Skip to content

Commit

Permalink
fix: robots.txt - ui headers - typescript error (#1680)
Browse files Browse the repository at this point in the history
* fix: remove duplicate headers (nginx) and log

* fix: robots.txt & ts error
  • Loading branch information
kevbarns authored Nov 29, 2024
1 parent 018c8fa commit 1bbdfba
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 51 deletions.
30 changes: 30 additions & 0 deletions ui/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { MetadataRoute } from "next"

import { publicConfig } from "../config.public"

const getRobotRules = () => {
const { env } = publicConfig
switch (env) {
case "production":
return {
rules: {
userAgent: "*",
disallow: ["/test-widget", "/recherche-apprentissage", "/recherche-apprentissage-formation", "/recherche-emploi"],
},
sitemap: "https://labonnealternance.apprentissage.beta.gouv.fr/sitemap.xml",
}

default:
return {
rules: {
userAgent: "*",
disallow: "/",
},
sitemap: "",
}
}
}

export default function Robots(): MetadataRoute.Robots {
return getRobotRules()
}
18 changes: 16 additions & 2 deletions ui/components/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ExternalLinkIcon } from "@chakra-ui/icons"
import { Box, Container, Divider, Flex, Grid, GridItem, Image, Link, ListItem, UnorderedList } from "@chakra-ui/react"
import NextLink from "next/link"
import { useRouter } from "next/router"
import { useEffect, useState } from "react"

import { publicConfig } from "../config.public"

Expand All @@ -24,7 +26,19 @@ const lastLink = {
paddingLeft: { base: 0, lg: 4 },
}

const Footer = ({ ressources = "" }: { ressources?: string }) => {
const Footer = () => {
const { pathname } = useRouter()
const [ressource, setRessource] = useState<string>()

useEffect(() => {
if (pathname === "/acces-recruteur") {
setRessource("recruter")
}
if (pathname === "/organisme-de-formation") {
setRessource("cfa")
}
}, [])

return (
<Box as="footer" borderTop="1px solid" borderTopColor="info" paddingTop={6} marginTop={12}>
<Container variant={"responsiveContainer"}>
Expand Down Expand Up @@ -116,7 +130,7 @@ const Footer = ({ ressources = "" }: { ressources?: string }) => {
</NextLink>
</ListItem>
<ListItem {...basicLink}>
<NextLink legacyBehavior passHref href={`/ressources${ressources ? "#" + ressources : ""}`}>
<NextLink legacyBehavior passHref href={{ pathname: "/ressources", hash: ressource }}>
<Link aria-label="Accès à la page Ressources">Ressources</Link>
</NextLink>
</ListItem>
Expand Down
20 changes: 0 additions & 20 deletions ui/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,15 @@ const nextConfig = withImages({
hideSourceMaps: false,
widenClientFileUpload: true,
},
async rewrites() {
return [
{
source: "/robots.txt",
destination: "/api/robots",
},
]
},
async headers() {
return [
{
source: "/:path*",
headers: [
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "Content-Security-Policy",
value: inline(contentSecurityPolicy + " frame-ancestors 'none';"),
},
{
key: "Referrer-Policy",
value: "unsafe-url",
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains",
},
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/acces-recruteur.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const AccesRecruteur = () => (
</Container>
<Box mb={3}>&nbsp;</Box>
</Box>
<Footer ressources="recruteur" />
<Footer />
</Box>
)

Expand Down
18 changes: 0 additions & 18 deletions ui/pages/api/robots.ts

This file was deleted.

3 changes: 1 addition & 2 deletions ui/pages/metiers/[forJob].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { find, sortBy } from "lodash"
import NextLink from "next/link"
import { useRouter } from "next/router"
import { NextSeo } from "next-seo"
import React from "react"

import Breadcrumb from "../../components/breadcrumb"
import Footer from "../../components/footer"
Expand Down Expand Up @@ -60,6 +59,7 @@ export default function ForJob(props) {

<Text marginTop="0px" mb={[2, 2, 2, 0]}>
<Text as="span">Emploi en alternance et formation en alternance en </Text>

<NextLink legacyBehavior href={buildLinkForTownAndJob({ name: "France" }, currentJob)} passHref>
<Link
title={`Voir les emplois en alternance et formation en alternance en ${currentJob.name} sur l'ensemble du territoire`}
Expand All @@ -80,7 +80,6 @@ export default function ForJob(props) {
title={`Voir les emplois en alternance et formation en alternance en ${currentJob.name} à ${currentTown.name}`}
textDecoration="underline"
fontWeight={700}
href={buildLinkForTownAndJob(currentTown, currentJob)}
>
{currentJob.name} à {currentTown.name}
</Link>
Expand Down
3 changes: 1 addition & 2 deletions ui/pages/organisme-de-formation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Box, Container, Text } from "@chakra-ui/react"
import { NextSeo } from "next-seo"
import React from "react"

import OffresAutoExposees from "@/components/HomeComponents/OffresAutoExposees"
import PromoRessources from "@/components/Ressources/promoRessources"
Expand Down Expand Up @@ -59,7 +58,7 @@ const Organisme = () => {
</Container>
</Box>

<Footer ressources="cfa" />
<Footer />
</Box>
)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"baseUrl": ".",
"skipLibCheck": true,
"strict": false,
// "strictNullChecks": true,
"strictNullChecks": false,
// "strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
Expand Down
44 changes: 39 additions & 5 deletions ui/utils/buildLinkForTownAndJob.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
export const buildLinkForTownAndJob = (town, job) => {
const result = `/recherche-apprentissage?&display=list&displayMap=false&job_name=${encodeURIComponent(job.name)}&romes=${job.romes.join(",")}${
town.name !== "France" ? `&radius=30&lat=${town.lat}&lon=${town.lon}&zipcode=${town.zip}&insee=${town.insee}&address=${encodeURIComponent(town.name)}` : ""
}`
return result
import { UrlObject } from "url"

interface Town {
name: string
lat?: number
lon?: number
zip?: string
insee?: string
}

interface Job {
name: string
romes: string[]
}

export const buildLinkForTownAndJob = (town: Town, job: Job): UrlObject => {
const pathname = "/recherche-apprentissage"
const query: Record<string, string | boolean | string[]> = {
display: "list",
displayMap: false,
job_name: encodeURIComponent(job.name),
romes: job.romes.join(","),
}

if (town.name !== "France") {
Object.assign(query, {
radius: "30",
lat: town.lat.toString(),
lon: town.lon.toString(),
zipcode: town.zip,
insee: town.insee,
address: encodeURIComponent(town.name),
})
}

return {
pathname,
query,
}
}

0 comments on commit 1bbdfba

Please sign in to comment.