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:
Xuqian 2020-07-30 21:41:15 +08:00 committed by GitHub
parent 1db3fbb564
commit 4af25cd597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 3 deletions

View file

@ -133,6 +133,7 @@ export default function pluginContentBlog(
page < numberOfPages - 1
? blogPaginationPermalink(page + 1)
: null,
blogDescription: options.blogDescription,
},
items: blogPosts
.slice(page * postsPerPage, (page + 1) * postsPerPage)

View file

@ -20,6 +20,7 @@ export const DEFAULT_OPTIONS = {
blogTagsListComponent: '@theme/BlogTagsListPage',
blogPostComponent: '@theme/BlogPostPage',
blogListComponent: '@theme/BlogListPage',
blogDescription: 'Blog',
postsPerPage: 10,
include: ['*.md', '*.mdx'],
routeBasePath: 'blog',
@ -42,6 +43,9 @@ export const PluginOptionSchema = Joi.object({
blogTagsPostsComponent: Joi.string().default(
DEFAULT_OPTIONS.blogTagsPostsComponent,
),
blogDescription: Joi.string()
.allow('')
.default(DEFAULT_OPTIONS.blogDescription),
showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
remarkPlugins: Joi.array()
.items(

View file

@ -29,6 +29,7 @@ export interface PluginOptions {
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
blogDescription: string;
remarkPlugins: ([Function, object] | Function)[];
rehypePlugins: string[];
truncateMarker: RegExp;
@ -67,6 +68,7 @@ export interface BlogPaginatedMetadata {
totalCount: number;
previousPage: string | null;
nextPage: string | null;
blogDescription: string;
}
export interface BlogPaginated {

View file

@ -13,7 +13,7 @@ import BlogPostItem from '@theme/BlogPostItem';
import BlogListPaginator from '@theme/BlogListPaginator';
type Props = {
metadata: {permalink: string; title: string};
metadata: {permalink: string; title: string; blogDescription: string};
items: {content}[];
};
@ -24,9 +24,9 @@ function BlogListPage(props: Props): JSX.Element {
} = useDocusaurusContext();
const isBlogOnlyMode = metadata.permalink === '/';
const title = isBlogOnlyMode ? siteTitle : 'Blog';
const {blogDescription} = metadata;
return (
<Layout title={title} description="Blog">
<Layout title={title} description={blogDescription}>
<div className="container margin-vert--lg">
<div className="row">
<main className="col col--8 col--offset-2">

View file

@ -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
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`.

View file

@ -200,6 +200,10 @@ module.exports = {
*/
editUrl:
'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.
* *DO NOT* include a trailing slash.