Skip to content

'/' missing in canonical link in the category pages #949

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

Closed
floydpink opened this issue Jan 17, 2013 · 10 comments
Closed

'/' missing in canonical link in the category pages #949

floydpink opened this issue Jan 17, 2013 · 10 comments

Comments

@floydpink
Copy link
Contributor

First up, thanks heaps for Octopress! Love it!

Here's my setup:
The blog (deployed here) is being published to the /blogs sub-directory of an existing gh-pages branch, whose root has the main site. (As an aside, the rake deploy script has been tweaked slightly to accommodate the main site as well, to the effect that there is a git pull --rebase from gh-pages first, and then a git push).

Running on Windows 7, with Git Bash and Ruby 1.9.3 installed via RubyInstaller.
The blog source is here.

The issue I have is that the canonical link url in the category pages alone, are all with the / between blogs and blog missing.

After source\_includes\head.html was tweaked as below (to see the variables that are in play to generate the canonical url):

   {% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' }}{% endif %}{% endcapture %}
+  <!-- site.url: {{ site.url }} -->
+  <!-- site.permalink: {{ site.permalink }} -->
+  <!-- page.url: {{ page.url }} -->
+  <!-- canonical: {{ canonical }} -->
   <link rel="canonical" href="{{ canonical }}">
   <link href="{{ root_url }}/favicon.png" rel="icon">
   <link href="{{ root_url }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">

...here are the excerpts from:

  • public\blogs\blog\archives\index.html ( good )
  <!-- site.url: http://flickrdownloadr.com/blogs -->
  <!-- site.permalink: /blog/:year/:month/:day/:title/ -->
  <!-- page.url: /blog/archives/index.html -->
  <!-- canonical: http://flickrdownloadr.com/blogs/blog/archives/ -->
  <link rel="canonical" href="http://flickrdownloadr.com/blogs/blog/archives/">
  • public\blogs\index.html ( good )
  <!-- site.url: http://flickrdownloadr.com/blogs -->
  <!-- site.permalink: /blog/:year/:month/:day/:title/ -->
  <!-- page.url: /index.html -->
  <!-- canonical: http://flickrdownloadr.com/blogs/ -->
  <link rel="canonical" href="http://flickrdownloadr.com/blogs/">
  • and public\blogs\blog\categories\general ( bad! )
  <!-- site.url: http://flickrdownloadr.com/blogs -->
  <!-- site.permalink: /blog/:year/:month/:day/:title/ -->
  <!-- page.url: blog/categories/general/index.html -->
  <!-- canonical: http://flickrdownloadr.com/blogsblog/categories/general/ -->
  <link rel="canonical" href="http://flickrdownloadr.com/blogsblog/categories/general/">

So, I see that the page.url not starting with a / is what is causing the canonical link in the category pages to be generated incorrectly, but I do not know if this is just me alone or how I could fix this.

Could someone help please?

@footedesign
Copy link

I addressed this in Pull #980 if you want to see what I did. Really easy fix.

@floydpink
Copy link
Contributor Author

@footedesign: It does fix the canonical link, but adds an additional / to all the category links (including in the RSS feed):

The Good:

<link rel="canonical" href="http://www.harimenon.com/blog/categories/blog/">

The side effects:

<a class='category' href='//blog/categories/octopress/'>Octopress</a>, <a class='category' href='//blog/categories/travis-ci/'>Travis-CI</a>, <a class='category' href='//blog/categories/blog/'>blog</a>, <a class='category' href='//blog/categories/technical/'>technical</a>
<footer>
  <span class="categories">posted in <a class='category' href='//blog/categories/octopress/'>Octopress</a>, <a class='category' href='//blog/categories/travis-ci/'>Travis-CI</a>, <a class='category' href='//blog/categories/blog/'>blog</a>, <a class='category' href='//blog/categories/technical/'>technical</a></span>
</footer>
<link href="http://www.harimenon.com//blog/categories/blog/atom.xml" rel="self"/>

@alexkirmse
Copy link

Yeah ran into this as well...this, somewhat hackish approach, seemed to work. Adds a forward slash if the page.url contains 'categories':

{% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{% if page.url contains 'categories' %}/{% endif %}{{ page.url | remove:'index.html' }}{% endif %}{% endcapture %}

@floydpink
Copy link
Contributor Author

Thanks @alexkirmse. I have included this into another pull request I have open (#953)

@floydpink
Copy link
Contributor Author

@alexkirmse: I have enhanced the change a little bit as could be seen here.
It avoids the check for a hard-coded 'categories' and instead goes after site.category_dir

@alexkirmse
Copy link

site.category_dir is definitely cleaner, thanks!

@swestcott
Copy link

Most recent patch works for me too, thanks.

@parkr
Copy link
Collaborator

parkr commented Feb 12, 2013

@floydpink This included in #953?

@floydpink
Copy link
Contributor Author

@parkr Yep. But that is off of master and not 2.1
If you could take this into both those branches, that would be awesome

Thanks

parkr pushed a commit that referenced this issue Feb 13, 2013
parkr pushed a commit that referenced this issue Feb 13, 2013
@floydpink
Copy link
Contributor Author

Thank you, @parkr

jhwist pushed a commit to jhwist/octopress that referenced this issue Feb 25, 2013
paxswill added a commit to paxswill/StupidRobots that referenced this issue Mar 29, 2013
* 'master' of git://github.com/imathis/octopress: (51 commits)
  fixed addSidebarToggler where index and section were flip-flopped
  Added sass-globbing, allowing plugin stylesheets to be auto-imported from the assets/stylesheets/plugins directory
  Improved: config_tag plugin is much more flexible now and can be used by other plugins directly through the config_tag method
  added config_tag plugin for integration of configuration into templates
  Fixed GitHub jsonp call. Closed imathis#1118
  removed Twitter configuration for timeline and follow buton which are no longer integrated
  Mobile nav fixed.
  Removed Twitter and Ender.js. Added jQuery and updated Modernizr
  Added .gitattributes file to keep CRLF's out of the codebase.
  Using data.code.to_i like a true Rubyist in plugins/gist_code.rb. Heh. imathis#438
  Using data.code.to_i like a true Rubyist in plugins/gist_code.rb. Heh. imathis#438
  Bump sinatra to 1.3.5
  It's 2013. Hi, MIT License.
  Use HTML5 '&' character to connect query params in GitHub API call. imathis#1031.
  Use the Github API repo sorting.
  Fixed issue with mobile nav choosing the last option by default. Fixes imathis#950.
  fixed issue imathis#949 using @alexkirmse's patch
  Update plugins/pygments_code.rb
  Async load of Facebook JS
  Update plugins/pygments_code.rb
  ...

Conflicts:
	Rakefile
	_config.yml
briansimmons pushed a commit to briansimmons/octopress that referenced this issue Aug 20, 2013
lehrblogger pushed a commit to lehrblogger/lehrblogger.com-old that referenced this issue Feb 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants