Git Product home page Git Product logo

canonical-rails's People

Contributors

abrom avatar banyan avatar benmorganio avatar cczona avatar chapolito avatar coreyward avatar cyril-sf avatar damianlegawiec avatar dan-jensen avatar duderamos avatar edouard avatar eric-guo avatar geeknees avatar islamazab avatar jhawthorn avatar joeadcock avatar johnriv avatar jormon avatar joshrpowell avatar jumph4x avatar kennyadsl avatar krzysiek1507 avatar mfrwdesign avatar peterberkenbosch avatar radar avatar reiz avatar richardvenneman avatar terryyin avatar thinkswan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

canonical-rails's Issues

Trailing slash issue.

You cannot configure if you want to add a trailing slash or have it removed.

Currently I have my rails setup to not use trailing slash

application.rb

config.action_controller.default_url_options = { trailing_slash: false }

However the canonical URL has a trailing slash and this URL is redirect to no trailing slash.

Resource Aliasing

I have an events resource, and created an alias route for 'e'. How can I make the canonical route the full resource name, events?

Rails.application.routes.draw do
  resources :events  
  resources :e, controller: 'events'
end

Also, I'm not sure I understand the config.collection_actions = []. What options are available to go into that array?

Support for rails 6.1

Rails 6.1 has now been released. Do you know when this gem will support it? Thanks!

any way to make Rails + this gem create hyphenated urls, especially for static pages such as /blue_socks to become /blue-socks

Does this gem (or gem in combination with some other technique) facilitate replacing Rails' hardwired "underscore" paths and urls with the more SEO-friendly "hyphenated" paths and urls.

Specifically is there any way given a controller method def blue_socks .... to have the auto-magic rails routes and paths and urls be in the form blue-socks (which Google will understand as "blue socks" instead of blue_socks (which to Google is just a non-word)?

Having installed this gem to play with it, it's nice on one hand to have an easy way to add a canonical to the layout, but the real SEO issue for Rails apps, it seems to me, is undoing Rails' (tragically IMO) baked-in "underscore" assumption for all routes, paths, urls.

Since Google explicitly states hyphenated words is better, surely there is some way to accomplish that with Rails?

Config option to force protocol

What are your thoughts on including a config option to force the protocol for the canonical URL href? For example, a site could have the same content hosted on http & https and wants to always have https be the canonical URL. With the current setup, the protocol is based on the incoming request protocol.

If you agree that is useful, I can work on a pull request.

No Route matches for canonical

I have been using canonical for quite some time, but it just stopped working after migrating to devise 4.2.0. This is preparation for rails 5

It only happens in the the rspec.

<link href="http://mysiteno route matches {:action=>"application", :controller=>"layouts"}" rel="canonical" />

The code i have debugged is:

   11:     def path_without_html_extension
=> 12:       request.path.sub(/\.html$/, '')
   13:     end

and here the request.path returns

"No route matches {:action=>\"application\", :controller=>\"layouts\"}"

Not sure where to go from here.

Multi-language friendly?

Hey,
i'm not a SEO expert but i think this gem is not multi-language ready, right?
I mean, in a site with pages and url in different languages www.example.com/page should not be the canonical of www.example.com/it/page.
For Google this would mean to index only the base language version, and that's not what you want in this context.

Failure in Spree's frontend on Ruby 2.0

Hello! By the issue title you're probably thinking that you should close this issue. Please don't!

I get this error when I run Spree's frontend build on Ruby 2.0.0:

  1) Visiting Products should be able to display products priced under 10 dollars
     Failure/Error: within(:css, '#sidebar_products_search') { click_button "Search" }
     ActionView::Template::Error:
       undefined method `encoding' for {"price_range_any"=>["Under $10.00"]}:ActiveSupport::HashWithIndifferentAccess
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/cgi/util.rb:7:in `escape'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:36:in `block in whitelisted_query_string'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:36:in `each'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:36:in `map'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:36:in `whitelisted_query_string'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:21:in `canonical_href'
     # /Users/ryanbigg/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/canonical-rails-0.0.6/app/helpers/canonical_rails/tag_helper.rb:25:in `canonical_tag'
     # ./app/views/spree/shared/_head.html.erb:7:in `_1a267b5e5f91d9723f931f318739dddf'

I think it also happens on Ruby 1.9.

I am not familiar with your library, but I think it is to blame since it is at the root of this issue.

add_helpers initializer prevents Rails 6.0.0rc1 app initialization

Gem version: 0.2.5
Ruby version: 2.6.3
Rails version: 6.0.0rc1

While attempting to upgrade an application from Rails 5.2 to 6.0.0rc1, I ran into this issue related to new autoload logic and an initializer in the canonical-rails engine.rb file:

/Users/mhwang/.rvm/gems/ruby-2.6.3/gems/railties-6.0.0.rc1/lib/rails/initializable.rb:32:in `instance_exec': DEPRECATION WARNING: Initialization autoloaded the constant CanonicalRails::TagHelper. (ActiveSupport::DeprecationException)

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload CanonicalRails::TagHelper, for example,
the expected changes won't be reflected in that stale Module object.

This autoloaded constant has been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.
 (called from <top (required)> at /Users/mhwang/fuzzy/code/marketing/config/environment.rb:5)

The line of code that is the issue is in engine.rb:

module CanonicalRails
  class Engine < ::Rails::Engine

    initializer 'canonical_rails.add_helpers' do |app|
      ActionView::Base.send :include, CanonicalRails::TagHelper
    end

  end
end

If I remove the initializer, the application loads fine. Without the initializer, the canonical_tag helper still works on each webpage.

This change is also backwards compatible to Rails 5.2. Is it worth considering removing this initializer for future compatibility if it still works without? Any suggestions would be appreciated!

Is there a way to support other subdomains?

I have a few subdomain site set up using the gem Apartment, they all have similar content so I intend to add "alternate" tag.

<link rel="canonical" href='https://hk.lvh.me/en/programs/enroll?course_code=AT212121321' />
<link rel="alternate" hreflang="en-sg" href='https://sg.lvh.me/en/programs/enroll?course_code=AT212121321' />
<link rel="alternate" hreflang="en-tw" href='https://tw.lvh.me/en/programs/enroll?course_code=AT212121321' />
<link rel="alternate" hreflang="zh-tw" href='https://tw.lvh.me/zh/programs/enroll?course_code=AT212121321' />

Is there a way to support adding some whitelisted subdomains? Thanks :)

Test suite fails with sprockets 4

In #70 the explicit dependency on "sprockets", '~> 3.0' was relaxed, so the gem can be used with applications that are using sprockets 4.

However, the dummy application in the test suite is not compatible with sprockets 4. The following error message is generated:

An error occurred while loading ./spec/helpers/canonical_rails/tag_helper_spec.rb.
Failure/Error: Dummy::Application.initialize!

Sprockets::Railtie::ManifestNeededError:
  Expected to find a manifest file in `app/assets/config/manifest.js`
  But did not, please create this file and use it to link any assets that need
  to be rendered by your app:

  Example:
    //= link_tree ../images
    //= link_directory ../javascripts .js
    //= link_directory ../stylesheets .css
  and restart your server

  For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs

There's an obvious fix, which is to create the missing file. Creating an empty manifest.js appears to work fine, and the test suite then runs and (mostly, see #86) passes.

However, I can see that #80 proposes removing the dummy application entirely, so I'm not sure which approach you would prefer.

Test suite fails with rack 3

While running the test suite with sprockets 4 (and adding the missing manifest file, see #85), I found that there are two failures with rack 3.

Sprockets < 4.2.0 (September 5 2023) will run without error, since they have a constraint to rack 2, but newer versions of sprockets support rack 3.

The errors are:

1) CanonicalRails::TagHelper w/ custom config with parameters should escape allowed params properly
   Failure/Error: expect(helper.allowed_query_string).to eq '?page=5&keywords=%22here+be+dragons%22&search[super]=special'
   
     expected: "?page=5&keywords=%22here+be+dragons%22&search[super]=special"
          got: "?page=5&keywords=%22here+be+dragons%22&search%5Bsuper%5D=special"
   
     (compared using ==)
   # ./spec/helpers/canonical_rails/tag_helper_spec.rb:207:in `block (4 levels) in <top (required)>'

2) CanonicalRails::TagHelper w/ custom config with parameters should output allowed params using proper syntax (?key=value&key=value)
   Failure/Error: expect(helper.canonical_tag).to eq '<link href="http://www.mywebstore.com/our_resources/?page=5&keywords=%22here+be+dragons%22&search[super]=special" rel="canonical" />'
   
     expected: "<link href=\"http://www.mywebstore.com/our_resources/?page=5&keywords=%22here+be+dragons%22&search[super]=special\" rel=\"canonical\" />"
          got: "<link href=\"http://www.mywebstore.com/our_resources/?page=5&keywords=%22here+be+dragons%22&search%5Bsuper%5D=special\" rel=\"canonical\" />"
   
     (compared using ==)
   # ./spec/helpers/canonical_rails/tag_helper_spec.rb:211:in `block (4 levels) in <top (required)>'

I haven't investigated what the root cause of these failures are, but they can be avoided by adding s.add_dependency "rack", '< 3' to the gemspec.

Get CI working again?

I don't know what the history is here, but it seems that travis-ci is no longer working for this gem. There's no CI results shown beside any commits, and PRs don't appear to have any CI checks run against them either.

It would be great to get CI working again, and I was wondering if you wanted to move to Github Actions? Or would you prefer to resurrect Travis, or something else?

Exclude default language from canonical URL

My website supports multiple languages, for example:

https://www.example.com/mypage
https://www.example.com/en-US/mypage
https://www.example.com/fr-FR/mypage

https://www.example.com/mypage and https://www.example.com/en-US/mypage are actually the same page because en-US is my default language.
What would be the best option to remove /en-US from canonical URLs ? I can write a PR if necessary.

Missleading documenation

Hi !

Not a big deal, but I think current documentation is a bit misleading and could cause problems for some developers. Canonical tag should be always put in the HTTP header or in the head tag of the HTML document. Current README suggest putting canonical_tag "into the views" which I think should be changed to "head section of your layout file".

Putting canonical tag into the body is listed as mistake number 5 at http://googlewebmastercentral.blogspot.ie/2013/04/5-common-mistakes-with-relcanonical.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.