Skip to content

init should include titleTemplate in generated index.mts #3375

@jblachly

Description

@jblachly

Describe the bug

npx vitepress init generates a default .vitepress/config.mts based on user responses, which is helpful. One of these questions/responses is the title of the site. This is inserted into config.mts as the title: kv pair for the config object.

However, when title exists without titleTemplate, the html <title> is rendered with duplication.

For example, if the user answers My Site to the title question, the browser displays in the tab or bookmark the title of the site as "My Site | My Site". This is not only unattractive, but it's difficult to discover why this is happening.

Reproduction

https://stackblitz.com/edit/vite-fmv5pr?file=docs%2F.vitepress%2Fconfig.ts

Open the resulting site @ webcontainer.io in a separate browser window to see the result.

Expected behavior

I expect no duplication. This could be accomplished by:

  1. changing the render code so that if titleTemplate is missing, that title is not rendered as <title>{{ title }} | {{ title }}</title>
  2. Including a titleTemplate in the init questionnaire; or simply including a default value that is different than what the user answered for title

System Info

System:
    OS: macOS 12.6.7
    CPU: (10) arm64 Apple M1 Pro
    Memory: 80.66 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 120.0.6099.129
    Safari: 17.1


### Additional context

_No response_

### Validations

- [X] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).
- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)
- [X] Read the [docs](https://vitepress.dev).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions