Skip to content

Commit

Permalink
Revert "Add ld+json structs"
Browse files Browse the repository at this point in the history
This reverts commit 9607730.
  • Loading branch information
romanzipp committed Jul 9, 2024
1 parent 88ebaf6 commit 71dfe47
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 140 deletions.
39 changes: 19 additions & 20 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ See the [Schema.org integration docs](/schema-org.html) for more information.

## Cheat Sheet

| Code | Rendered HTML |
|---------------------------------------|--------------------------------------------------------------|
| **Shorthand Setters** | |
| `seo()->title('Laravel')` | `<title>Laravel</title>` |
| `seo()->description('Laravel')` | `<meta name="description" content="Laravel" />` |
| `seo()->meta('author', 'Roman Zipp')` | `<meta name="author" content="Roman Zipp" />` |
| `seo()->twitter('card', 'summary')` | `<meta name="twitter:card" content="summary" />` |
| `seo()->og('site_name', 'Laravel')` | `<meta name="og:site_name" content="Laravel" />` |
| `seo()->charset()` | `<meta charset="utf-8" />` |
| `seo()->viewport()` | `<meta name="viewport" content="width=device-width, ..." />` |
| `seo()->csrfToken()` | `<meta name="csrf-token" content="..." />` |
| `seo()->ldJson([...])` | `<script type="application/ld+json">...</scrit>` |
| **Adding Structs** | |
| `seo()->add(...)` | `<meta name="foo" />` |
| `seo()->addMany([...])` | `<meta name="foo" />` |
| `seo()->addIf(true, ...)` | `<meta name="foo" />` |
| **Various** | |
| `seo()->mix()` | |
| `seo()->hook()` | |
| `seo()->render()` | |
| Code | Rendered HTML |
|----|----|
| **Shorthand Setters** | |
| `seo()->title('Laravel')` | `<title>Laravel</title>` |
| `seo()->description('Laravel')` | `<meta name="description" content="Laravel" />` |
| `seo()->meta('author', 'Roman Zipp')` | `<meta name="author" content="Roman Zipp" />` |
| `seo()->twitter('card', 'summary')` | `<meta name="twitter:card" content="summary" />` |
| `seo()->og('site_name', 'Laravel')` | `<meta name="og:site_name" content="Laravel" />` |
| `seo()->charset()` | `<meta charset="utf-8" />` |
| `seo()->viewport()` | `<meta name="viewport" content="width=device-width, ..." />` |
| `seo()->csrfToken()` | `<meta name="csrf-token" content="..." />` |
| **Adding Structs** | |
| `seo()->add(...)` | `<meta name="foo" />` |
| `seo()->addMany([...])` | `<meta name="foo" />` |
| `seo()->addIf(true, ...)` | `<meta name="foo" />` |
| **Various** | |
| `seo()->mix()` | |
| `seo()->hook()` | |
| `seo()->render()` | |
33 changes: 0 additions & 33 deletions docs/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,39 +332,6 @@ seo()->add(

</details>

### JSON-LD

```php
seo()->ldJson(array $data, bool $pretty = false);
```

<details>
<summary>same as ...</summary>

```php
use romanzipp\Seo\Structs\LinkedData;

seo()->add(
LinkedData::make()
->data($data, $pretty = false)
);
```

</details>

<details>
<summary>renders to ...</summary>

```html
<script type="application/ld+json">
{
"@context": "https://schema.org/"
}
</script>
```

</details>

## Adding single structs

If you need to use more advanced elements which are not covered with shorthand setters, you can easily add single structs to your SEO instance the following way.
Expand Down
18 changes: 0 additions & 18 deletions src/Services/Traits/ShorthandSetterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Support\Arr;
use romanzipp\Seo\Services\SeoService;
use romanzipp\Seo\Structs\Link\Canonical;
use romanzipp\Seo\Structs\LinkedData;
use romanzipp\Seo\Structs\Meta;
use romanzipp\Seo\Structs\Meta\Charset;
use romanzipp\Seo\Structs\Meta\CsrfToken;
Expand Down Expand Up @@ -246,23 +245,6 @@ public function csrfToken(string $token = null): self
);
}

/**
* Add a JSON-LD script.
*
* @see https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data
*
* @param array<string, array|string> $structuredData
* @param bool $pretty
*
* @return $this
*/
public function ldJson(array $structuredData, bool $pretty = false): self
{
return $this->add(
LinkedData::make()->data($structuredData, $pretty)
);
}

abstract public function add(Struct $struct): SeoService;

abstract public function addIf(bool $boolean, Struct $struct): SeoService;
Expand Down
32 changes: 0 additions & 32 deletions src/Structs/LinkedData.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/RenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\HtmlString;
use romanzipp\Seo\Builders\StructBuilder;
use romanzipp\Seo\Structs\LinkedData;
use romanzipp\Seo\Structs\Meta;
use romanzipp\Seo\Structs\Title;

Expand Down Expand Up @@ -208,27 +207,4 @@ public function testTagSyntaxUnknown()

$this->assertEquals('<meta name="1" />', seo()->render()->toHtml());
}

public function testTagLinkedData()
{
seo()->add(
LinkedData::make()->data([
'@context' => 'https://schema.org/',
'@type' => 'Recipe',
'name' => 'Party Coffee Cake',
'author' => [
'@type' => 'Person',
'name' => 'Mary Stone',
],
'datePublished' => '2018-03-10',
'description' => 'This coffee cake is awesome and perfect for parties.',
'prepTime' => 'PT20M',
])
);

$this->assertEquals(
'<script type="application/ld+json">{"@context":"https://schema.org/","@type":"Recipe","name":"Party Coffee Cake","author":{"@type":"Person","name":"Mary Stone"},"datePublished":"2018-03-10","description":"This coffee cake is awesome and perfect for parties.","prepTime":"PT20M"}</script>',
seo()->render()->toHtml()
);
}
}
12 changes: 0 additions & 12 deletions tests/ShorthandSettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace romanzipp\Seo\Test;

use romanzipp\Seo\Structs\Link\Canonical;
use romanzipp\Seo\Structs\LinkedData;
use romanzipp\Seo\Structs\Meta;
use romanzipp\Seo\Structs\Meta\Charset;
use romanzipp\Seo\Structs\Meta\OpenGraph;
Expand Down Expand Up @@ -152,15 +151,4 @@ public function testCanonicalSetter()

$this->assertInstanceOf(Canonical::class, seo()->getStructs()[0]);
}

public function testLinkedDataSetter()
{
seo()->ldJson(['@context' => 'https://schema.org/']);

$contents = seo()->render()->toArray();

$this->assertCount(1, $contents);

$this->assertInstanceOf(LinkedData::class, seo()->getStructs()[0]);
}
}
1 change: 0 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static function assertMatchesRegularExpressionCustom(string $pattern, str
// If parent has method assertMatchesRegularExpression, call it
if (method_exists(BaseTestCase::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);

return;
}

Expand Down

0 comments on commit 71dfe47

Please sign in to comment.