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

Ability to customize page's 'title' HTML tag value #540

Closed
soulfly opened this issue Jun 15, 2018 · 3 comments
Closed

Ability to customize page's 'title' HTML tag value #540

soulfly opened this issue Jun 15, 2018 · 3 comments

Comments

@soulfly
Copy link
Contributor

soulfly commented Jun 15, 2018

Right now, the 'title' HTML tag value is generated based on sidebar item value

Sometimes I want to make it more custom, e.g. to make it more convenient for SEO, but keep it short in sidebar

Would be great to have this ability

We can do it in the same way as ignoring subheaders works
https://docsify.js.org/#/more-pages?id=ignoring-subheaders

e.g.

# Getting Started {docsify-title=Getting started with iOS machine learning SDK toolkit}

@soulfly
Copy link
Contributor Author

soulfly commented Jun 28, 2018

For everybody - I found a quick way to do it with a little of customization:

  1. btw we can provide sidebar links with titles, e.g.
    * [Getting Started](ios/getting-started.md "Getting started with iOS SDK toolkit")

  2. Then we need to customize a bit docsify.js:

In getAndActive function:

Replace this

if (autoTitle) {
      $.title = target ? ((target.innerText) + " - " + title) : title;
}

with this:

if (autoTitle) {
    if(target && target.title){
      $.title = target.title;
    }else{
      $.title = target ? ((target.innerText) + " - " + title) : title;
    }
 }

Actually I like how it works,
going to prepare a PR with the fix

hope the Docsify team will merge it 👍

@soulfly
Copy link
Contributor Author

soulfly commented Jun 28, 2018

PR prepared #557

@Giraffeness
Copy link

I wanted to add a suffix to my titles, so I wrote a little plugin:

    window.$docsify = {
      ...
      plugins: [
        titlePlugin({
          suffix: ' | My Website'
        })
      ]
    }

    function titlePlugin(config) {
      return (hook, vm) => {
        hook.doneEach((content) => {
          document.title += config.suffix
        });
      }
    }

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

No branches or pull requests

4 participants