Skip to content

Commit

Permalink
Add s/plural to option name for consistency: onUntruncatedBlogPosts
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 9, 2024
1 parent 56b71c0 commit 3da8f60
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,43 +375,44 @@ describe('validateOptions', () => {
});
});

describe('onUntruncatedBlogPost', () => {
it('accepts onUntruncatedBlogPost - undefined', () => {
describe('onUntruncatedBlogPosts', () => {
it('accepts onUntruncatedBlogPosts - undefined', () => {
expect(
testValidate({onUntruncatedBlogPost: undefined}).onUntruncatedBlogPost,
testValidate({onUntruncatedBlogPosts: undefined})
.onUntruncatedBlogPosts,
).toBe('warn');
});

it('accepts onUntruncatedBlogPost - "throw"', () => {
it('accepts onUntruncatedBlogPosts - "throw"', () => {
expect(
testValidate({onUntruncatedBlogPost: 'throw'}).onUntruncatedBlogPost,
testValidate({onUntruncatedBlogPosts: 'throw'}).onUntruncatedBlogPosts,
).toBe('throw');
});

it('rejects onUntruncatedBlogPost - "trace"', () => {
it('rejects onUntruncatedBlogPosts - "trace"', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onUntruncatedBlogPost: 'trace'}),
testValidate({onUntruncatedBlogPosts: 'trace'}),
).toThrowErrorMatchingInlineSnapshot(
`""onUntruncatedBlogPost" must be one of [ignore, log, warn, throw]"`,
`""onUntruncatedBlogPosts" must be one of [ignore, log, warn, throw]"`,
);
});

it('rejects onUntruncatedBlogPost - null', () => {
it('rejects onUntruncatedBlogPosts - null', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onUntruncatedBlogPost: 42}),
testValidate({onUntruncatedBlogPosts: 42}),
).toThrowErrorMatchingInlineSnapshot(
`""onUntruncatedBlogPost" must be one of [ignore, log, warn, throw]"`,
`""onUntruncatedBlogPosts" must be one of [ignore, log, warn, throw]"`,
);
});

it('rejects onUntruncatedBlogPost - 42', () => {
it('rejects onUntruncatedBlogPosts - 42', () => {
expect(() =>
// @ts-expect-error: test
testValidate({onUntruncatedBlogPost: 42}),
testValidate({onUntruncatedBlogPosts: 42}),
).toThrowErrorMatchingInlineSnapshot(
`""onUntruncatedBlogPost" must be one of [ignore, log, warn, throw]"`,
`""onUntruncatedBlogPosts" must be one of [ignore, log, warn, throw]"`,
);
});
});
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {

export function reportUntruncatedBlogPosts({
blogPosts,
onUntruncatedBlogPost,
onUntruncatedBlogPosts,
}: {
blogPosts: BlogPost[];
onUntruncatedBlogPost: PluginOptions['onUntruncatedBlogPost'];
onUntruncatedBlogPosts: PluginOptions['onUntruncatedBlogPosts'];
}): void {
const untruncatedBlogPosts = blogPosts.filter(
(p) => !p.metadata.hasTruncateMarker,
);
if (onUntruncatedBlogPost !== 'ignore' && untruncatedBlogPosts.length > 0) {
if (onUntruncatedBlogPosts !== 'ignore' && untruncatedBlogPosts.length > 0) {
const message = `Docusaurus found untruncated blog posts:
${untruncatedBlogPosts
.map((p) => aliasedSitePathToRelativePath(p.metadata.source))
.join('\n- ')}
You can turn off this settings by setting onUntruncatedBlogPost to 'ignore' in your docusaurus config file`;
logger.report(onUntruncatedBlogPost)(message);
You can turn off this settings by setting onUntruncatedBlogPosts to 'ignore' in your docusaurus config file`;
logger.report(onUntruncatedBlogPosts)(message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default async function pluginContentBlog(
});
reportUntruncatedBlogPosts({
blogPosts,
onUntruncatedBlogPost: options.onUntruncatedBlogPost,
onUntruncatedBlogPosts: options.onUntruncatedBlogPosts,
});
const listedBlogPosts = blogPosts.filter(shouldBeListed);

Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-content-blog/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
tags: undefined,
authorsBasePath: 'authors',
onInlineAuthors: 'warn',
onUntruncatedBlogPost: 'warn',
onUntruncatedBlogPosts: 'warn',
};

export const XSLTBuiltInPaths = {
Expand Down Expand Up @@ -241,9 +241,9 @@ const PluginOptionSchema = Joi.object<PluginOptions>({
onInlineAuthors: Joi.string()
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_OPTIONS.onInlineAuthors),
onUntruncatedBlogPost: Joi.string()
onUntruncatedBlogPosts: Joi.string()
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_OPTIONS.onUntruncatedBlogPost),
.default(DEFAULT_OPTIONS.onUntruncatedBlogPosts),
}).default(DEFAULT_OPTIONS);

export function validateOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ declare module '@docusaurus/plugin-content-blog' {
authorsBasePath: string;
/** The behavior of Docusaurus when it finds inline authors. */
onInlineAuthors: 'ignore' | 'log' | 'warn' | 'throw';
onUntruncatedBlogPost: 'ignore' | 'log' | 'warn' | 'throw';
/** The behavior of Docusaurus when it finds untruncated blog posts. */
onUntruncatedBlogPosts: 'ignore' | 'log' | 'warn' | 'throw';
};

export type UserFeedXSLTOptions =
Expand Down
2 changes: 1 addition & 1 deletion website/_dogfooding/dogfooding.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const dogfoodingPluginInstances: PluginConfig[] = [
: defaultReadingTime({content, options: {wordsPerMinute: 5}}),
onInlineTags: 'warn',
onInlineAuthors: 'ignore',
onUntruncatedBlogPost: 'ignore',
onUntruncatedBlogPosts: 'ignore',
tags: 'tags.yml',
} satisfies BlogOptions,
],
Expand Down
2 changes: 1 addition & 1 deletion website/docs/api/plugins/plugin-content-blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Accepted fields:
| `showLastUpdateTime` | `boolean` | `false` | Whether to display the last date the blog post was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub `actions/checkout`, use`fetch-depth: 0`. |
| `tags` | `string \| false \| null \| undefined` | `tags.yml` | Path to the YAML tags file listing pre-defined tags. Relative to the blog content directory. |
| `onInlineTags` | `'ignore' \| 'log' \| 'warn' \| 'throw'` | `warn` | The plugin behavior when blog posts contain inline tags (not appearing in the list of pre-defined tags, usually `tags.yml`). |
| `onUntruncatedBlogPost` | `'ignore' \| 'log' \| 'warn' \| 'throw'` | `warn` | The plugin behavior when blog posts do not contain a truncate marker. |
| `onUntruncatedBlogPosts` | `'ignore' \| 'log' \| 'warn' \| 'throw'` | `warn` | The plugin behavior when blog posts do not contain a truncate marker. |

```mdx-code-block
</APITable>
Expand Down
2 changes: 1 addition & 1 deletion website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ export default async function createConfigAsync() {
blog: {
// routeBasePath: '/',
path: 'blog',
onUntruncatedBlogPost: 'throw',
showLastUpdateAuthor: true,
showLastUpdateTime: true,
editUrl: ({locale, blogDirPath, blogPath}) => {
Expand All @@ -497,6 +496,7 @@ export default async function createConfigAsync() {
blogDescription: 'Read blog posts about Docusaurus from the team',
blogSidebarCount: 'ALL',
blogSidebarTitle: 'All our posts',
onUntruncatedBlogPosts: 'throw',
onInlineTags:
process.env.DOCUSAURUS_CURRENT_LOCALE !== defaultLocale
? 'warn'
Expand Down

0 comments on commit 3da8f60

Please sign in to comment.