Skip to content

Commit

Permalink
refactor options to object
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed Jul 30, 2024
1 parent 1653ed2 commit 7096aff
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/assets/atom.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</g>
</svg>
</div>
Custom Atom Feed Preview </h1>
Atom Feed Preview </h1>
<h2>
<xsl:value-of select="atom:feed/atom:title" />
</h2>
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async function createBlogFeedFile({
feed,
feedType,
generatePath,
feedOptions: {atomXslt, rssXslt, xslt},
feedOptions: {xslt},
contentPaths,
}: {
feed: Feed;
Expand All @@ -247,11 +247,11 @@ async function createBlogFeedFile({
case 'rss': {
const rssFeed = feed.rss2();
const outputPath = 'rss.xml';
if (xslt) {
if (xslt.enabled) {
const xsltFeed = await transformFeedWithStylesheet({
feedDetails: rssFeed,
generatePath,
xsltFile: rssXslt,
xsltFile: xslt.rssXslt,
contentPaths,
});
return [xsltFeed, outputPath];
Expand All @@ -263,11 +263,11 @@ async function createBlogFeedFile({
case 'atom': {
const atomFeed = feed.atom1();
const outputPath = 'atom.xml';
if (xslt) {
if (xslt.enabled) {
const xsltFeed = await transformFeedWithStylesheet({
feedDetails: atomFeed,
generatePath,
xsltFile: atomXslt,
xsltFile: xslt.atomXslt,
contentPaths,
});
return [xsltFeed, outputPath];
Expand Down
16 changes: 10 additions & 6 deletions packages/docusaurus-plugin-content-blog/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export const DEFAULT_OPTIONS: PluginOptions = {
type: ['rss', 'atom'],
copyright: '',
limit: 20,
xslt: false,
atomXslt: 'atom.xslt',
rssXslt: 'rss.xslt',
xslt: {
enabled: false,
atomXslt: 'atom.xslt',
rssXslt: 'rss.xslt',
},
},
beforeDefaultRehypePlugins: [],
beforeDefaultRemarkPlugins: [],
Expand Down Expand Up @@ -129,9 +131,11 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
)
.allow(null)
.default(DEFAULT_OPTIONS.feedOptions.type),
xslt: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt),
atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.atomXslt),
rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.rssXslt),
xslt: Joi.object({
enabled: Joi.boolean().default(DEFAULT_OPTIONS.feedOptions.xslt.enabled),
atomXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.atomXslt),
rssXslt: Joi.string().default(DEFAULT_OPTIONS.feedOptions.xslt.rssXslt),
}).default(DEFAULT_OPTIONS.feedOptions.xslt),
title: Joi.string().allow(''),
description: Joi.string().allow(''),
// Only add default value when user actually wants a feed (type is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
export type FeedType = 'rss' | 'atom' | 'json';

export type XslParams = {
/** Enable xsl stylesheet */
xslt: boolean;
rssXslt: string;
atomXslt: string;
/** Enable xslt stylesheet */
xslt: {
enabled: boolean;
rssXslt: string;
atomXslt: string;
};
};

/**
Expand Down Expand Up @@ -491,6 +493,11 @@ yarn workspace v1.22.19image` is a collocated image path, this entry will be the
{
/** Type of feed to be generated. Use `null` to disable generation. */
type?: FeedOptions['type'] | 'all' | FeedType;
xslt?: {
enabled?: boolean;
rssXslt?: string;
atomXslt?: string;
};
}
>;
/**
Expand Down
8 changes: 5 additions & 3 deletions website/_dogfooding/dogfooding.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ export const dogfoodingPluginInstances: PluginConfig[] = [
type: 'all',
title: 'Docusaurus Tests Blog',
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
xslt: true,
rssXslt: 'custom-rss.xslt',
atomXslt: 'custom-atom.xslt',
xslt: {
enabled: true,
rssXslt: 'custom-rss.xslt',
atomXslt: 'custom-atom.xslt',
},
},
readingTime: ({content, frontMatter, defaultReadingTime}) =>
frontMatter.hide_reading_time
Expand Down
4 changes: 3 additions & 1 deletion website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ export default async function createConfigAsync() {
feedOptions: {
type: 'all',
copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`,
xslt: true,
xslt: {
enabled: true,
},
},
blogTitle: 'Docusaurus blog',
blogDescription: 'Read blog posts about Docusaurus from the team',
Expand Down

0 comments on commit 7096aff

Please sign in to comment.