fix(route/landiannews): sanitize rendered titles (#21461)

* fix(route/landiannews): sanitize rendered titles

* refactor(route/landiannews): use sanitize-html for titles
This commit is contained in:
LinxHex 2026-03-24 21:39:50 +08:00 committed by GitHub
parent f0af555774
commit 697c3d6edb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -1,8 +1,15 @@
import sanitizeHtml from 'sanitize-html';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
const rootUrl = 'https://www.landiannews.com/';
const getRenderedText = (html: string) => sanitizeHtml(html, { allowedTags: [], allowedAttributes: {} });
const getPubDate = (dateGmt?: string, date?: string) => (dateGmt ? parseDate(`${dateGmt}Z`) : date ? parseDate(date) : undefined);
const fetchTaxonomy = async (slug: string, type: 'categories' | 'tags') => {
const taxonomyUrl = `${rootUrl}wp-json/wp/v2/${type}?slug=${slug}`;
const cachedTaxonomy = await cache.tryGet(taxonomyUrl, async () => {
@ -22,10 +29,10 @@ async function fetchNewsItems(apiUrl: string) {
const data = await ofetch(apiUrl);
return data.map((item) => ({
title: item.title.rendered,
title: getRenderedText(item.title.rendered),
description: item.content.rendered,
link: item.link,
pubDate: new Date(item.date).toUTCString(),
pubDate: getPubDate(item.date_gmt, item.date),
author: item._embedded.author[0].name,
category: item._embedded['wp:term'].flat().map((term) => term.name),
}));