rsshub
Version:
Make RSS Great Again!
67 lines (65 loc) • 2.21 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs";
import "./parse-date-r5WDWHno.mjs";
import { i as toTitleCase } from "./common-utils-Cz5bFBus.mjs";
//#region lib/routes/smartlink/index.ts
function parseTitle(smartlinkUrl) {
try {
const pathSegments = new URL(smartlinkUrl).pathname.split("/").filter((segment) => segment.length > 0);
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
const dateIndex = pathSegments.findIndex((segment) => dateRegex.test(segment));
return toTitleCase((dateIndex !== -1 && dateIndex < pathSegments.length - 1 ? pathSegments[dateIndex + 1] : pathSegments.at(-1) || "").replaceAll("-", " "));
} catch {
return smartlinkUrl.split("?")[0];
}
}
function isYouTubeUrl(url) {
try {
const hostname = new URL(url).hostname.toLowerCase();
return hostname === "youtube.com" || hostname === "www.youtube.com" || hostname === "m.youtube.com" || hostname === "youtu.be";
} catch {
return false;
}
}
function getTitle(item) {
return isYouTubeUrl(item.smartlink) ? item.smartlink.split("?")[0] : parseTitle(item.smartlink);
}
const route = {
path: "/:site",
categories: ["social-media"],
example: "/smartlink/bloombergpursuits",
parameters: { site: "the site attached to smartlink.bio/" },
radar: [{ source: ["smartlink.bio/"] }],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "Posts",
maintainers: ["nickyfoto"],
handler,
description: "smartlink.bio link in bio takes your audience from Instagram and TikTok to your website in one easy step."
};
async function handler(ctx) {
const site = ctx.req.param("site");
const data = await ofetch_default(`https://smartlink.bio/api/instagram/${site}/posts`);
const items = JSON.parse(data).map((item) => ({
title: getTitle(item),
link: item.smartlink.split("?")[0],
description: `<p><img src="${item.imageUrl}"></p>`,
pubDate: item.created,
guid: item.id
}));
return {
title: `@${site} SmartLink`,
link: `https://smartlink.bio/${site}`,
item: items
};
}
//#endregion
export { route };