Skip to content

Commit

Permalink
Merge pull request #385 from NDLANO/remove-not-found-concepts-from-ar…
Browse files Browse the repository at this point in the history
…ticle

Remove 404 concepts from article
  • Loading branch information
Jonas-C authored Nov 13, 2023
2 parents 6ba65b2 + bda7b0e commit 1d6df15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/api/embedsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
EmbedData,
ConceptVisualElementMeta,
CampaignBlockMetaData,
ConceptData,
} from '@ndla/types-embed';
import { IImageMetaInformationV3 } from '@ndla/types-backend/image-api';
import { load } from 'cheerio';
Expand Down Expand Up @@ -165,6 +166,7 @@ export interface TransformOptions {
absoluteUrl?: boolean;
subject?: string;
shortCircuitOnError?: boolean;
standalone?: boolean;
}

const footnoteMeta: Fetch<
Expand Down Expand Up @@ -434,7 +436,18 @@ export const transformEmbed = async (
} else if (embedData.resource === 'related-content') {
meta = await relatedContentMeta({ embedData, context, index, opts });
} else if (embedData.resource === 'concept') {
meta = await conceptMeta({ embedData, context, index, opts });
const response: ConceptData | undefined = await conceptMeta({
embedData,
context,
index,
opts,
}).catch(_ => undefined);
// If the concept does not exist and we are not requesting a standalone concept, remove it from the article.
if (!opts.standalone && !response) {
embed.embed.replaceWith('');
return;
}
meta = response;
embedData.pageUrl = `/${embedData.resource}/${embedData.contentId}`;
} else if (embedData.resource === 'concept-list') {
meta = await conceptListMeta({ embedData, context, index, opts });
Expand Down
2 changes: 2 additions & 0 deletions src/api/resourceEmbedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const fetchResourceEmbed = async (
const embeds = getEmbedsFromContent(html)[0];
const embedPromise = await transformEmbed(embeds, context, 0, 0, {
shortCircuitOnError: true,
standalone: true,
});

const metadata = toArticleMetaData([embedPromise]);
Expand Down Expand Up @@ -143,6 +144,7 @@ export const fetchResourceEmbeds = async (
embedsFromContent.map((embed, index) =>
transformEmbed(embed, context, index, 0, {
shortCircuitOnError: true,
standalone: true,
}),
),
);
Expand Down

0 comments on commit 1d6df15

Please sign in to comment.