Skip to content

Commit

Permalink
feat: onUntruncatedBlogPost blog options
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed Aug 5, 2024
1 parent 7be1fea commit bbb522d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {
return fileString.split(truncateMarker, 1).shift()!;
}

function reportTruncateMarkerProblem({
blogSourceRelative,
truncateMarker,
options,
content,
}: {
content: string;
truncateMarker: RegExp;
blogSourceRelative: string;
options: Pick<PluginOptions, 'onUntruncatedBlogPost'>;

Check failure on line 59 in packages/docusaurus-plugin-content-blog/src/blogUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- Pick<PluginOptions, 'onUntruncatedBlogPost'>;
}): void {
if (!truncateMarker.test(content)) {
logger.report(options.onUntruncatedBlogPost)(

Check failure on line 62 in packages/docusaurus-plugin-content-blog/src/blogUtils.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- logger.report(options.onUntruncatedBlogPost)(
logger.interpolate`Blog post path=${blogSourceRelative} is not truncated.`,
);
}
}

export function paginateBlogPosts({
blogPosts,
basePageUrl,
Expand Down Expand Up @@ -228,6 +246,13 @@ async function processBlogSourceFile(
parseFrontMatter,
});

reportTruncateMarkerProblem({
blogSourceRelative,
truncateMarker,
options,
content,
});

const aliasedSource = aliasedSitePath(blogSourceAbsolute, siteDir);

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

Check failure on line 75 in packages/docusaurus-plugin-content-blog/src/options.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- onUntruncatedBlogPost: 'warn',
};

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

Check failure on line 244 in packages/docusaurus-plugin-content-blog/src/options.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- onUntruncatedBlogPost: Joi.string
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_OPTIONS.onUntruncatedBlogPost),

Check failure on line 246 in packages/docusaurus-plugin-content-blog/src/options.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- default(DEFAULT_OPTIONS.onUntruncatedBlogPost),
}).default(DEFAULT_OPTIONS);

export function validateOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ 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';

Check failure on line 524 in packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- onUntruncatedBlogPost: 'ignore' |
};

export type UserFeedXSLTOptions =
Expand Down
1 change: 1 addition & 0 deletions website/_dogfooding/dogfooding.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const dogfoodingPluginInstances: PluginConfig[] = [
: defaultReadingTime({content, options: {wordsPerMinute: 5}}),
onInlineTags: 'warn',
onInlineAuthors: 'ignore',
onUntruncatedBlogPost: 'ignore',

Check failure on line 102 in website/_dogfooding/dogfooding.config.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- onUntruncatedBlogPost: 'ignore',
tags: 'tags.yml',
} satisfies BlogOptions,
],
Expand Down
1 change: 1 addition & 0 deletions website/docs/api/plugins/plugin-content-blog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +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 does not contain truncate marker |

Check failure on line 88 in website/docs/api/plugins/plugin-content-blog.mdx

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- | `onUntruncatedBlogPost` | `'ignore

```mdx-code-block
</APITable>
Expand Down
1 change: 1 addition & 0 deletions website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ export default async function createConfigAsync() {
blog: {
// routeBasePath: '/',
path: 'blog',
onUntruncatedBlogPost: 'throw',

Check failure on line 478 in website/docusaurus.config.ts

View workflow job for this annotation

GitHub Actions / Lint

Unknown word (Untruncated) -- onUntruncatedBlogPost: 'throw',
showLastUpdateAuthor: true,
showLastUpdateTime: true,
editUrl: ({locale, blogDirPath, blogPath}) => {
Expand Down

0 comments on commit bbb522d

Please sign in to comment.