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: disable glossary on fiches MT #1497

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
67 changes: 16 additions & 51 deletions targets/ingester/src/transform/fiche-travail-emploi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import slugify from "@socialgouv/cdtn-slugify";
import { SOURCES } from "@socialgouv/cdtn-sources";
import type { FicheTravailEmploi } from "@socialgouv/fiches-travail-data-types";
import got from "got";
import pMap from "p-map";

import { getJson } from "../lib/getJson";
Expand All @@ -11,8 +10,6 @@ import {
} from "../lib/referenceResolver";
import { Code } from "@socialgouv/legi-data-types";

const URL_EXPORT = process.env.URL_EXPORT ?? "http://localhost:8787";

export default async function getFicheTravailEmploi(pkgName: string) {
const [fichesMT, cdt] = await Promise.all([
getJson<FicheTravailEmploi[]>(`${pkgName}/data/fiches-travail.json`),
Expand Down Expand Up @@ -52,57 +49,25 @@ const fetchSections = async (

return await pMap(
sections,
async ({ references, ...section }) => {
let htmlWithGlossary = section.html;
if (section.html && section.html !== "") {
const fetchResult: any = await got
.post(`${URL_EXPORT}/glossary`, {
json: {
type: "html",
content: section.html,
},
responseType: "json",
headers: {
"Content-Type": "application/json",
},
})
.json();

if (!fetchResult?.result) {
console.error(
`Error with glossary for this html :${
section.html
}, we get this result from API : ${JSON.stringify(fetchResult)} `
);
} else {
htmlWithGlossary = fetchResult.result;
async ({ references, ...section }) => ({
...section,
htmlWithGlossary: section.html,
references: Object.keys(references).flatMap((key) => {
if (key !== "LEGITEXT000006072050") {
return [];
}
} else {
console.warn(
`No html found for this section : ${JSON.stringify(section)}`
);
}

return {
...section,
htmlWithGlossary,
references: Object.keys(references).flatMap((key) => {
if (key !== "LEGITEXT000006072050") {
const { articles } = references[key];
return articles.flatMap(({ id }) => {
const maybeArticle = resolveCdtReference(
id
) as LegiData.CodeArticle[];
if (maybeArticle.length !== 1) {
return [];
}
const { articles } = references[key];
return articles.flatMap(({ id }) => {
const maybeArticle = resolveCdtReference(
id
) as LegiData.CodeArticle[];
if (maybeArticle.length !== 1) {
return [];
}
return articleToReference(maybeArticle[0]);
});
}),
};
},
return articleToReference(maybeArticle[0]);
});
}),
}),
{ concurrency: 1 }
);
};
Loading