Skip to content

Commit

Permalink
fix(route/udn): Remove control character to prevent JSON parser error. (
Browse files Browse the repository at this point in the history
  • Loading branch information
dzx-dzx authored Oct 7, 2023
1 parent cbea1f9 commit 8ce05e0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/v2/udn/breaking-news.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ module.exports = async (ctx) => {
}

const $ = cheerio.load(result.data);
const metadata = $('script[type="application/ld+json"]').eq(0).text().trim().replaceAll(/[\b]/g, '');
const metadata = $('script[type="application/ld+json"]')
.eq(0)
.text()
.trim()
.replaceAll(/[\b\n\t]/g, '');
const data = metadata.startsWith('[') ? JSON.parse(metadata)[0] : JSON.parse(metadata);
// e.g. https://udn.com/news/story/7331/6576320
const content = $('.article-content__editor');
Expand Down

0 comments on commit 8ce05e0

Please sign in to comment.