summaryrefslogtreecommitdiff
path: root/src/utility/feed/helper.ts
diff options
context:
space:
mode:
authornetop://ウィビ <paul@webb.page>2026-04-11 14:24:49 -0700
committernetop://ウィビ <paul@webb.page>2026-04-11 14:24:49 -0700
commit8c34d810af95fae0ef846f54370a8c88bfab7123 (patch)
tree436beaf30f7b2b3f15741dd54a37e313964d1f7d /src/utility/feed/helper.ts
initial commitHEADprimary
Diffstat (limited to 'src/utility/feed/helper.ts')
-rw-r--r--src/utility/feed/helper.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/utility/feed/helper.ts b/src/utility/feed/helper.ts
new file mode 100644
index 0000000..0177364
--- /dev/null
+++ b/src/utility/feed/helper.ts
@@ -0,0 +1,67 @@
+
+
+
+/*** EXPORT ------------------------------------------- ***/
+
+export interface FeedOptions {
+ authors: Array<{
+ name: string;
+ email?: string;
+ link?: string;
+ }>;
+ copyright?: string;
+ description: string;
+ feed?: string;
+ feedLinks?: {
+ atom?: string;
+ };
+ generator?: string;
+ icon?: string;
+ id?: string;
+ language?: string;
+ link: string;
+ title: string;
+ updated?: Date;
+}
+
+export function escapeXML(unsafe: string): string {
+ const escapeMap: { [key: string]: string } = {
+ "<": "&lt;",
+ ">": "&gt;",
+ "&": "&amp;",
+ "'": "&apos;",
+ '"': "&quot;"
+ };
+
+ return unsafe.replace(/[<>&'"]/g, (c) => escapeMap[c] || c);
+}
+
+export abstract class BaseFeed<T> {
+ protected categories: Set<string>;
+ protected items: Array<T>;
+ protected options: FeedOptions;
+
+ constructor(options: FeedOptions) {
+ this.categories = new Set();
+ this.items = [];
+
+ this.options = {
+ ...options,
+ updated: options.updated || new Date()
+ };
+ }
+
+ abstract build(): string;
+
+ addCategory(category: string) {
+ this.categories.add(category);
+ }
+
+ addContributor(contributor: { name: string; email: string; link?: string }) {
+ this.options.authors.push(contributor);
+ }
+
+ addItem(item: T) {
+ this.items.push(item);
+ }
+}