mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-30 17:37:09 +02:00
feat(v2): support custom description for blog-only mode (#2359)
* feat: support custom description on blog page resolve conflicts * feat(v2): allow additional props to pass to route components resolve conflicts * Update blogDescription feature * Update doc for blogDescription * Remove test blogDescription config * Fix blogDescription schema validation * Fix minor errors Co-authored-by: Xuqian <zxuqian@163.com>
This commit is contained in:
parent
1db3fbb564
commit
4af25cd597
6 changed files with 32 additions and 3 deletions
|
@ -133,6 +133,7 @@ export default function pluginContentBlog(
|
||||||
page < numberOfPages - 1
|
page < numberOfPages - 1
|
||||||
? blogPaginationPermalink(page + 1)
|
? blogPaginationPermalink(page + 1)
|
||||||
: null,
|
: null,
|
||||||
|
blogDescription: options.blogDescription,
|
||||||
},
|
},
|
||||||
items: blogPosts
|
items: blogPosts
|
||||||
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
||||||
|
|
|
@ -20,6 +20,7 @@ export const DEFAULT_OPTIONS = {
|
||||||
blogTagsListComponent: '@theme/BlogTagsListPage',
|
blogTagsListComponent: '@theme/BlogTagsListPage',
|
||||||
blogPostComponent: '@theme/BlogPostPage',
|
blogPostComponent: '@theme/BlogPostPage',
|
||||||
blogListComponent: '@theme/BlogListPage',
|
blogListComponent: '@theme/BlogListPage',
|
||||||
|
blogDescription: 'Blog',
|
||||||
postsPerPage: 10,
|
postsPerPage: 10,
|
||||||
include: ['*.md', '*.mdx'],
|
include: ['*.md', '*.mdx'],
|
||||||
routeBasePath: 'blog',
|
routeBasePath: 'blog',
|
||||||
|
@ -42,6 +43,9 @@ export const PluginOptionSchema = Joi.object({
|
||||||
blogTagsPostsComponent: Joi.string().default(
|
blogTagsPostsComponent: Joi.string().default(
|
||||||
DEFAULT_OPTIONS.blogTagsPostsComponent,
|
DEFAULT_OPTIONS.blogTagsPostsComponent,
|
||||||
),
|
),
|
||||||
|
blogDescription: Joi.string()
|
||||||
|
.allow('')
|
||||||
|
.default(DEFAULT_OPTIONS.blogDescription),
|
||||||
showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
|
showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
|
||||||
remarkPlugins: Joi.array()
|
remarkPlugins: Joi.array()
|
||||||
.items(
|
.items(
|
||||||
|
|
|
@ -29,6 +29,7 @@ export interface PluginOptions {
|
||||||
blogPostComponent: string;
|
blogPostComponent: string;
|
||||||
blogTagsListComponent: string;
|
blogTagsListComponent: string;
|
||||||
blogTagsPostsComponent: string;
|
blogTagsPostsComponent: string;
|
||||||
|
blogDescription: string;
|
||||||
remarkPlugins: ([Function, object] | Function)[];
|
remarkPlugins: ([Function, object] | Function)[];
|
||||||
rehypePlugins: string[];
|
rehypePlugins: string[];
|
||||||
truncateMarker: RegExp;
|
truncateMarker: RegExp;
|
||||||
|
@ -67,6 +68,7 @@ export interface BlogPaginatedMetadata {
|
||||||
totalCount: number;
|
totalCount: number;
|
||||||
previousPage: string | null;
|
previousPage: string | null;
|
||||||
nextPage: string | null;
|
nextPage: string | null;
|
||||||
|
blogDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BlogPaginated {
|
export interface BlogPaginated {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import BlogPostItem from '@theme/BlogPostItem';
|
||||||
import BlogListPaginator from '@theme/BlogListPaginator';
|
import BlogListPaginator from '@theme/BlogListPaginator';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
metadata: {permalink: string; title: string};
|
metadata: {permalink: string; title: string; blogDescription: string};
|
||||||
items: {content}[];
|
items: {content}[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ function BlogListPage(props: Props): JSX.Element {
|
||||||
} = useDocusaurusContext();
|
} = useDocusaurusContext();
|
||||||
const isBlogOnlyMode = metadata.permalink === '/';
|
const isBlogOnlyMode = metadata.permalink === '/';
|
||||||
const title = isBlogOnlyMode ? siteTitle : 'Blog';
|
const title = isBlogOnlyMode ? siteTitle : 'Blog';
|
||||||
|
const {blogDescription} = metadata;
|
||||||
return (
|
return (
|
||||||
<Layout title={title} description="Blog">
|
<Layout title={title} description={blogDescription}>
|
||||||
<div className="container margin-vert--lg">
|
<div className="container margin-vert--lg">
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<main className="col col--8 col--offset-2">
|
<main className="col col--8 col--offset-2">
|
||||||
|
|
|
@ -163,6 +163,24 @@ Don't forget to delete the existing homepage at `./src/pages/index.js` or else t
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
You can also add meta description to the blog list page for better SEO:
|
||||||
|
|
||||||
|
```js {8} title="docusaurus.config.js"
|
||||||
|
module.exports = {
|
||||||
|
// ...
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@docusaurus/preset-classic',
|
||||||
|
{
|
||||||
|
blog: {
|
||||||
|
blogDescription: 'A docusaurus powered blog!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### Multiple blogs
|
### Multiple blogs
|
||||||
|
|
||||||
By default, the classic theme assumes only one blog per website and hence includes only one instance of the blog plugin. If you would like to have multiple blogs on a single website, it's possible too! You can add another blog by specifying another blog plugin in the `plugins` option for `docusaurus.config.js`.
|
By default, the classic theme assumes only one blog per website and hence includes only one instance of the blog plugin. If you would like to have multiple blogs on a single website, it's possible too! You can add another blog by specifying another blog plugin in the `plugins` option for `docusaurus.config.js`.
|
||||||
|
|
|
@ -200,6 +200,10 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
editUrl:
|
editUrl:
|
||||||
'https://github.com/facebook/docusaurus/edit/master/website/blog/',
|
'https://github.com/facebook/docusaurus/edit/master/website/blog/',
|
||||||
|
/**
|
||||||
|
* Blog page meta description for better SEO
|
||||||
|
*/
|
||||||
|
blogDescription: 'Blog',
|
||||||
/**
|
/**
|
||||||
* URL route for the blog section of your site.
|
* URL route for the blog section of your site.
|
||||||
* *DO NOT* include a trailing slash.
|
* *DO NOT* include a trailing slash.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue