Another trim attempt
This commit is contained in:
parent
e6b7142829
commit
1b65fe4512
11
index.ts
11
index.ts
@ -4,6 +4,10 @@ import * as xml2js from "xml2js";
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
function trim(str: string, length: number): string {
|
||||
return str.length <= length ? str : str.slice(0, length - 1) + "…";
|
||||
}
|
||||
|
||||
app.use(async (ctx) => {
|
||||
try {
|
||||
const { data } = await Axios.get(
|
||||
@ -25,6 +29,10 @@ app.use(async (ctx) => {
|
||||
/(<([^>]+)>)/gi,
|
||||
""
|
||||
);
|
||||
parsed_data.rss.channel[0]["itunes:subtitle"][0] = trim(
|
||||
parsed_data.rss.channel[0]["itunes:subtitle"][0],
|
||||
255
|
||||
);
|
||||
|
||||
for (let i = 0; i < parsed_data.rss.channel[0]["atom:link"].length; i++) {
|
||||
const atomLink = parsed_data.rss.channel[0]["atom:link"][i];
|
||||
@ -40,8 +48,7 @@ app.use(async (ctx) => {
|
||||
|
||||
item["guid"][0].$.isPermaLink = item["guid"][0].$.isPermalink;
|
||||
delete item["guid"][0].$.isPermalink;
|
||||
const subtitle = item["itunes:subtitle"][0];
|
||||
subtitle.length < 254 ? subtitle : subtitle.slice(0, 254) + "…";
|
||||
item["itunes:subtitle"][0] = trim(item["itunes:subtitle"][0], 255);
|
||||
item["itunes:summary"][0] = item["itunes:summary"][0].replace(
|
||||
/(<([^>]+)>)/gi,
|
||||
""
|
||||
|
Loading…
Reference in New Issue
Block a user