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

Add support for title templates #2151

Open
abdrahmanrizk opened this issue Feb 7, 2025 · 1 comment
Open

Add support for title templates #2151

abdrahmanrizk opened this issue Feb 7, 2025 · 1 comment
Labels

Comments

@abdrahmanrizk
Copy link

Description

Description

Currently, when setting page titles in Vike, we have to manually handle title templates for each page. Having built-in support for title templates would improve developer experience and provide a consistent way to handle page titles across the application.

Current Workaround

Currently, we have to manually concatenate titles:

config({
  title: `My Site | ${pageContext.config.meta?.title}`,
});

Proposed Solution

Add support for title templates similar to other meta frameworks. For example:

export default {
  meta: {
    titleTemplate: '%s | My Site', // or (title) => `${title} | My Site`
  }
}

Then in page components:

config({
  title: 'Articles', // Would automatically become "Articles | My Site"
})
@abdrahmanrizk abdrahmanrizk added the enhancement 🚀 New feature or request label Feb 7, 2025
@brillout
Copy link
Member

brillout commented Feb 7, 2025

Yes, that's would be nice. It's very much something we want to implement.

Also, I was thinking of adding a new config +name with a default +titleTemplate:

// Default +titleTemplate
function titleTemplate(pageContext) {
  const { title, name } = pageContext.config
  if (!name || !title) return null
  return `${title} | ${name}`
}

The +name config would also set <meta property="og:site_name" content="${pageContext.config.name}">.

Or maybe projectName instead of name to be less ambiguous.

WDYT? (Contribution/PR welcome in case that's something you'd be up to.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants