mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
del: line breaker handling in middleware (#1592)
* del: remove line breaker handling As it's slowing down RSSHub drastically * del: related test case * feat: weibo line breaker handling
This commit is contained in:
@@ -48,17 +48,6 @@ module.exports = async (ctx, next) => {
|
||||
const itunes_duration = Math.floor(item.enclosure_length / 3600) + ':' + Math.floor((item.enclosure_length % 3600) / 60) + ':' + (((item.enclosure_length % 3600) % 60) / 100).toFixed(2).slice(-2);
|
||||
item.itunes_duration = itunes_duration;
|
||||
}
|
||||
|
||||
if (item.description) {
|
||||
item.description = item.description
|
||||
.trim()
|
||||
.replace(/(\r\n|\r|\n)/g, '<br>')
|
||||
.replace(/^(<br>| |<br\/>)+|(<br>| |<br\/>)+$/g, '');
|
||||
}
|
||||
|
||||
if (item.author) {
|
||||
item.author = item.author.trim();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,6 @@ module.exports = async (ctx) => {
|
||||
link: `https://github.com/DIYgod/RSSHub/issues/0`,
|
||||
author: `DIYgod0`,
|
||||
});
|
||||
} else if (ctx.params.id === 'linebreaker') {
|
||||
item.push({
|
||||
title: `Long Title `,
|
||||
description: `<br> <br/> \r\n\r\n Description \n\r with \r\n newlines \r\n\r\n <br/> <br>`,
|
||||
pubDate: new Date(`2018-3-1`).toUTCString(),
|
||||
link: `https://github.com/DIYgod/RSSHub/issues/0`,
|
||||
author: `DIYgod0`,
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 1; i < 6; i++) {
|
||||
|
||||
@@ -35,6 +35,7 @@ module.exports = async (ctx) => {
|
||||
wb.description = titleEle
|
||||
.html()
|
||||
.replace(/^\s+|\s+$/g, '')
|
||||
.replace(/(\r\n|\r|\n)/g, '<br>')
|
||||
.replace(/thumbnail/, 'large');
|
||||
wb.pubDate = date(item.find('.link_d').html(), 8);
|
||||
wb.link = item.find('.wgtCell_tm a').attr('href');
|
||||
|
||||
@@ -66,17 +66,4 @@ describe('template', () => {
|
||||
const parsed = await parser.parseString(response.text);
|
||||
expect(parsed.items[0].title.length).toBe(103);
|
||||
});
|
||||
|
||||
it(`replace newlines with <br>`, async () => {
|
||||
const response = await request.get('/test/linebreaker');
|
||||
const parsed = await parser.parseString(response.text);
|
||||
const test = parsed.items[0].content;
|
||||
|
||||
// line breakers should have been replaced with <br>
|
||||
expect(test).not.toContain('\r');
|
||||
expect(test).not.toContain('\n');
|
||||
|
||||
// content should not start with and/or end with <br>|<br/>, which are meaningless
|
||||
expect(test).toEqual(expect.not.stringMatching(/^(<br>| |<br\/>)+|(<br>| |<br\/>)+$/g));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user