A Crystal library for managing meta tags in Kemal web applications with support for internationalization, geolocation, and social media optimization.
Add this to your application's shard.yml:
dependencies:
kemal-meta:
github: dcalixto/kemal-metaThen run:
shards installConfigure 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"]
endget "/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"
endIn your layout template:
<head>
<%= Kemal::Meta.display_meta_tags(env) %>
</head>Add structured data to your pages:
schema: {
"@type" => "Product",
"name" => "Nome do Produto",
"description" => "Descrição",
"image" => "url-da-imagem",
"brand" => "Marca"
}Enable automatic language detection:
config.auto_locale_detection = true
config.locale_detection_sources = [:header, :geo, :url, :cookie]Enable caching for better performance:
config.cache_enabled = true
config.cache_ttl = 3600 # 1 hourThis library offers:
✅ Complete geolocation support
✅ Multi-regional functionality
✅ Clean and intuitive API
✅ Extensibility for future features
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.