mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-10-03 13:17:07 +00:00
Add feed discovery plugin
This commit is contained in:
parent
e47616bf9d
commit
5cfeea6b57
37 changed files with 2432 additions and 5 deletions
27
plugins/feed-discovery/src/output/opml.ts
Normal file
27
plugins/feed-discovery/src/output/opml.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import type { DiscoveredFeed, FeedDiscoveryResponse } from "../types.js";
|
||||
|
||||
export function renderOpml(response: FeedDiscoveryResponse) {
|
||||
const outlines = response.results.map(renderOutline).join("\n");
|
||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<opml version="2.0">
|
||||
<head>
|
||||
<title>LogicSRC feed discovery: ${escapeXml(response.query)}</title>
|
||||
</head>
|
||||
<body>
|
||||
${outlines}
|
||||
</body>
|
||||
</opml>`;
|
||||
}
|
||||
|
||||
function renderOutline(feed: DiscoveredFeed) {
|
||||
return ` <outline text="${escapeXml(feed.title)}" title="${escapeXml(feed.title)}" type="rss" xmlUrl="${escapeXml(feed.canonicalFeedUrl ?? feed.feedUrl)}"${feed.homepageUrl ? ` htmlUrl="${escapeXml(feed.homepageUrl)}"` : ""} category="${escapeXml(feed.kind)}" />`;
|
||||
}
|
||||
|
||||
export function escapeXml(value: string) {
|
||||
return value
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """)
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue