Skip to content

Commit

Permalink
feat: disable glossary on fiches MT (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-maillot authored Oct 31, 2024
1 parent 964ffd3 commit 1db4113
Showing 1 changed file with 16 additions and 51 deletions.
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 }
);
};

0 comments on commit 1db4113

Please sign in to comment.