Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(feed2): fix output count might be less
- Loading branch information
1 parent
11a4570
commit 4da42b1
Showing
17 changed files
with
160 additions
and
163 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { generateAtomFeed } from "./atom/index.js"; | ||
import { generateJSONFeed } from "./json/index.js"; | ||
import { generateRssFeed } from "./rss/index.js"; | ||
import type { FeedItem } from "../feedItem.js"; | ||
import type { | ||
FeedCategory, | ||
FeedContributor, | ||
FeedInitOptions, | ||
FeedItemInformation, | ||
} from "../typings/index.js"; | ||
|
||
export class FeedStore { | ||
public categories = new Set<string>(); | ||
public contributors: FeedContributor[] = []; | ||
public items: FeedItemInformation[] = []; | ||
|
||
private _contributorKeys = new Set<string>(); | ||
|
||
constructor(public options: FeedInitOptions) {} | ||
|
||
/** | ||
* Add category to store | ||
*/ | ||
private addCategory = (category: FeedCategory): void => { | ||
this.categories.add(category.name); | ||
}; | ||
|
||
/** | ||
* Add contributor to store | ||
*/ | ||
private addContributor = (contributor: FeedContributor): void => { | ||
// use keys to avoid adding same contributor | ||
const key = contributor.email || contributor.name; | ||
|
||
if (key && !this._contributorKeys.has(key)) { | ||
this._contributorKeys.add(key); | ||
this.contributors.push(contributor); | ||
} | ||
}; | ||
|
||
/** | ||
* Add a feed item | ||
*/ | ||
public add = (item: FeedItem): void => { | ||
const info = item.getInfo(); | ||
|
||
if (info) { | ||
const { category, contributor } = info; | ||
|
||
this.items.push(info); | ||
category?.forEach(this.addCategory); | ||
contributor?.forEach(this.addContributor); | ||
} | ||
}; | ||
|
||
/** | ||
* Returns a Atom 1.0 feed | ||
*/ | ||
public atom = (): string => generateAtomFeed(this); | ||
|
||
/** | ||
* Returns a RSS 2.0 feed | ||
*/ | ||
public rss = (): string => generateRssFeed(this); | ||
|
||
/** | ||
* Returns a JSON 1.1 feed | ||
*/ | ||
public json = (): string => generateJSONFeed(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./feed.js"; | ||
export * from "./feedStore.js"; | ||
export * from "./generator.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.