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

feat: ameliorer le poid sur les contributions generique #997

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
maxgfr marked this conversation as resolved.
Show resolved Hide resolved
const projectURL = `${baseUrl}/${source}/${doc.slug}`;
return toUrlEntry(projectURL, doc.modified, priority);
});
Expand Down
Loading