feed
Generate feeds for your VuePress site.
Usage
npm i -D @vuepress/plugin-feed@nextimport { feedPlugin } from '@vuepress/plugin-feed'
export default {
plugins: [
feedPlugin({
hostname: 'https://example.com',
atom: true,
}),
],
}The plugin can generate the following formats. Enable the ones you need:
- Atom 1.0:
atom - JSON 1.1:
json - RSS 2.0:
rss
The hostname option is required, as the feed links are generated from it.
Readable Preview
Atom and RSS feeds include XSL templates, so they are rendered as human-readable HTML when opened in a browser. See the Atom and RSS feeds of this site for a live example.
To preview feeds in the development server, set devServer: true, and configure devHostname if your local address differs from the default http://localhost:{port}.
Channel Metadata
The channel option configures the metadata shared by all the generated feeds. It is recommended to set channel.pubDate, channel.ttl, channel.copyright and channel.author.
See also: Channel Options.
Item Generation
By default, every page generated from a Markdown file is included in the feed, except the homepage. You can:
- exclude a single page, or override the fields of its feed item, with the feed frontmatter;
- take full control of the item generation with the getter option.
Items are sorted by the page creation time from git, falling back to the date frontmatter. @vuepress/plugin-git must be enabled to have the creation time, otherwise the items follow the default page order.
I18n
The plugin generates a separate feed for each locale, which can be configured with the locales option.
Options
stringThe hostname where the site is deployed, e.g. https://example.com.
booleanWhether to generate an Atom 1.0 feed.
booleanWhether to generate a JSON 1.1 feed.
booleanWhether to generate an RSS 2.0 feed.
number100The maximum number of items in each feed.
stringThe image of the feeds, used as a banner.
stringThe icon of the feeds, used as a favicon.
(RegExp | string)[] | (tagName: string) => booleanThe elements to preserve in the feed content. All other unknown tags are removed.
(page: Page) => boolean({ frontmatter, filePathRelative }) => Boolean(frontmatter.feed ?? (filePathRelative && !frontmatter.home))A function to determine whether a page is included in the feed.
(pageA: Page, pageB: Page) => numberA function to sort the feed items.
See also: Item Generation.
Partial<FeedChannelOptions>The metadata of the generated feeds.
See also: Channel Options.
FeedGetterThe controller of the feed item generation, a built-in getter is used by default.
See also: Getter Options.
booleanWhether to generate feeds in the development server.
string'http://localhost:${port}'The hostname used in the development server.
string'atom.xml'The output filename of the Atom feed, relative to the output directory.
stringThe content of the XSL template of the Atom feed, which defaults to the built-in atom.xsl.
string'atom.xsl'The output filename of the Atom XSL file, relative to the output directory.
string'feed.json'The output filename of the JSON feed, relative to the output directory.
string'rss.xml'The output filename of the RSS feed, relative to the output directory.
stringThe content of the XSL template of the RSS feed, which defaults to the built-in rss.xsl.
string'rss.xsl'The output filename of the RSS XSL file, relative to the output directory.
Record<string, BaseFeedPluginOptions>The configuration for specific locales. Every option above except hostname is supported.
Channel Options
Details
stringThe title of the channel.
stringThe address of the site the channel stands for.
stringThe description of the channel.
stringlang of the locale The language of the channel.
stringThe copyright notice of the channel.
DateThe publication date of the channel.
DateThe last updated time of the channel content.
numberThe number of minutes a feed reader may cache the content before refreshing it.
stringThe image of the channel, a square image of at least 512×512 pixels is recommended.
stringThe icon of the channel, a square image of at least 128×128 pixels with a transparent background is recommended.
FeedAuthor | FeedAuthor[]The primary author of the channel.
interface FeedAuthor {
name?: string
email?: string
/** json feed only */
url?: string
/** json feed only */
avatar?: string
}stringThe URL of the WebSub hub, see WebSub.
Getter Options
Details
(page: Page, app: App) => stringGet the title of the feed item.
(page: Page, app: App) => stringGet the link of the feed item.
(page: Page, app: App) => string | nullGet the description of the feed item.
Atom supports HTML in the description, return a string prefixed with html: to have it rendered.
(page: Page, app: App) => string | nullGet the excerpt of the feed item.
(page: Page, app: App) => stringGet the content of the feed item.
(page: Page, app: App) => FeedAuthor[]Get the authors of the feed item. Return an empty array when there is no author.
interface FeedAuthor {
name?: string
email?: string
/** json feed only */
url?: string
/** json feed only */
avatar?: string
}(page: Page, app: App) => FeedCategory[] | nullGet the categories of the feed item.
interface FeedCategory {
name: string
/** rss format only */
domain?: string
/** atom format only */
scheme?: string
}(page: Page, app: App) => FeedEnclosure | nullGet the enclosure of the feed item.
interface FeedEnclosure {
url: string
/** should be a standard MIME type, rss format only */
type: string
/** rss format only */
length?: number
}(page: Page, app: App) => Date | nullGet the publish date of the feed item.
(page: Page, app: App) => DateGet the last update date of the feed item.
(page: Page, app: App) => stringGet the image of the feed item. Return a complete absolute URL.
(page: Page, app: App) => FeedContributor[]Get the contributors of the feed item. Return an empty array when there is no contributor.
interface FeedContributor {
name?: string
email?: string
/** json feed only */
url?: string
/** json feed only */
avatar?: string
}(page: Page, app: App) => string | nullGet the copyright of the feed item.
Frontmatter
Inclusion Control
By default, every page generated from a Markdown file is included in the feed, except the homepage. Set feed: false in the frontmatter to exclude a page.
Standard Information
The following standard frontmatter properties are read automatically.
stringThe title of the page, which falls back to the first h1 header.
stringThe description of the page.
DateThe publish date of the page, used by the default feed item sorter.
AuthorInfo | AuthorInfo[] | string | string[]The author of the page. An object author should have a name field, and can have optional url and email fields.
stringThe copyright of the page.
stringThe cover image of the page, which must be a complete URL or an absolute path.
stringThe banner image of the page, which takes priority over cover and is used as the feed item image. When neither is set, the first image of the page content is used.
Feed Options
The feed frontmatter overrides the standard properties or provides fields specific to the feed item.
FeedFrontmatterOption | falseWhether to include the page in the feed, or the feed item config of the page.
stringThe title used for the feed item.
stringThe description used for the feed item, which should be plain text.
stringThe summary used for the feed item, which should be HTML content.
stringThe content used for the feed item, which defaults to the page content.
FeedAuthor | FeedAuthor[]The authors of the feed item.
interface FeedAuthor {
name?: string
email?: string
/** json feed only */
url?: string
/** json feed only */
avatar?: string
}FeedContributor | FeedContributor[]The contributors of the feed item.
interface FeedContributor {
name?: string
email?: string
/** json feed only */
url?: string
/** json feed only */
avatar?: string
}FeedCategory | FeedCategory[]The categories of the feed item.
interface FeedCategory {
name: string
/** rss format only */
domain?: string
/** atom format only */
scheme?: string
}stringThe globally unique identifier of the feed item, which defaults to its link.
