stricter data handling
This commit is contained in:
parent
31a62d2a7d
commit
07e4adcca5
|
|
@ -30,25 +30,31 @@ module.exports = async (ctx, next) => {
|
|||
template = path.resolve(__dirname, '../views/rss.art');
|
||||
break;
|
||||
}
|
||||
// trim title length
|
||||
ctx.state.data.item &&
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
for (let length = 0, i = 0; i < item.title.length; i++) {
|
||||
length += Buffer.from(item.title[i]).length !== 1 ? 2 : 1;
|
||||
if (length > config.titleLengthLimit) {
|
||||
item.title = `${item.title.slice(0, i)}...`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ctx.state.data.title && (ctx.state.data.title = he.decode(ctx.state.data.title));
|
||||
ctx.state.data.description && (ctx.state.data.description = he.decode(ctx.state.data.description));
|
||||
ctx.state.data.item &&
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
item.title && (item.title = he.decode(item.title));
|
||||
item.description && (item.description = he.decode(item.description));
|
||||
});
|
||||
if (ctx.state.data) {
|
||||
// trim title length
|
||||
ctx.state.data.item &&
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
if (item.title) {
|
||||
for (let length = 0, i = 0; i < item.title.length; i++) {
|
||||
length += Buffer.from(item.title[i]).length !== 1 ? 2 : 1;
|
||||
if (length > config.titleLengthLimit) {
|
||||
item.title = `${item.title.slice(0, i)}...`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// decode HTML entities
|
||||
ctx.state.data.title && (ctx.state.data.title = he.decode(ctx.state.data.title));
|
||||
ctx.state.data.description && (ctx.state.data.description = he.decode(ctx.state.data.description));
|
||||
ctx.state.data.item &&
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
item.title && (item.title = he.decode(item.title));
|
||||
item.description && (item.description = he.decode(item.description));
|
||||
});
|
||||
}
|
||||
|
||||
const data = {
|
||||
lastBuildDate: new Date().toUTCString(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue