Skip to content

dcalixto/kemal-meta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kemal-Meta

A Crystal library for managing meta tags in Kemal web applications with support for internationalization, geolocation, and social media optimization.

Installation

Add this to your application's shard.yml:

dependencies:
  kemal-meta:
    github: dcalixto/kemal-meta

Then run:

shards install

Configuration

Configure the library with your application settings:

Kemal::Meta.configure do |config|
  config.site = "Meu Site"
  config.separator = " - "
  config.title_limit = 60
  config.auto_geo_location = true
  config.default_locale = "pt-BR"
  config.geo_api_key = "sua-chave-api"
  config.auto_locale_detection = true
  config.supported_locales = ["pt-BR", "en-US", "es-ES"]
end

Usage

Basic Usage in Routes

get "/produto/:id" do |env|
  # Automatic geolocation detection
  geo = Kemal::Meta::GeoLocation.from_context(env)

  # Location-based configuration
  locale = detect_locale(geo.country, env.params.query["lang"]?)

  Kemal::Meta.set_meta_tags(env,
    title: I18n.t("product.title", locale: locale),
    description: I18n.t("product.description", locale: locale),
    keywords: ["produto", "loja", "brasil"],
    canonical: "https://example.com/produto/123",
    alternate: {
      "pt-BR" => "https://example.com/br/produto/123",
      "en-US" => "https://example.com/us/product/123",
      "es-ES" => "https://example.com/es/produto/123"
    },
    geo_location: geo,
    og: {
      title: I18n.t("product.og_title", locale: locale),
      type: "product",
      image: "https://example.com/produto-123.jpg",
      locale: locale
    }
  )

  render "views/produto.ecr"
end

Rendering Meta Tags

In your layout template:

<head>
  <%= Kemal::Meta.display_meta_tags(env) %>
</head>

Advanced Features

Schema.org Support

Add structured data to your pages:

schema: {
  "@type" => "Product",
  "name" => "Nome do Produto",
  "description" => "Descrição",
  "image" => "url-da-imagem",
  "brand" => "Marca"
}

Auto-detection of Language

Enable automatic language detection:

config.auto_locale_detection = true
config.locale_detection_sources = [:header, :geo, :url, :cookie]

Meta Tags Cache

Enable caching for better performance:

config.cache_enabled = true
config.cache_ttl = 3600 # 1 hour

Features

This library offers:

✅ Complete geolocation support
✅ Multi-regional functionality
✅ Clean and intuitive API
✅ Extensibility for future features

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Crystal library for managing meta tags in Kemal web applications with support for internationalization, geolocation, and social media optimization.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors