Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d55bef4
feat: updated getSubstackFeedByLink method signature
rohit1901 Feb 7, 2025
bb21787
1.0.3
actions-user Feb 7, 2025
718f8bc
Merge branch 'main' into release/patch
rohit1901 Feb 7, 2025
d119c6e
fix: updated declaration file
rohit1901 Feb 7, 2025
1f51f48
Merge remote-tracking branch 'origin/release/patch' into release/patch
rohit1901 Feb 7, 2025
47fa5bf
1.0.4
actions-user Feb 7, 2025
4205e84
Merge branch 'main' into release/patch
rohit1901 Feb 7, 2025
79d2603
fix: updated declaration
rohit1901 Feb 7, 2025
1b8456b
1.0.5
actions-user Feb 7, 2025
11f249e
fix: updated parsing for non browser calls
rohit1901 Feb 7, 2025
d48a505
1.0.6
actions-user Feb 7, 2025
7753983
fix: updated parsing for non browser calls
rohit1901 Feb 7, 2025
d89d90a
Merge remote-tracking branch 'origin/release/patch' into release/patch
rohit1901 Feb 7, 2025
0d872ee
1.0.7
actions-user Feb 7, 2025
648e8cd
fix: determine client or server call
rohit1901 Feb 7, 2025
7211c50
1.0.8
actions-user Feb 7, 2025
4f8adfa
Merge branch 'main' into release/patch
rohit1901 Feb 8, 2025
1f06c49
chore: fixed error in package.json
rohit1901 Feb 8, 2025
e9e18af
1.0.9
actions-user Feb 8, 2025
a6dc94c
Merge branch 'main' into release/patch
rohit1901 Feb 8, 2025
bed6549
chore: fixed build issues
rohit1901 Feb 8, 2025
00c062b
1.0.10
actions-user Feb 8, 2025
b92c550
fix: fixed issues with client and server fetching
rohit1901 Feb 8, 2025
95fa7b1
1.0.11
actions-user Feb 8, 2025
f2dffec
chore: removed .tgz
rohit1901 Feb 8, 2025
7154471
1.0.12
actions-user Feb 8, 2025
0532d51
Merge branch 'main' into release/patch
rohit1901 Feb 8, 2025
7fa92be
Pre-version bump changes
actions-user Feb 8, 2025
f6f262b
1.0.13
actions-user Feb 8, 2025
3c4ace1
Merge branch 'main' into release/patch
rohit1901 Feb 8, 2025
c20c39a
chore: cleanup
rohit1901 Feb 8, 2025
f2cb2be
Merge branch 'feature/cleanup' into release/patch
rohit1901 Feb 8, 2025
b6644a3
1.0.14
actions-user Feb 8, 2025
a45a74c
Merge branch 'main' into release/patch
rohit1901 Feb 11, 2025
b52b327
chore: updated types
rohit1901 Feb 11, 2025
ce377dd
1.1.1
actions-user Feb 11, 2025
4849812
Merge branch 'main' into release/patch
rohit1901 Feb 11, 2025
0a14fb3
chore: added property to goodreads feed
rohit1901 Feb 11, 2025
d9e951c
1.1.2
actions-user Feb 11, 2025
2a41a94
fix: updated proxy
rohit1901 May 19, 2025
0d9e922
1.1.3
actions-user May 19, 2025
ddf52bf
Merge remote-tracking branch 'origin/main' into release/patch
rohit1901 May 19, 2025
241aad1
1.1.3
actions-user May 19, 2025
8479552
feat: udpated proxy
rohit1901 May 19, 2025
d21cd5a
Merge branch 'release/patch' of https://github.com/rohit1901/substack…
rohit1901 May 19, 2025
e1328c7
1.1.4
actions-user May 19, 2025
c8121ec
Merge branch 'main' into release/patch
rohit1901 Jan 30, 2026
60c1fe6
fix: Refactor to generic RSS parser with Cheerio
rohit1901 Jan 30, 2026
296a565
chore: bump version to v2.0.1
github-actions[bot] Jan 30, 2026
26bf27e
fix: Extract parseRssItems into its own file
rohit1901 Jan 30, 2026
c848d44
chore: bump version to v2.0.2
github-actions[bot] Jan 30, 2026
b583855
Merge branch 'main' into release/patch
rohit1901 Jan 30, 2026
f6d7add
chore: bump version to v2.0.3
github-actions[bot] Jan 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 3 additions & 53 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
import { load } from "cheerio";

// Generic selector map keyed by the raw record keys
export type SelectorMap<TRaw extends Record<string, string>> = Partial<
Record<keyof TRaw, string>
>;

export type ParseRssOptions<TRaw extends Record<string, string>> = {
itemSelector?: string;
selectors?: SelectorMap<TRaw>;
fallback?: TRaw[];
};

/**
* Generic RSS → array of flat string records.
*/
export function parseRssItems<TRaw extends Record<string, string>>(
xml: string,
{
itemSelector = "channel > item",
selectors = {} as SelectorMap<TRaw>,
fallback = [],
}: ParseRssOptions<TRaw> = {},
): TRaw[] {
try {
const $ = load(xml, { xmlMode: true });

const items: TRaw[] = [];

$(itemSelector).each((_, el) => {
const result: Record<string, string> = {};

(Object.keys(selectors) as (keyof TRaw)[]).forEach((key) => {
const selector = selectors[key];
if (!selector) return;

result[key as string] = $(el).find(selector).first().text().trim();
});

items.push(result as TRaw);
});

return items;
} catch (error) {
console.error("[parseRssItems] Failed to parse RSS feed", {
error,
itemSelector,
selectors,
});

return fallback;
}
}
export * from "./parseRssItems";
export * from "./goodreads";
export * from "./substack";
53 changes: 53 additions & 0 deletions lib/parseRssItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { load } from "cheerio";

// Generic selector map keyed by the raw record keys
export type SelectorMap<TRaw extends Record<string, string>> = Partial<
Record<keyof TRaw, string>
>;

export type ParseRssOptions<TRaw extends Record<string, string>> = {
itemSelector?: string;
selectors?: SelectorMap<TRaw>;
fallback?: TRaw[];
};

/**
* Generic RSS → array of flat string records.
*/
export function parseRssItems<TRaw extends Record<string, string>>(
xml: string,
{
itemSelector = "channel > item",
selectors = {} as SelectorMap<TRaw>,
fallback = [],
}: ParseRssOptions<TRaw> = {},
): TRaw[] {
try {
const $ = load(xml, { xmlMode: true });

const items: TRaw[] = [];

$(itemSelector).each((_, el) => {
const result: Record<string, string> = {};

(Object.keys(selectors) as (keyof TRaw)[]).forEach((key) => {
const selector = selectors[key];
if (!selector) return;

result[key as string] = $(el).find(selector).first().text().trim();
});

items.push(result as TRaw);
});

return items;
} catch (error) {
console.error("[parseRssItems] Failed to parse RSS feed", {
error,
itemSelector,
selectors,
});

return fallback;
}
}
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "substack-feed-api",
"version": "2.0.1",
"version": "2.0.3",
"type": "module",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineConfig(({ mode }) => {
},
build: {
lib: {
entry: ["./lib/index.ts", "./lib/goodreads.ts", "./lib/substack.ts"],
entry: "./lib/index.ts",
name: "SubstackFeedAPI",
fileName: "substackFeedApi",
},
Expand Down
Loading