nitinthewiz / ghost-phantom

Phantom theme for Ghost
MIT License
434 stars 121 forks source link

Sharing twitter link doesn't work on the homepage #13

Closed CMCDragonkai closed 9 years ago

CMCDragonkai commented 9 years ago

I noticed the share.hbs is:

<div class="share">
    Share this on <a id="twitter" href="http://twitter.com/share?text={{encode title}}&amp;url={{url absolute='true'}}">Twitter</a>, <a id="facebook" href="https://www.facebook.com/sharer/sharer.php?u={{url absolute='true'}}">Facebook</a> or <a id="google-plus" href="https://plus.google.com/share?url={{url absolute='true'}}">Google+</a>.
</div>

When this share snippet is on particular pages, it works, but when I put it on the homepage, the twitter link turns into: http://twitter.com/share?text=%5Bobject%20Object%5D&url=/

This tries to share [object Object] on Twitter.

It's happening on my blog: http://matrix.ai/

Any ideas on how to fix it? The other share links FB and google+ works.

haydenbleasel commented 9 years ago

Yeah I think I forgot to update the {{encode title}} helper to {{encode meta_title}} so it works on all pages. I'll fix this soon, or you can test it out and submit a PR. Up to you!

haydenbleasel commented 9 years ago

@CMCDragonkai I couldn't seem to resolve this so I've opened it up as a bug on the Ghost repo.

haydenbleasel commented 9 years ago

Turns out this is a Ghost / HBS issue so refer to the referenced issue above.

CMCDragonkai commented 9 years ago

Why can't we just do something if it's on the homepage use the blog url, if not, use what's currently there?

haydenbleasel commented 9 years ago

As a workaround, you can copy the code into index.hbs or wherever and change {{encode title}} to {{encode @blog.title}}, but at the current time you can't use the same partial in both contexts.

CMCDragonkai commented 9 years ago

Could you elaborate, I didn't quite understand what you mean.

haydenbleasel commented 9 years ago

Yeah, sorry:

So basically you can use this code on the post page:

<div class="share">
    Share this on <a id="twitter" href="http://twitter.com/share?text={{encode title}}&amp;url={{url absolute='true'}}">Twitter</a>, <a id="facebook" href="https://www.facebook.com/sharer/sharer.php?u={{url absolute='true'}}">Facebook</a> or <a id="google-plus" href="https://plus.google.com/share?url={{url absolute='true'}}">Google+</a>.
</div>

But you'll need to use this code everywhere else (homepage, author page, etc):

<div class="share">
    Share this on <a id="twitter" href="http://twitter.com/share?text={{encode @blog.title}}&amp;url={{url absolute='true'}}">Twitter</a>, <a id="facebook" href="https://www.facebook.com/sharer/sharer.php?u={{url absolute='true'}}">Facebook</a> or <a id="google-plus" href="https://plus.google.com/share?url={{url absolute='true'}}">Google+</a>.
</div>

The difference is {{encode title}} vs {{encode @blog.title}}. This means that you can't use the same partial code (share.hbs) on both pages due to current issues with Ghost.