docusaurus: Customize page title per plugin instance - avoid duplicated page title

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

By default, the landing page name repeats itself, i.e. “Auth with Caddy | Auth with Caddy”.

image

Steps to reproduce

Please see the landing page of https://authp.github.io/

Expected behavior

The page name should not repeat, i.e. be “Auth with Caddy”.

Actual behavior

The name repeats itself “Auth with Caddy | Auth with Caddy”.

image

Your environment

Reproducible demo

No response

Self-service

  • I’d be willing to fix this bug myself.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 15 (1 by maintainers)

Most upvoted comments

You can omit the title field in the home page layout:

export default function home() {
  return (
    // Don't add the title here
    <Layout>
      {/* ... */}
    <Layout>
  )
}

And I do think there’s something we can do: check if site title is equal to page title, and do not duplicate if that’s the case:

https://github.com/facebook/docusaurus/blob/cbcaa52f88cb702a3712c2b4c19b02225f975ea9/packages/docusaurus-theme-common/src/utils/generalUtils.ts#L12-L14

#11090 is a nice feature, but it seems the <title> and <meta name="og:title"> are still required to be the same. Would it be possible to make these different? For example, it’s common for sites to specify og:title + og:site_name metadata separately, and then use <title>{title} | {siteName}</title> for the traditional title.

The use-case will be solved by https://github.com/facebook/docusaurus/pull/11090 in v3.8

For now, the API is not perfect, but it is the most flexible: you will need to swizzle a small theme component, which makes it possible to provide your own code logic instead of dealing with a static string template.

We may provide a siteConfig option later.

I’d also like to collect feedback before implementing a new public siteConfig API. For example: are the provided callback params enough to solve most use cases?

Maybe we’ll also want to deprecate siteConfig.titleDelimiter later if we have a more powerful API.


In the future, we’ll likely implement an API to assign a “label” to a plugin instance. For example, you may have 2 docs plugin instance (iOS + Android). Plugin ids are used for file system paths, and are not meant to be displayed in meta title. So a plugin instance label would look cleaner to display in a title.

We also need this for docs breadcrumbs, where we’d want a breadcrumb such as Home > iOS > My iOS doc page, see related issues:

You can omit the title field in the home page layout:

@Josh-Cena , thank you! This change from defaults worked! 👍

And I do think there’s something we can do: check if site title is equal to page title, and do not duplicate if that’s the case:

Yes, that would be great!

Additionally, it would be nice to have "Page Name" | "Instance Name" | "Site Title" in the case of multi-doc instance.

For example, I have two pages:

Path Page Name
https://authp.github.io/docs/authenticate/intro Auth Portal Plugin Overview | Auth with Caddy
https://authp.github.io/docs/authorize/intro Authorize Plugin Overview | Auth with Caddy

It would be nice to have instance name (i.e. Authenticate and Authorize) taken into account.

Path Page Name
https://authp.github.io/docs/authenticate/intro Auth Portal Plugin Overview | Authenticate | Auth with Caddy
https://authp.github.io/docs/authorize/intro Authorize Plugin Overview | Authorize | Auth with Caddy