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

og:url incorrect when site is put under subdirectory #942

Closed
leesei opened this issue Dec 1, 2014 · 4 comments · Fixed by #2348
Closed

og:url incorrect when site is put under subdirectory #942

leesei opened this issue Dec 1, 2014 · 4 comments · Fixed by #2348
Labels
bug Something isn't working

Comments

@leesei
Copy link
Member

leesei commented Dec 1, 2014

_config.yml

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com/child
root: /child/

In HTML's meta

<meta property="og:url" content="http://yoursite.com/child/child/">
@guiohm
Copy link

guiohm commented Dec 6, 2014

Same here.

@apalskoi
Copy link

I am having the same issue. I have fixed it for now by adding a replacement for the 'url' option of open_graph in the layout/_partial/head.ejs:

url: url.replace('/blog/blog', '/blog') - my blog is in the '/blog' subdirectory.

<%- open_graph({twitter_id: theme.twitter, google_plus: theme.google_plus, fb_admins: theme.fb_admins, fb_app_id: theme.fb_app_id, url: url.replace('/blog/blog', '/blog')}) %>

@leesei leesei added the bug Something isn't working label Jul 16, 2015
@kflu
Copy link
Contributor

kflu commented Jan 9, 2017

Same problem here. Problem is facebook won't display images when sharing links that have the invalid og:image tags. I worked it around by commenting those out.

But it seems the true fix really should be in node_modules\hexo\lib\plugins\helper\open_graph.js:

  images = images.map(function(path) {
    if (!urlFn.parse(path).host) {
      if (path[0] !== '/') path = '/' + path;
      return config.url + path;  // <------ THIS IS WRONG
    }

    return path;
  });

THe marked line above is wrong. Instead, we should use something like return currentPageUrl + path;. But I don't know how to get currentPageUrl in that file. Any hint?

@kflu
Copy link
Contributor

kflu commented Jan 9, 2017

OK. I've fixed this with:


  images = images.map(function(path) {
    if (!urlFn.parse(path).host) {
      if (path[0] !== '/') {
        return urlFn.resolve(url, path);
      }
    }

    return path;
  });

kflu added a commit to kflu/hexo that referenced this issue Jan 9, 2017
@kflu kflu mentioned this issue Jan 9, 2017
NoahDragon pushed a commit that referenced this issue Jan 18, 2017
* Fix issue #942

* Fix test cases

* Add test coverage

* Fix eslint

* Fix jscs failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants