Skip to content

Commit

Permalink
feat(route): fix images not displaying in msn news full text
Browse files Browse the repository at this point in the history
  • Loading branch information
KTachibanaM committed Jan 1, 2025
1 parent 0ad07d2 commit 9fafbd2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/routes/msn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cache from '@/utils/cache';
import { load } from 'cheerio';

const apiKey = '0QfOX3Vn51YCzitbLaRkTTBadtWpgTN8NZLW0C1SEM';
const fetchedArticleContentHtmlImgRegex = /<img data-reference="image" data-document-id="cms\/api\/amp\/image\/([A-Za-z0-9]+)">/;

export const route: Route = {
path: '/:market/:name/:id',
Expand Down Expand Up @@ -54,10 +55,11 @@ export const route: Route = {
let articleId = parsedArticleUrl?.pathname.split('/').pop();
if (articleId?.startsWith('ar-')) {
articleId = articleId.substring(3);
const fetchedArticleContentHtml = (await cache.tryGet(articleId, async () => {
let fetchedArticleContentHtml = (await cache.tryGet(articleId, async () => {
const articleData = await ofetch(`https://assets.msn.com/content/view/v2/Detail/${market}/${articleId}`);
return articleData.body;
})) as string; // cache article content for 3 months
})) as string;
fetchedArticleContentHtml = fetchedArticleContentHtml.replace(fetchedArticleContentHtmlImgRegex, '<img src="https://img-s-msn-com.akamaized.net/tenant/amp/entityid/$1.img">');
articleContentHtml = fetchedArticleContentHtml;
}

Expand Down

0 comments on commit 9fafbd2

Please sign in to comment.