https://github.com/area17/laravel-auto-head-tags
Laravel auto head tags
https://github.com/area17/laravel-auto-head-tags
Last synced: 2 months ago
JSON representation
Laravel auto head tags
- Host: GitHub
- URL: https://github.com/area17/laravel-auto-head-tags
- Owner: area17
- License: mit
- Created: 2020-05-05T19:19:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-17T16:05:36.000Z (over 1 year ago)
- Last Synced: 2025-03-26T10:11:33.366Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 92.8 KB
- Stars: 46
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Laravel Auto Head Tags
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]## Description
This package aims to ease the creating of all HTML head tags: meta, links, SEO, Open Graph, Twitter and whatever else you need.
The package will grab all the info it needs from the data sent to Blade:
```php
return view('welcome', [
'seo' => [
'title' => 'Your page title','description' => 'The meta description for the page',
'urls' => [
'canonical' => 'https://site.com/the-article-slug'
],
],'twitter' => [
'handle' => '@opticalcortex'
],'image' => [
'url' => 'https://site.com/image.jpg'
]
]);
```To generate, out of the box, this set of tags for you:
```html
Your page title\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n```
[The list of tags is larger](https://github.com/area17/laravel-auto-head-tags/blob/master/config/laravel-auto-head-tags.yaml), but if you don't provide enough information to create those tags, they won't be created.
## Install
### Via Composer
```bash
composer require area17/laravel-auto-head-tags
```### Publish the config file
```bash
php artisan vendor:publish --provider="A17\LaravelAutoHeadTags\ServiceProvider"
```# Using
## Add to your blade template
Add the tag `@head` to your main template:
```html
@head...
...
```
This directive is also configurable, just publish the configuration and change the `blade.directive`.
## Configuring
All available tags are on the config file: `config/laravel-auto-head-tags.yaml`, and everything is configurable. This is an extract of the tags section:
```yaml
# TAGS
tags:
# META# HEAD
meta:
- charset: "{head.charset}|utf-8"
- name: viewport
content: "{head.viewport}|width=device-width, initial-scale=1.0, minimum-scale=1"
- name: author
content: "{head.author}"
- http-equiv: "X-UA-Compatible"
content: "{head.httpEquiv}|IE=Edge"
- name: mobile-web-app-capable
content: "{head.mobile-web-app-capable}|yes"
- name: apple-mobile-web-app-capable
content: "{head.apple-mobile-web-app-capable}|yes"
- name: apple-mobile-web-app-title
content: "{head.apple-mobile-web-app-title}|{og.title}|{$config.app.name}"
```You can define macros to access Blade data, using `{}`, and the package can resolve them using the "dot" notation for arrays:
```yaml
content: "{head.author}"
```You can define as many fallbacks you need for those macros:
```yaml
title: "{title}|{head.title}|{seo.title}|{og.title}|{$config.app.name}"
```And you can also access data from the Laravel config:
```yaml
content: "{$config.app.name}"
```If it's required to generate more than one URL for a single tag definition, there's `loop` concept:
```yaml
- rel: canonical
href: "{seo.urls.canonical}"
- rel: alternate
href: "{seo.urls.hreflang:value}"
hreflang: "{seo.urls.hreflang:key}"
```If `seo.urls.hreflang` is an array made of locales (`key`) and URLs (`value`), this configuration will generate these tags:
```html
```
## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Testing
```bash
$ composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [AREA 17](https://github.com/area17)
- [Antonio Ribeiro][link-author]
- [All Contributors][link-contributors]## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/area17/laravel-auto-head-tags.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://scrutinizer-ci.com/g/area17/laravel-auto-head-tags/badges/build.png?b=master&style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/area17/laravel-auto-head-tags.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/area17/laravel-auto-head-tags.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/area17/laravel-auto-head-tags.svg?style=flat-square[link-packagist]: https://packagist.org/packages/area17/laravel-auto-head-tags
[link-travis]: https://travis-ci.com/github/area17/laravel-auto-head-tags
[link-scrutinizer]: https://scrutinizer-ci.com/g/area17/laravel-auto-head-tags/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/area17/laravel-auto-head-tags
[link-downloads]: https://packagist.org/packages/area17/laravel-auto-head-tags
[link-author]: https://github.com/antonioribeiro
[link-contributors]: ../../contributors