Dynamic `titleTemplate` needed
boxsnake opened this issue · comments
Is your feature request related to a problem? Please describe.
In my case, I want make different titleTemplate
for different route patterns.
For example, I have /guide
and /faq
. I want to use :title | A
for /guide
and :title | B
for /faq
.
Describe the solution you'd like
Two optional solutions:
- Expose a build hooks, which allows users to access
pageData
and / orsiteConfig
before build stage. - Allow
titleTemplate
inconfig.js
(config.ts
) to use a function to generate template string according topageData
andsiteConfig
.
Describe alternatives you've considered
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the docs.
- Read the Contributing Guidelines.
- Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.
I tried transformPageData
to change frontmatter's titleTemplate
, but the page's <title>
label didn't display as expected.
I did something like:
{
...
transformPageData(pageData) {
if (pageData.relativePath.includes('guide')) {
pageData.frontmatter.titleTemplate = ':title | B';
}
}
}
However, the title is still in the pattern :title | A
.
It seems only affect the variables used in vue templates, but it does not change <title>
in build stage.
transformPageData(pageData) {
if (pageData.relativePath.includes('guide')) {
pageData.titleTemplate = ':title | B'
}
}
By the way, the doc didn't state the differences between outer titleTemplate
and the one in frontmatter
object.
Hope this can be updated in the doc.
Thanks.