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();
|
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) => {
|
app.use(async (ctx) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await Axios.get(
|
const { data } = await Axios.get(
|
||||||
|
@ -25,6 +29,10 @@ app.use(async (ctx) => {
|
||||||
/(<([^>]+)>)/gi,
|
/(<([^>]+)>)/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++) {
|
for (let i = 0; i < parsed_data.rss.channel[0]["atom:link"].length; i++) {
|
||||||
const atomLink = parsed_data.rss.channel[0]["atom:link"][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;
|
item["guid"][0].$.isPermaLink = item["guid"][0].$.isPermalink;
|
||||||
delete item["guid"][0].$.isPermalink;
|
delete item["guid"][0].$.isPermalink;
|
||||||
const subtitle = item["itunes:subtitle"][0];
|
item["itunes:subtitle"][0] = trim(item["itunes:subtitle"][0], 255);
|
||||||
subtitle.length < 254 ? subtitle : subtitle.slice(0, 254) + "…";
|
|
||||||
item["itunes:summary"][0] = item["itunes:summary"][0].replace(
|
item["itunes:summary"][0] = item["itunes:summary"][0].replace(
|
||||||
/(<([^>]+)>)/gi,
|
/(<([^>]+)>)/gi,
|
||||||
""
|
""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user