Skip to content

Commit

Permalink
feat(v2): add option for blog meta title #3571
Browse files Browse the repository at this point in the history
* feat(blog-meta-title): add support for additional meta title

* retrocompatible blog title

Co-authored-by: slorber <lorber.sebastien@gmail.com>
  • Loading branch information
DeadEnglish and slorber authored Oct 12, 2020
1 parent 2e51034 commit d151077
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-blog/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ declare module '@theme/BlogListPage' {
};

export type Metadata = {
readonly blogTitle: string;
readonly blogDescription: string;
readonly nextPage?: string;
readonly page: number;
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default function pluginContentBlog(
? blogPaginationPermalink(page + 1)
: null,
blogDescription: options.blogDescription,
blogTitle: options.blogTitle,
},
items: blogPosts
.slice(page * postsPerPage, (page + 1) * postsPerPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const DEFAULT_OPTIONS = {
blogPostComponent: '@theme/BlogPostPage',
blogListComponent: '@theme/BlogListPage',
blogDescription: 'Blog',
blogTitle: 'Blog',
postsPerPage: 10,
include: ['*.md', '*.mdx'],
routeBasePath: 'blog',
Expand All @@ -52,6 +53,7 @@ export const PluginOptionSchema = Joi.object({
blogTagsPostsComponent: Joi.string().default(
DEFAULT_OPTIONS.blogTagsPostsComponent,
),
blogTitle: Joi.string().allow('').default(DEFAULT_OPTIONS.blogTitle),
blogDescription: Joi.string()
.allow('')
.default(DEFAULT_OPTIONS.blogDescription),
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-plugin-content-blog/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface PluginOptions {
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
blogTitle: string;
blogDescription: string;
remarkPlugins: ([Function, object] | Function)[];
beforeDefaultRehypePlugins: ([Function, object] | Function)[];
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface BlogPaginatedMetadata {
totalCount: number;
previousPage: string | null;
nextPage: string | null;
blogTitle: string;
blogDescription: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ function BlogListPage(props: Props): JSX.Element {
const {
siteConfig: {title: siteTitle},
} = useDocusaurusContext();
const isBlogOnlyMode = metadata.permalink === '/';
const title = isBlogOnlyMode ? siteTitle : 'Blog';
const {blogDescription, blogTitle, permalink} = metadata;
const isBlogOnlyMode = permalink === '/';
const title = isBlogOnlyMode ? siteTitle : blogTitle;

return (
<Layout title={title} description="Blog">
<Layout title={title} description={blogDescription}>
<div className="container-fluid mt-4">
<div className="row row-cols-1 row-cols-sm-1">
{items.map(({content: BlogPostContent}) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function BlogListPage(props: Props): JSX.Element {
const {
siteConfig: {title: siteTitle},
} = useDocusaurusContext();
const isBlogOnlyMode = metadata.permalink === '/';
const title = isBlogOnlyMode ? siteTitle : 'Blog';
const {blogDescription} = metadata;
const {blogDescription, blogTitle, permalink} = metadata;
const isBlogOnlyMode = permalink === '/';
const title = isBlogOnlyMode ? siteTitle : blogTitle;
return (
<Layout title={title} description={blogDescription}>
<div className="container margin-vert--lg">
Expand Down
1 change: 1 addition & 0 deletions website/docs/blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ module.exports = {
'@docusaurus/preset-classic',
{
blog: {
blogTitle: 'Docusaurus blog!',
blogDescription: 'A docusaurus powered blog!',
},
},
Expand Down
4 changes: 4 additions & 0 deletions website/docs/using-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ module.exports = {
*/
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/blog/',
/**
* Blog page title for better SEO
*/
blogTitle: 'Blog title',
/**
* Blog page meta description for better SEO
*/
Expand Down

0 comments on commit d151077

Please sign in to comment.