From cbe0201ca25893667cb079bd8da2e7d95eff4d6a Mon Sep 17 00:00:00 2001 From: Arnaud Gissinger <37625778+mathix420@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:40:57 +0200 Subject: [PATCH] feat(route/rsshub/transform): Add support for link prefixes (#17187) --- lib/routes/rsshub/transform/json.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/routes/rsshub/transform/json.ts b/lib/routes/rsshub/transform/json.ts index ec4ba9601d..782754738e 100644 --- a/lib/routes/rsshub/transform/json.ts +++ b/lib/routes/rsshub/transform/json.ts @@ -39,14 +39,15 @@ export const route: Route = { handler, description: `Specify options (in the format of query string) in parameter \`routeParams\` parameter to extract data from JSON. -| Key | Meaning | Accepted Values | Default | -| ------------- | ---------------------------------------- | --------------- | ------------------------------------------ | -| \`title\` | The title of the RSS | \`string\` | Extracted from home page of current domain | -| \`item\` | The JSON Path as \`item\` element | \`string\` | Entire JSON response | -| \`itemTitle\` | The JSON Path as \`title\` in \`item\` | \`string\` | None | -| \`itemLink\` | The JSON Path as \`link\` in \`item\` | \`string\` | None | -| \`itemDesc\` | The JSON Path as \`description\` in \`item\` | \`string\` | None | -| \`itemPubDate\` | The JSON Path as \`pubDate\` in \`item\` | \`string\` | None | +| Key | Meaning | Accepted Values | Default | +| ------------------ | -------------------------------------------- | ----------------- | ------------------------------------------ | +| \`title\` | The title of the RSS | \`string\` | Extracted from home page of current domain | +| \`item\` | The JSON Path as \`item\` element | \`string\` | Entire JSON response | +| \`itemTitle\` | The JSON Path as \`title\` in \`item\` | \`string\` | None | +| \`itemLink\` | The JSON Path as \`link\` in \`item\` | \`string\` | None | +| \`itemLinkPrefix\` | Optional Prefix for \`itemLink\` value | \`string\` | None | +| \`itemDesc\` | The JSON Path as \`description\` in \`item\` | \`string\` | None | +| \`itemPubDate\` | The JSON Path as \`pubDate\` in \`item\` | \`string\` | None | :::tip JSON Path only supports format like \`a.b.c\`. if you need to access arrays, like \`a[0].b\`, you can write it as \`a.0.b\`. @@ -92,6 +93,11 @@ async function handler(ctx) { const items = jsonGet(response.data, routeParams.get('item')).map((item) => { let link = jsonGet(item, routeParams.get('itemLink')).trim(); + const linkPrefix = routeParams.get('itemLinkPrefix'); + + if (link && linkPrefix) { + link = `${linkPrefix}${link}`; + } // 补全绝对链接 if (link && !link.startsWith('http')) { link = `${new URL(url).origin}${link}`;