{"id":14969839,"url":"https://github.com/hardpixel/active-seo","last_synced_at":"2025-10-26T10:30:33.463Z","repository":{"id":62552900,"uuid":"107139991","full_name":"hardpixel/active-seo","owner":"hardpixel","description":"Add SEO meta to ActiveRecord models.","archived":false,"fork":false,"pushed_at":"2022-05-28T08:03:27.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T18:05:23.998Z","etag":null,"topics":["activerecord","gem","ruby-on-rails","seo"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hardpixel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-16T14:36:24.000Z","updated_at":"2022-05-28T08:03:28.000Z","dependencies_parsed_at":"2022-11-03T04:15:33.087Z","dependency_job_id":null,"html_url":"https://github.com/hardpixel/active-seo","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Factive-seo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Factive-seo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Factive-seo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardpixel%2Factive-seo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardpixel","download_url":"https://codeload.github.com/hardpixel/active-seo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238310130,"owners_count":19450798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","gem","ruby-on-rails","seo"],"created_at":"2024-09-24T13:42:28.674Z","updated_at":"2025-10-26T10:30:33.116Z","avatar_url":"https://github.com/hardpixel.png","language":"Ruby","readme":"# ActiveSeo\n\nOptimize ActiveRecord models with support for SEO, Twitter and Open Graph meta.\n\n[![Gem Version](https://badge.fury.io/rb/active_seo.svg)](https://badge.fury.io/rb/active_seo)\n[![Build Status](https://travis-ci.org/hardpixel/active-seo.svg?branch=master)](https://travis-ci.org/hardpixel/active-seo)\n[![Maintainability](https://api.codeclimate.com/v1/badges/4447eb1a073a93ace5b2/maintainability)](https://codeclimate.com/github/hardpixel/active-seo/maintainability)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_seo'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install active_seo\n\nThen run the generator that will create a migration for the SeoMetum model and an initializer:\n\n    $ rails g active_seo:install\n\nAnd finally run the migrations:\n\n    $ rails db:migrate\n\n## Usage\n\nTo add SEO meta support to an ActiveRecord model include the `ActiveSeo::Meta` Concern or use the `has_seo` class method:\n\n```ruby\nclass Page \u003c ApplicationRecord\n  # Using concern\n  include ActiveSeo::Meta\n\n  # Or using `has_seo` class method\n  has_seo\nend\n```\n\nSeoMetum's attributes will be automatically delegated by your model with the `seo` prefix and you can use them in forms:\n\n```erb\n\u003c%= form_for @page do |f| %\u003e\n  \u003c%= f.text_field :seo_title %\u003e\n  \u003c%= f.text_area  :seo_description %\u003e\n  \u003c%= f.text_area  :seo_keywords %\u003e\n  \u003c%= f.check_box  :seo_noindex %\u003e\n  \u003c%= f.check_box  :seo_nofollow %\u003e\n\u003c% end %\u003e\n```\n\nTo get a SEO attribute:\n\n```ruby\n@page.seo_title\n```\n\nTo get all SEO attributes:\n\n```ruby\n@page.seo_meta\n```\n\n## Configuration\n\nThe install generator will create an initializer:\n\n```ruby\nActiveSeo.setup do |config|\n  # config.title_limit          = 70\n  # config.description_limit    = 160\n  # config.keywords_limit       = 255\n  # config.keywords_separator   = ', '\n  # config.title_fallback       = true\n  # config.description_fallback = true\n  # config.generate_keywords    = true\n\n  # config.opengraph_setup do |og|\n  #   og.type      = 'website'\n  #   og.site_name = 'Site Name'\n  # end\n\n  # config.twitter_setup do |tw|\n  #   tw.card    = 'summary'\n  #   tw.site    = '@site'\n  #   tw.creator = '@author'\n  # end\nend\n```\n\nYou can set global defaults for attribute validations, automatic meta generation, OpenGraph and Twitter meta.\n\nSettings `title_fallback` and `description_fallback` can be a `Symbol` or an `Array` of symbols that reference a model attribute/method which will be used to autogenerate the title and description attributes. When using an `Array` the first attribute that returns a value will be used.\n\nThis behavior can also be configured on a model level:\n\n```ruby\nclass Page \u003c ApplicationRecord\n  # Using concern\n  include ActiveSeo::Meta\n\n  # With `seo_setup` method\n  seo_setup title_fallback: :name, description_fallback: [:content, :excerpt]\n\n  # Or using `has_seo` class method\n  has_seo title_fallback: :name, description_fallback: [:content, :excerpt]\nend\n```\n\n## OpenGraph and Twitter\n\nIf you want to define non-global OpenGraph and Twitter configurations you can create a custom meta contextualizer. ActiveSeo will look for a class defined in the model:\n\n```ruby\nclass Page \u003c ApplicationRecord\n  # Using concern\n  include ActiveSeo::Meta\n\n  # With `seo_contextualizer` method\n  seo_contextualizer 'CustomContextualizer'\n\n  # Or using `has_seo` class method\n  has_seo contextualizer: 'CustomContextualizer'\nend\n```\n\nOr for a class located in `app/contextualizers` with a name like `ModelContextualizer`.\n\n```ruby\nclass PageContextualizer \u003c ActiveSeo::Contextualizer\n  # Using a proc\n  og_meta :image, -\u003e obj { { _: obj.image, width: obj.image_width } }\n  # Using a method defined in the contextualizer\n  og_meta :video, :video_url\n\n  # Using an attribute from the record\n  twitter_meta :description, :seo_description\n  # Using a string\n  twitter_meta :card, 'app'\n\n  # Use `record` to get record attributes\n  def video_url\n    record.video_url\n  end\nend\n```\n\nInside the contextualizer you can define values using a `Proc` which gives you access to the record, a `Symbol` which will look for an attibute or method first inside the contextualizer and then in the model, or a `String` for a static value.\n\n## Printing SEO meta\n\nThis gem does not provide helpers to output the meta, but was designed to provide a hash containing all the attributes the way the [Meta Tags](https://github.com/kpumuk/meta-tags) gem requires them.\n\nSo, if you're using Meta Tags you can do the following:\n\n```erb\n\u003c%= display_meta_tags(@page.seo_meta) %\u003e\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/active-seo.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Factive-seo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardpixel%2Factive-seo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardpixel%2Factive-seo/lists"}