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

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

Projects

None yet

5 participants

@floydpink
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

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

@floydpink
Contributor

@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

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
Contributor

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

@floydpink
Contributor

@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

site.category_dir is definitely cleaner, thanks!

@swestcott

Most recent patch works for me too, thanks.

@parkr
Collaborator
parkr commented Feb 12, 2013

@floydpink This included in #953?

@floydpink
Contributor

@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

@floydpink
Contributor

Thank you, @parkr

@floydpink floydpink closed this Feb 13, 2013
@jhwist jhwist added a commit to jhwist/octopress that referenced this issue Feb 25, 2013
@floydpink @jhwist floydpink + jhwist fixed issue #949 using @alexkirmse's patch fa6209f
@paxswill paxswill added a commit to paxswill/StupidRobots that referenced this issue Mar 29, 2013
@paxswill paxswill Merge branch 'master' of git://github.com/imathis/octopress
* '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 #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. #438
  Using data.code.to_i like a true Rubyist in plugins/gist_code.rb. Heh. #438
  Bump sinatra to 1.3.5
  It's 2013. Hi, MIT License.
  Use HTML5 '&' character to connect query params in GitHub API call. #1031.
  Use the Github API repo sorting.
  Fixed issue with mobile nav choosing the last option by default. Fixes #950.
  fixed issue #949 using @alexkirmse's patch
  Update plugins/pygments_code.rb
  Async load of Facebook JS
  Update plugins/pygments_code.rb
  ...

Conflicts:
	Rakefile
	_config.yml
21d22bb
@briansimmons briansimmons pushed a commit to briansimmons/octopress that referenced this issue Aug 20, 2013
@floydpink @parkr floydpink + parkr fixed issue #949 using @alexkirmse's patch 24d581d
@lehrblogger lehrblogger pushed a commit to lehrblogger/lehrblogger.com-old that referenced this issue Feb 24, 2014
@floydpink @parkr floydpink + parkr fixed issue #949 using @alexkirmse's patch 5d1ac09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment