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

Make it possible to set homepage title #2247

Closed
alizadeh118 opened this issue Mar 24, 2020 · 8 comments
Closed

Make it possible to set homepage title #2247

alizadeh118 opened this issue Mar 24, 2020 · 8 comments
Labels
contribution welcome Contributions welcome topic: theme Relates to VuePress theme

Comments

@alizadeh118
Copy link
Contributor

Feature request

What problem does this feature solve?

It gives the ability to change home page title.

What does the proposed API look like?

It's not going to change API.

How should this be implemented in your opinion?

Imagine you want to use homepage option so you set home: true then you search something that exist on homepage:
Screen Shot 1399-01-05 at 16 12 41
It is shown as Home and you can not change homepage title because when home is true it's hard coded and I don't know why:

if (frontmatter.home) {
return 'Home'
}

Are you willing to work on this yourself?

Yes.

@meteorlxy meteorlxy added contribution welcome Contributions welcome topic: theme Relates to VuePress theme labels Apr 8, 2020
@meteorlxy
Copy link
Member

Contribtion welcome.

Tip: remember to consider the locales support

@Mister-Hope
Copy link
Contributor

Mister-Hope commented Apr 14, 2020

Are you willing to work on this yourself?

Yes.

Are you working on it? I can help if you need @alizadeh118

alizadeh118 added a commit to alizadeh118/vuepress that referenced this issue Apr 14, 2020
@alizadeh118
Copy link
Contributor Author

alizadeh118 commented Apr 14, 2020

I made a PR and honestly I didn't change a lot but it fixes the problem.
Hope to work as my first PR on GitHub :)

alizadeh118 added a commit to alizadeh118/vuepress that referenced this issue Apr 14, 2020
@Mister-Hope
Copy link
Contributor

Mister-Hope commented Apr 14, 2020

I made a PR and honestly I didn't change a lot but it fixes the problem.
Hope to work as my first PR on GitHub :)

As meteorlxy suggested above, could you make the default word 'Home' changed with locales? Just a suggestion.

@alizadeh118
Copy link
Contributor Author

I'll work on it.

@alizadeh118
Copy link
Contributor Author

alizadeh118 commented Apr 15, 2020

I have checked the code and I'm not sure about something and I need your help.

How should it exactly support locales for "Home" default title?

I can imagine three options:

  1. We can use locales that users provide on .vuepress/config.js and look for some property like homepageTitle for each locale.

  2. As we have homepage as a feature for default theme and some themes may not have homepage, we can implement this in default theme scope and use default theme i18n config and get some value from its locales property and for each locale, like that homepageTitle.

But the problem for both is that we already made it possible to set homepage title from home frontmatter title property. And actually our challenge was about default title for homepage, means there is no a defined title by user anywhere.

  1. So we can have a data list of translations for word of Home for all languages that are used as a default when the user doesn't set title for homepage in home frontmatter.

But I'm not sure about having such a big list in core only for support default Home word for locales.

Thank you in advance for you suggestions.

@Mister-Hope
Copy link
Contributor

i think 1 is not necessary, and 3 is what I want, any problem doing 2 such as cannot get the locale?

@alizadeh118
Copy link
Contributor Author

alizadeh118 commented Apr 16, 2020

There is no problem for getting the locale from default theme config (2nd scenario), but I mean if we want to obtain homepage title from user explicitly, we don't have to get it from theme config because we can get it from homepage frontmatter.

So let's say we have a complete list of translations for Home for each language (3rd scenario),
Although I'm not sure that how we should get this list but anyway:

{
  "en": "Home",
  "zh": ""
}

How should we find out the page (homepage) locale in inferTitle function?
When inferTitle is called in Page.js:

const title = inferTitle(this.frontmatter, this._strippedContent)

we have access to siteConfig and themeConfig and path:

Page {
  _context: App {
    siteConfig: {
  	  locales: {
  	    '/': {
  	      lang: 'en-US',
  	      title: 'VuePress',
  	      description: 'Vue-powered Static Site Generator',
  	      homepageTitle: 'Home',
  	      path: '/'
  	    },
  	    '/zh/': {
  	      lang: 'zh-CN',
  	      title: 'VuePress',
  	      description: 'Vue 驱动的静态网站生成器',
  	      homepageTitle: '家',
  	      path: '/zh/'
  	    }
  	  },
  	  theme: '@vuepress/vue',
  	  themeConfig: {
  	    locales: {
  	      '/': {
  	        label: 'English',
  	        selectText: 'Languages',
  	        ariaLabel: 'Select language',
  	        editLinkText: 'Edit this page on GitHub',
  	        lastUpdated: 'Last Updated',
  	        nav: [Array],
  	        sidebar: [Object]
  	      },
  	      '/zh/': {
  	        label: '简体中文',
  	        selectText: '选择语言',
  	        ariaLabel: '选择语言',
  	        editLinkText: '在 GitHub 上编辑此页',
  	        lastUpdated: '上次更新',
  	        nav: [Array],
  	        sidebar: [Object]
  	      }
  	  },
    },
  regularPath: '/',
  relativePath: 'README.md',
  path: '/'
}

We can pass siteConfig.locales to inferTitle as third parameter then make a loop and map lang onto path, for example { en: '/', zh: '/zh/ } then detect the page locale from the path and finally get the correct Home translations from our list.

But I don't think it's a good idea and also I have no another!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Contributions welcome topic: theme Relates to VuePress theme
Projects
None yet
Development

No branches or pull requests

3 participants