Skip to content
Open
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
97 changes: 97 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"congé parental d'éducation, congé parental",
"congédiement, licenciement",
"congés payés, cp",
"congés familial, congés exceptionnel",
"covid, covid 19, coronavirus, corona virus => covid_19",
"chiffre d'affaires, ca => c_a",
"conseil de prud'hommes, cph",
Expand Down
1 change: 0 additions & 1 deletion shared/types/src/elastic/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface ContributionGenericInfos {

export interface ContributionMetadata {
title: string;
text: string;
metas: {
title: string;
description: string;
Expand Down
2 changes: 2 additions & 0 deletions targets/export-elasticsearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"body-parser": "^1.19.2",
"cors": "^2.8.5",
"express": "^4.17.3",
"html-to-text": "^9.0.5",
"inversify": "^6.0.1",
"inversify-express-utils": "^6.4.3",
"mime-types": "^2.1.35",
Expand All @@ -54,6 +55,7 @@
"@types/body-parser": "^1.19.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/html-to-text": "^9.0.4",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.21",
"@types/supertest": "^2.0.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe("generateMetadata", () => {
);

expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("Question");
expect(metadata.metas.description).toBe("Description");
});
Expand All @@ -64,7 +63,6 @@ describe("generateMetadata", () => {
);

expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("Question");
expect(metadata.metas.description).toBe("Description");
});
Expand Down Expand Up @@ -97,7 +95,6 @@ describe("generateMetadata", () => {
);

expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("SEO Title - CC Short title");
expect(metadata.metas.description).toBe("Question - Description");
});
Expand All @@ -121,7 +118,6 @@ describe("generateMetadata", () => {
);

expect(metadata.title).toBe("Question");
expect(metadata.text).toBe("Description");
expect(metadata.metas.title).toBe("Breadcrumb 2 - CC Short title");
expect(metadata.metas.description).toBe("Question - Description");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { getCcSupported } from "./getCcSupported";
import { fetchAgreementUnextended } from "./fetchCcUnextended";
import { getCcInfos } from "./getCcInfos";
import { generateContent } from "./generateContent";
import { getContributionContent } from "./getContributionContent";
import {
getContributionContent,
getContributionText,
} from "./getContributionContent";
import { generateMessageBlock } from "./generateMessageBlock";
import { generateLinkedContent } from "./generateLinkedContent";
import pMap from "p-map";
Expand Down Expand Up @@ -91,15 +94,20 @@ export async function generateContributions(
? contrib.breadcrumbs
: (breadcrumbsOfRootContributionsPerIndex[contrib.questionIndex] ?? []);

const contributionContent = getContributionContent(content);
const text = getContributionText(content, contrib.description);

const contribution: ContributionElasticDocumentLightRelatedContent = {
...contrib,
...doc,
...contributionContent,
...generateMetadata(ccnData, contrib, breadcrumbs),
...getContributionContent(content),
...content,
breadcrumbs,
highlight,
messageBlock,
references,
text,
};

delete contribution.contentWithGlossary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const generateGenericMetadata = (
): ContributionMetadata => {
return {
title: contribution.questionName,
text: contribution.description,
metas: {
title: contribution.questionName,
description: contribution.description,
Expand All @@ -58,7 +57,6 @@ const generateCustomMetadata = (
): ContributionMetadata => {
return {
title: contribution.questionName,
text: contribution.description,
metas: {
title: generateMetaTitle(
contribution.seoTitle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ContributionContent } from "@socialgouv/cdtn-types";
import { convert } from "html-to-text";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est un peu dommage de passer pour une lib juste ici. Je m'en rappelle plus, mais il vaudrait voir comment on fait ailleurs pour extraire le contenu


export function getContributionContent(
content: ContributionContent
Expand All @@ -15,3 +16,22 @@ export function getContributionContent(
};
}
}

export function getContributionText(
content: ContributionContent,
description: string
): string {
if ("content" in content) {
return convert(content.content, {
selectors: [
{ options: { ignoreHref: true }, selector: "a" },
{ format: "skip", selector: "img" },
],
wordwrap: false,
})
.trim()
.replace(/^\s*\n/gm, "\n");
} else {
return description;
}
}
Loading