English
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
hostnameRequired
stringThe hostname where the site is deployed, e.g. https://example.com.
atom
booleanWhether to generate an Atom 1.0 feed.
json
booleanWhether to generate a JSON 1.1 feed.
rss
booleanWhether to generate an RSS 2.0 feed.
count
numberDefault
100The maximum number of items in each feed.
image
stringThe image of the feeds, used as a banner.
icon
stringThe icon of the feeds, used as a favicon.
preservedElements
(RegExp | string)[] | (tagName: string) => booleanThe elements to preserve in the feed content. All other unknown tags are removed.
filter
(page: Page) => booleanDefault
({ frontmatter, filePathRelative }) => Boolean(frontmatter.feed ?? (filePathRelative && !frontmatter.home))A function to determine whether a page is included in the feed.
sorter
(pageA: Page, pageB: Page) => numberA function to sort the feed items.
See also: Item Generation.
channel
Partial<FeedChannelOptions>The metadata of the generated feeds.
See also: Channel Options.
getter
FeedGetterThe controller of the feed item generation, a built-in getter is used by default.
See also: Getter Options.
devServer
booleanWhether to generate feeds in the development server.
devHostname
stringDefault
'http://localhost:${port}'The hostname used in the development server.
atomOutputFilename
stringDefault
'atom.xml'The output filename of the Atom feed, relative to the output directory.
atomXslTemplate
stringThe content of the XSL template of the Atom feed, which defaults to the built-in atom.xsl.
atomXslFilename
stringDefault
'atom.xsl'The output filename of the Atom XSL file, relative to the output directory.
jsonOutputFilename
stringDefault
'feed.json'The output filename of the JSON feed, relative to the output directory.
rssOutputFilename
stringDefault
'rss.xml'The output filename of the RSS feed, relative to the output directory.
rssXslTemplate
stringThe content of the XSL template of the RSS feed, which defaults to the built-in rss.xsl.
rssXslFilename
stringDefault
'rss.xsl'The output filename of the RSS XSL file, relative to the output directory.
locales
Record<string, BaseFeedPluginOptions>The configuration for specific locales. Every option above except hostname is supported.
Channel Options
Details
title
stringDefault The title of the locale
The title of the channel.
link
stringDefault The deployment link of the locale
The address of the site the channel stands for.
description
stringDefault The description of the locale
The description of the channel.
language
stringDefault The
lang of the locale The language of the channel.
copyrightrecommended: Yes
stringDefault Copyright by the author name
The copyright notice of the channel.
pubDaterecommended: Yes
DateDefault The time when the plugin is invoked
The publication date of the channel.
lastUpdated
DateDefault The time when the plugin is invoked
The last updated time of the channel content.
ttlrecommended: Yes
numberThe number of minutes a feed reader may cache the content before refreshing it.
imagerecommended: Yes
stringThe image of the channel, a square image of at least 512×512 pixels is recommended.
iconrecommended: Yes
stringThe icon of the channel, a square image of at least 128×128 pixels with a transparent background is recommended.
authorrecommended: Yes
FeedAuthor | FeedAuthor[]The primary author of the channel.
interface FeedAuthor {
name?: string
email?: string
/** Json feed only */
url?: string
/** Json feed only */
avatar?: string
}hub
stringThe URL of the WebSub hub, see WebSub.
Getter Options
Details
title
(page: Page, app: App) => stringGet the title of the feed item.
link
(page: Page, app: App) => stringGet the link of the feed item.
description
(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.
excerpt
(page: Page, app: App) => string | nullGet the excerpt of the feed item.
content
(page: Page, app: App) => stringGet the content of the feed item.
author
(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
}category
(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
}enclosure
(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
}publishDate
(page: Page, app: App) => Date | nullGet the publish date of the feed item.
lastUpdateDate
(page: Page, app: App) => DateGet the last update date of the feed item.
image
(page: Page, app: App) => stringGet the image of the feed item. Return a complete absolute URL.
contributor
(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
}copyright
(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.
title
stringThe title of the page, which falls back to the first h1 header.
description
stringThe description of the page.
date
DateThe publish date of the page, used by the default feed item sorter.
author
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.
copyright
stringThe copyright of the page.
cover
stringThe cover image of the page, which must be a complete URL or an absolute path.
banner
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.
feed
FeedFrontmatterOption | falseWhether to include the page in the feed, or the feed item config of the page.
feed.title
stringThe title used for the feed item.
feed.description
stringThe description used for the feed item, which should be plain text.
feed.summary
stringThe summary used for the feed item, which should be HTML content.
feed.content
stringThe content used for the feed item, which defaults to the page content.
feed.author
FeedAuthor | FeedAuthor[]The authors of the feed item.
interface FeedAuthor {
name?: string
email?: string
/** Json feed only */
url?: string
/** Json feed only */
avatar?: string
}feed.contributor
FeedContributor | FeedContributor[]The contributors of the feed item.
interface FeedContributor {
name?: string
email?: string
/** Json feed only */
url?: string
/** Json feed only */
avatar?: string
}feed.category
FeedCategory | FeedCategory[]The categories of the feed item.
interface FeedCategory {
name: string
/** Rss format only */
domain?: string
/** Atom format only */
scheme?: string
}feed.guid
stringThe globally unique identifier of the feed item, which defaults to its link.
