mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-26 07:47:58 +02:00
feat(blog): add onUntruncatedBlogPosts
blog options (#10375)
Co-authored-by: OzakIOne <OzakIOne@users.noreply.github.com> Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
f43be857d7
commit
a096bbc0b9
10 changed files with 189 additions and 0 deletions
packages/docusaurus-plugin-content-blog/src
|
@ -26,6 +26,7 @@ import {
|
|||
isDraft,
|
||||
readLastUpdateData,
|
||||
normalizeTags,
|
||||
aliasedSitePathToRelativePath,
|
||||
} from '@docusaurus/utils';
|
||||
import {getTagsFile} from '@docusaurus/utils-validation';
|
||||
import {validateBlogPostFrontMatter} from './frontMatter';
|
||||
|
@ -47,6 +48,28 @@ export function truncate(fileString: string, truncateMarker: RegExp): string {
|
|||
return fileString.split(truncateMarker, 1).shift()!;
|
||||
}
|
||||
|
||||
export function reportUntruncatedBlogPosts({
|
||||
blogPosts,
|
||||
onUntruncatedBlogPosts,
|
||||
}: {
|
||||
blogPosts: BlogPost[];
|
||||
onUntruncatedBlogPosts: PluginOptions['onUntruncatedBlogPosts'];
|
||||
}): void {
|
||||
const untruncatedBlogPosts = blogPosts.filter(
|
||||
(p) => !p.metadata.hasTruncateMarker,
|
||||
);
|
||||
if (onUntruncatedBlogPosts !== 'ignore' && untruncatedBlogPosts.length > 0) {
|
||||
const message = logger.interpolate`Docusaurus found blog posts without truncation markers:
|
||||
- ${untruncatedBlogPosts
|
||||
.map((p) => logger.path(aliasedSitePathToRelativePath(p.metadata.source)))
|
||||
.join('\n- ')}
|
||||
|
||||
We recommend using truncation markers (code=${`<!-- truncate -->`} or code=${`{/* truncate */}`}) in blog posts to create shorter previews on blog paginated lists.
|
||||
Tip: turn this security off with the code=${`onUntruncatedBlogPosts: 'ignore'`} blog plugin option.`;
|
||||
logger.report(onUntruncatedBlogPosts)(message);
|
||||
}
|
||||
}
|
||||
|
||||
export function paginateBlogPosts({
|
||||
blogPosts,
|
||||
basePageUrl,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue