Skip to content

Commit

Permalink
feat: ameliorer le poid sur les contributions generique (#997)
Browse files Browse the repository at this point in the history
* feat: ameliorer le poid sur les contributions generique

* chore: update TU

---------

Co-authored-by: Victor Zeinstra <[email protected]>
  • Loading branch information
Viczei and Victor Zeinstra authored Aug 25, 2023
1 parent a000814 commit 7a4c014
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { toUrlEntries } from "../pages/api/sitemap";
import { toUrlEntries, Document } from "../pages/api/sitemap";

jest.mock("p-limit", () => () => ({}));

describe("Sitemap", () => {
const documents = [
const documents: Document[] = [
{
__typename: "documents",
modified: "2022-01-03T00:30:44.301258+00:00",
Expand Down Expand Up @@ -46,12 +46,19 @@ describe("Sitemap", () => {
slug: "1634-quelles-sont-les-conditions-dindemnisation-pendant-le-conge-de-maternite",
source: "contributions",
},
{
__typename: "documents",
modified: "2022-01-19T11:07:11.31437+00:00",
slug: "quelles-sont-les-conditions-dindemnisation-pendant-le-conge-de-maternite",
source: "contributions",
},
];
const glossaryTerms = [
const glossaryTerms: Document[] = [
{
__typename: "glossary",
modified: "2020-11-25T14:38:50.085775+00:00",
slug: "abrogation",
source: "glossary",
},
];
it("should generate urlEntry for given documents", async () => {
Expand All @@ -66,6 +73,7 @@ describe("Sitemap", () => {
"<url><loc>base.url/information/indemnite-inflation-infographies</loc><lastmod>2022-01-07T13:09:02.024878+00:00</lastmod><priority>0.7</priority></url>\n",
"<url><loc>base.url/themes/greve</loc><lastmod>2020-11-16T15:46:33.470855+00:00</lastmod><priority>0.5</priority></url>\n",
"<url><loc>base.url/contribution/1634-quelles-sont-les-conditions-dindemnisation-pendant-le-conge-de-maternite</loc><lastmod>2022-01-19T11:07:11.31437+00:00</lastmod><priority>0.5</priority></url>\n",
"<url><loc>base.url/contribution/quelles-sont-les-conditions-dindemnisation-pendant-le-conge-de-maternite</loc><lastmod>2022-01-19T11:07:11.31437+00:00</lastmod><priority>0.7</priority></url>\n",
]);
expect(staticPages.length).toEqual(8);
expect(staticPages[0]).toContain("<url><loc>base.url/a-propos</loc>");
Expand Down
13 changes: 11 additions & 2 deletions targets/frontend/src/pages/api/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import {
import { NextApiRequest, NextApiResponse } from "next";
import pLimit from "p-limit";

type Document = {
export type Document = {
__typename: string;
modified: string;
slug: string;
source: SourceRoute;
};

const slugStartsWithNumber = (slug: string) => {
const [firstElement] = slug.split("-");
return !isNaN(parseInt(firstElement));
};

export async function toUrlEntries(
documents: Document[],
glossaryTerms: Document[],
Expand All @@ -27,7 +32,11 @@ export async function toUrlEntries(
latestPost = postDate;
}
const source = getRouteBySource(doc.source);
const priority = source === SOURCES.EDITORIAL_CONTENT ? 0.7 : 0.5;
const priority =
source === SOURCES.EDITORIAL_CONTENT ||
(source === "contribution" && !slugStartsWithNumber(doc.slug))
? 0.7
: 0.5;
const projectURL = `${baseUrl}/${source}/${doc.slug}`;
return toUrlEntry(projectURL, doc.modified, priority);
});
Expand Down

0 comments on commit 7a4c014

Please sign in to comment.