Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize page title per plugin instance - avoid duplicated page title #5878

Open
7 tasks done
greenpau opened this issue Nov 4, 2021 · 13 comments
Open
7 tasks done
Labels
bug An error in the Docusaurus core causing instability or issues with its execution feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@greenpau
Copy link

greenpau commented Nov 4, 2021

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.
@greenpau greenpau added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Nov 4, 2021
@Josh-Cena
Copy link
Collaborator

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:

return title && title.trim().length
? `${title.trim()} ${titleDelimiter} ${siteTitle}`
: siteTitle;

@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Nov 4, 2021
@greenpau
Copy link
Author

greenpau commented Nov 4, 2021

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

@Josh-Cena
Copy link
Collaborator

I propose this API to replace the current titleDelimiter in docusaurus.config.js:

titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'

It will leverage the existing interpolate API, and you can swap out the delimiter, rearrange the components, get rid of siteTitle on all pages, etc.

Afaik, every page belongs to a plugin, so the pluginID will always be available. When pluginID === 'default', it will be omitted.

@greenpau
Copy link
Author

greenpau commented Nov 7, 2021

@Josh-Cena , what about adding pluginTitle field?

@Josh-Cena
Copy link
Collaborator

You mean... allowing each plugin instance to declare its own title component instead of relying on pluginID? That sounds fine with me

@slorber
Copy link
Collaborator

slorber commented Nov 9, 2021

Using plugin instance name in site title is a quite specific need.

In any case, I'd rather not apply this by default, and I think it's more a theming concern, not sure we want to add a nodejs plugin option just for this.

React Helmet already has a titleTemplate system so it's worth reusing it (already in use) instead of using our custom interpolate fn.

The way I'd solve it:

  • swizzle/wrap the theme DocPage component (we should rename it to something better like DocLayout, and IMHO each plugin should always have a layout comp with a consistent name)
  • add <Head titleTemplate={currentInstanceId === "ios" ? "%s | iOS | MySite" : "%s | Android | MySite"}/> in it

Didn't test this but it should work. I'd rather use this because this is a marginal use-case and we already have/want APIs to support that

@slorber
Copy link
Collaborator

slorber commented Nov 9, 2021

Oh actually didn't even notice but we don't use titleTemplate but rather a custom useTitleFormatter hook 😅

titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'

This is not a bad idea to have such a global themeConfig but the pluginId is not necessarily a good-looking label, and we can't easily make it good looking because it's used in many places like FS paths, not allowing all kind of chars.

@slorber slorber changed the title landing/home page name repeats itself Customize page title per plugin instance Nov 9, 2021
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. and removed bug An error in the Docusaurus core causing instability or issues with its execution labels Jan 31, 2022
@slorber
Copy link
Collaborator

slorber commented May 26, 2022

Relevant discussions related to customizing site title (in particular the prefix)

#6640
#7491

@elitan
Copy link

elitan commented May 31, 2022

Another one: #7535

@slorber slorber added the bug An error in the Docusaurus core causing instability or issues with its execution label Aug 16, 2022
@slorber slorber changed the title Customize page title per plugin instance Customize page title per plugin instance - avoid duplicated page title Aug 16, 2022
@anaclumos
Copy link
Contributor

Would like to hear any updates on this!

@Sas2k
Copy link

Sas2k commented Sep 30, 2022

yeah same here (Not to NecroPost)

@laureladastra
Copy link

Upvoted. Not entirely sure what the rationale was behind the decision to create these SEO values dynamically. You want to have full control as a website owner over this aspect.

@jetxr
Copy link

jetxr commented Jul 1, 2023

I propose this API to replace the current titleDelimiter in docusaurus.config.js:

titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'

It will leverage the existing interpolate API, and you can swap out the delimiter, rearrange the components, get rid of siteTitle on all pages, etc.

This would be superb. Would help to avoid swizzling layouts just to change the title format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

8 participants