{"id":13880061,"url":"https://github.com/fnando/page_meta","last_synced_at":"2025-04-13T05:13:07.411Z","repository":{"id":1635781,"uuid":"43689826","full_name":"fnando/page_meta","owner":"fnando","description":"Easily define \u003cmeta\u003e and \u003clink\u003e tags. I18n support for descriptions, keywords and titles.","archived":false,"fork":false,"pushed_at":"2024-12-29T18:00:37.000Z","size":82,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T05:13:02.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fnando"],"custom":["https://www.paypal.me/nandovieira/🍕"]}},"created_at":"2015-10-05T14:36:20.000Z","updated_at":"2024-12-29T18:00:37.000Z","dependencies_parsed_at":"2024-10-20T12:39:58.858Z","dependency_job_id":null,"html_url":"https://github.com/fnando/page_meta","commit_stats":{"total_commits":42,"total_committers":4,"mean_commits":10.5,"dds":0.5,"last_synced_commit":"a9d0114c19f177a21ea9fa0f5a6dfa6c1c8bf4ac"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpage_meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpage_meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpage_meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpage_meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/page_meta/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665746,"owners_count":21142123,"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":[],"created_at":"2024-08-06T08:02:45.588Z","updated_at":"2025-04-13T05:13:07.388Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://www.paypal.me/nandovieira/🍕"],"categories":["Ruby"],"sub_categories":[],"readme":"# page_meta\n\n[![Tests](https://github.com/fnando/page_meta/workflows/ruby-tests/badge.svg)](https://github.com/fnando/page_meta)\n[![Gem](https://img.shields.io/gem/v/page_meta.svg)](https://rubygems.org/gems/page_meta)\n[![Gem](https://img.shields.io/gem/dt/page_meta.svg)](https://rubygems.org/gems/page_meta)\n\nEasily define `\u003cmeta\u003e` and `\u003clink\u003e` tags. I18n support for descriptions,\nkeywords and titles.\n\n## Installation\n\n```bash\ngem install page_meta\n```\n\nOr add the following line to your project's Gemfile:\n\n```ruby\ngem \"page_meta\"\n```\n\n## Usage\n\nYour controller and views have an object called `page_meta`. You can use it to\ndefine meta tags and links. By default, it will include the encoding, language\nand viewport meta tags.\n\n```html\n\u003cmeta charset=\"utf-8\" /\u003e\n\u003cmeta name=\"language\" content=\"en\" /\u003e\n\u003cmeta itemprop=\"language\" content=\"en\" /\u003e\n\u003cmeta name=\"viewport\" content=\"width=device-width,initial-scale=1\" /\u003e\n```\n\nYou can use I18n to define titles, descriptions and keywords. These values will\nbe inferred from the controller and action names. For an action\n`SiteController#index` you'll need the following translation scope:\n\n```yaml\nen:\n  page_meta:\n    title_base: \"%{value} • MyApp\"\n\n    site:\n      index:\n        title: \"Welcome to MyApp\"\n```\n\nPreviously, you could also use the `page_meta.{titles,description,keywords}`\nscopes, but this is now deprecated in favor of the above.\n\n```yaml\n---\nen:\n  page_meta:\n    titles:\n      base: \"%{value} • MyApp\"\n      site:\n        index: \"Welcome to MyApp\"\n```\n\nThe title without the `base` context can be accessed through\n`page_meta.title.simple`.\n\n```erb\n\u003c%= page_meta.title %\u003e          // Welcome to MyApp • MyApp\n\u003c%= page_meta.title.simple %\u003e   // Welcome to MyApp\n```\n\nSometimes you need to render some dynamic value. In this case, you can use the\nI18n placeholders.\n\n```yaml\n---\nen:\n  page_meta:\n    title_base: \"%{title} • MyCompany\"\n\n    workshops:\n      show:\n        title: \"%{name}\"\n```\n\nYou can then set dynamic values using the `PageMeta::Base#[]=`.\n\n```ruby\nclass WorkshopsController \u003c ApplicationController\n  def show\n    @workshop = Workshop.find_by_permalink!(params[:permalink])\n    page_meta[:name] = @workshop.name\n  end\nend\n```\n\nSome actions are aliased, so you don't have to duplicate the translations:\n\n- Action `create` points to `new`\n- Action `update` points to `edit`\n- Action `destroy` points to `remove`\n\nThe same concept is applied to descriptions and keywords.\n\n```yaml\n---\nen:\n  page_meta:\n    base_title: \"%{value} • MyApp\"\n    site:\n      show:\n        title: \"Show\"\n        description: MyApp is the best way of doing something.\n        keywords: \"myapp, thing, other thing\"\n```\n\n### Defining base url\n\nYou can define the base url.\n\n```ruby\npage_meta.base \"https://example.com/\"\n```\n\n### Defining meta tags\n\nTo define other meta tags, you have to use `PageMeta::Base#tag` like the\nfollowing:\n\n```ruby\nclass Workshops Controller \u003c ApplicationController\n  def show\n    @workshop = Workshop.find_by_permalink(params[:permalink])\n    page_meta.tag :description, @workshop.description\n    page_meta.tag :keywords, @workshop.tags\n  end\nend\n```\n\n\u003e [!TIP]\n\u003e\n\u003e The meta tag's content can also be any object that responds to the method\n\u003e `call`. This way you can lazy evaluate the content.\n\nYou can define default meta/link tags in a `before_action`:\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  before_action :set_default_meta\n\n  private\n\n  def set_default_meta\n    page_meta.tag :dns_prefetch_control, \"http://example.com\"\n    page_meta.tag :robots, \"index, follow\"\n    page_meta.tag :copyright, \"Example Inc.\"\n  end\nend\n```\n\nFinally, you can define meta tags for Facebook and Twitter:\n\n```ruby\n# Meta tags for Facebook\npage_meta.tag :og, {\n  image: helpers.asset_url(\"fb.png\"),\n  image_type: \"image/png\",\n  image_width: 800,\n  image_height: 600,\n  description: @workshop.description,\n  title: @workshop.name,\n  url: workshop_url(@workshop)\n}\n\n# Meta tags for Twitter\npage_meta.tag :twitter, {\n  card: \"summary_large_image\",\n  title: @workshop.name,\n  description: @workshop.description,\n  site: \"@howto\",\n  creator: \"@fnando\",\n  image: helpers.asset_url(@workshop.cover_image)\n}\n```\n\n### Defining link tags\n\nTo define link tags, you have to use `PageMeta::Base#link` like the following:\n\n```ruby\npage_meta.link :canonical, href: article_url(article)\npage_meta.link :last, href: article_url(articles.last)\npage_meta.link :first, href: article_url(articles.first)\n```\n\nThe hash can be any of the link tag's attributes. The following example defines\nthe Safari 9 Pinned Tab icon:\n\n```ruby\npage_meta.link :mask_icon, color: \"#4078c0\", href: helpers.asset_url(\"mask_icon.svg\")\n```\n\n### Rendering the elements\n\nTo render all tags, just do something like this:\n\n```erb\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003c%= page_meta %\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c%= yield %\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n#### Rendering titles and descriptions\n\nYou may want to render title and description on your page. In this case, you may\nuse something like this:\n\n```erb\n\u003ch1\u003e\u003c%= page_meta.title.simple %\u003e\u003c/h1\u003e\n\u003cp\u003e\u003c%= page_meta.description.simple %\u003e\u003c/p\u003e\n```\n\nIf your description contains HTML, you can use\n`page_meta.description(html: true).simple` instead. It will use Rails'\n`html_safe` helpers to safely retrieve the translation, just like regular Rails\nwould do.\n[Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations)\nfor more info.\n\n### Removing meta tags\n\nYou can use `PageMeta::Base#delete` to remove meta tags. All matching tags will\nbe removed.\n\n```ruby\npage_meta.delete(:description)\n```\n\n## Maintainer\n\n- [Nando Vieira](https://github.com/fnando)\n\n## Contributors\n\n- https://github.com/fnando/page_meta/contributors\n\n## Contributing\n\nFor more details about how to contribute, please read\nhttps://github.com/fnando/page_meta/blob/main/CONTRIBUTING.md.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be\nfound at https://github.com/fnando/page_meta/blob/main/LICENSE.md.\n\n## Code of Conduct\n\nEveryone interacting in the page_meta project's codebases, issue trackers, chat\nrooms and mailing lists is expected to follow the\n[code of conduct](https://github.com/fnando/page_meta/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpage_meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fpage_meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpage_meta/lists"}