archtechx / laravel-seo Goto Github PK
View Code? Open in Web Editor NEWSEO package for Laravel
Home Page: https://archte.ch/blog/introducing-laravel-seo
License: MIT License
SEO package for Laravel
Home Page: https://archte.ch/blog/introducing-laravel-seo
License: MIT License
og:url for a complete Open Graph schema, and likely canonical URL as well
We need dev-master from PHPStan and larastan/larastan#946
diff --git a/composer.json b/composer.json
index 6c0e997..3e62416 100644
--- a/composer.json
+++ b/composer.json
@@ -29,9 +29,10 @@
},
"require-dev": {
"orchestra/testbench": "^6.9",
- "nunomaduro/larastan": "^0.6.10",
+ "nunomaduro/larastan": "dev-master",
"pestphp/pest": "^1.2",
- "pestphp/pest-plugin-laravel": "^1.0"
+ "pestphp/pest-plugin-laravel": "^1.0",
+ "phpstan/phpstan": "dev-master as 0.12.90"
},
"extra": {
"laravel": {
diff --git a/phpstan.neon b/phpstan.neon
index f586106..a04c137 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -10,11 +10,9 @@ parameters:
universalObjectCratesClasses:
- Illuminate\Routing\Route
- ArchTech\SEO\SEOManager
+ checkMissingIterableValueType: false
ignoreErrors:
- - '#SEOManager\|array\|string\|null#'
- - '#string\|false given#'
- - '#flipp\(\) should return#'
- - '#\_\_set\(\) has no return typehint specified#'
-
- checkMissingIterableValueType: false
+ # Waiting for https://github.com/phpstan/phpstan/issues/5706
+ - '#^Cannot call method (flipp|get|set)\(\) on ArchTech\\SEO\\SEOManager\|array\|string\|null\.$#'
+ - '#^Method ArchTech\\SEO\\SEOManager::flipp\(\) should return static\(ArchTech\\SEO\\SEOManager\)\|string but returns array\|string\|null\.$#'
diff --git a/src/SEOManager.php b/src/SEOManager.php
index d036034..d68a98f 100644
--- a/src/SEOManager.php
+++ b/src/SEOManager.php
@@ -82,11 +82,14 @@ class SEOManager
: value($this->values[$key]);
}
- /** Set one or more values. */
+ /**
+ * Set one or more values.
+ *
+ * @param string|array<string, string> $key
+ */
public function set(string|array $key, string|Closure|null $value = null): string|array|null
{
if (is_array($key)) {
- /** @var array<string, string> $key */
foreach ($key as $k => $v) {
$this->set($k, $v);
}
@@ -166,7 +169,7 @@ class SEOManager
];
}
- $query = base64_encode(json_encode($data));
+ $query = base64_encode((string)json_encode($data));
/** @var string $template */
$template = $this->meta("flipp.templates.$alias");
@@ -273,7 +276,11 @@ class SEOManager
return $this->get(Str::snake($key, '.'));
}
- /** Handle magic set. */
+ /**
+ * Handle magic set.
+ *
+ * @phpstan-return string|array|null
+ */
public function __set(string $key, string $value)
{
return $this->set(Str::snake($key, '.'), $value);
diff --git a/src/helpers.php b/src/helpers.php
index 658df88..9a8e8f1 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -5,14 +5,21 @@ declare(strict_types=1);
use ArchTech\SEO\SEOManager;
if (! function_exists('seo')) {
+ /**
+ * @template T of string|array
+ * @param T|null $key
+ * @return SEOManager|string|array|null
+ */
function seo(string|array $key = null): SEOManager|string|array|null
{
- if (! $key) {
+ if ($key === null) {
return app('seo');
- } elseif (is_array($key)) {
+ }
+
+ if (is_array($key)) {
return app('seo')->set($key);
- } else {
- return app('seo')->get($key);
}
+
+ return app('seo')->get($key);
}
}
It is 100% up to you! This is an inspiration, not code.
Is it possible to add an option to change the og:type ?
So things like 'website', 'article'.
seo()->type('article')
But always keeping 'website' as the default fall back setting.
If i will edit everything myself why i would use a package for that????
this is all the tags you need, i guess there is no one can't fill them the correct way:
<meta name="description" content=""/>
<meta name="author" content="" />
<meta name="robots" content="index, follow" />
<meta property="og:title" content="" />
<meta property="og:description" content="" />
<meta property="og:type" content="og:product" />
<meta property="og:url" content="" />
<meta property="og:image" content="" />
<meta property="product:plural_title" content="" />
<meta property="product:price:amount" content=""/>
<meta property="product:price:currency" content="USD"/>
for more social tags : ogp.me
hi
Can I remove trail slash from meta
tags ?
I send my site to html validator and get next
Info: Trailing slash on void elements [has no effect](https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements#trailing-slashes-in-void-element-start-tags-do-not-mark-the-start-tags-as-self-closing) and [interacts badly with unquoted attribute values](https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements#trailing-slashes-directly-preceded-by-unquoted-attribute-values).
From line 9, column 9; to line 9, column 100
<meta property="og:title" content="site title" />
Using this package with Laravel Octane causes any values that aren't explicitly set on the current page to be filled with data from other pages that were populated on prior requests.
I believe the fix is to register the SEOManager as a scoped singleton in the SEOServiceProvider. Here's the relevant section of the docs:
Binding Scoped Singletons
The scoped method binds a class or interface into the container that should only be resolved one time within a given Laravel request / job lifecycle. While this method is similar to the singleton method, instances registered using the scoped method will be flushed whenever the Laravel application starts a new "lifecycle", such as when a Laravel Octane worker processes a new request or when a Laravel queue worker processes a new job
The @seo
blade tag can set e.g. the description like this @seo(['description' => 'foo'])
. But I didn't find any way to do the same for the social image? The following call (which I expected to work) resulted in an error:
ArchTech\SEO\SEOManager::set(): Argument #2 ($value) must be of type Closure|string|null, array given, called in /Users/tpetry/Documents/laravel-seo/src/SEOManager.php on line 95
@seo(['flipp' => ['blog', ['title' => 'Lorem Ipsum', 'description' => 'Lorem Ipsum, Lorem Ipsum']]])
```php
Is it not supported to set the social image with the `@seo` tag without returning any value or did I just miss the correct call?
Hey team,
How come when using the <x-seo::meta />
tag, it inputs the HTML all strange? It adds tabs randomly, adds new lines randomly, and joins some things together on the same line. Why not just input everything one line after eachother?
Controller Code:
seo()
->title('News & Updates - MySite')
->description('Find out the latest')
->site('MySite')
->twitter();
Actual HTML output:
<title>News & Updates - MySite</title>
<meta property="og:title" content="News & Updates - MySite" />
<meta property="og:description" content="Find out the latest" />
<meta name="description" content="Find out the latest" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="MySite">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="MySite"> <meta name="twitter:title" content="News & Updates - MySite"> <meta name="twitter:description" content="Find out the latest">
It would be awesome if this could be added, I know its not directly SEO but it touches with images etc.
It may appear (may be wrong) that the package is vulnerable to XSS as it does not properly sanitize the input. Example:
$description = 'Quick hotkey to save time instead of pressing "Share" -> "With timecode" -> "Copy" from UI';
$seo->title('Some name')
->description($description)
->twitter()
->twitterCreator('sample');
Completely breaks the description and seems to push the meta directly into the body
of the page. Potentially dangerous. Let me know if you need help reproducing it.
Hello! While resolving all ignored PHPStan errors I've bumped into methods like SEOManager::meta
. Or the seo
function.
Please consider using 1 method for 1 thing.
Get or set metadata.
The "S" in SOLID.
When using raw tags (with the keys), it only adds additional HTML entries into the header, I know the concept behind it is to override as we spoke about previously. I personally use this for favicons, where I change it for viewing pages with user uploaded avatars.
When diving further, your tests (as found https://github.com/archtechx/laravel-seo/blob/master/tests/Pest/ManagerTest.php#L102) seem to reference the wrong value. Shouldn't this be checking for the newer entry, rather than the original abc?
Is it possible to use different content for the title and og:title?
So for example.
<title>Article Title | Category | Website</title>
<meta property="og:title" content="Article Title"/>
I have tried using the following but the 'og:title' only appears twice.
seo()->title('Article Title | Category | Website');
seo()->tag('og:title', 'Article Title.');
...
<title>Article Title | Category | Website</title>
<meta property="og:title" content="Article Title | Category | Website"/>
<meta property="og:title" content="Article Title"/>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.