Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added schema.org tags #733

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/Http/Controllers/Forum/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Coyote\Services\Forum\TreeBuilder\ListDecorator;
use Coyote\Topic;
use Illuminate\Http\Request;
use Spatie\SchemaOrg\Schema;

class TopicController extends BaseController
{
Expand Down Expand Up @@ -130,6 +131,18 @@ public function index(Request $request, $forum, $topic)

TopicResource::withoutWrapping();

$author = $topic->firstPost()->get()->first()->user->name;
$schema = Schema::discussionForumPosting()
->identifier($request->getUri())
->headline($topic->title)
->author(
Schema::person()
->name($author)
)->interactionStatistic(
Schema::interactionCounter()
->userInteractionCount($topic->replies)
);

return $this->view('forum.topic', compact('posts', 'forum', 'paginate', 'reasons'))->with([
'mlt' => $this->moreLikeThis($topic),
'model' => $topic, // we need eloquent model in twig to show information about locked/moved topic
Expand All @@ -139,7 +152,8 @@ public function index(Request $request, $forum, $topic)
'all_forums' => $allForums,
'user_forums' => $userForums,
'description' => excerpt(array_first($posts['data'])['text'], 100),
'flags' => $this->flags($forum)
'flags' => $this->flags($forum),
'schema' => $schema,
]);
}

Expand Down
20 changes: 19 additions & 1 deletion app/Services/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Coyote\Services;

use Illuminate\Contracts\Support\Arrayable;
use Spatie\SchemaOrg\Schema;

/**
* Prosta klasa sluzaca do budowania elementu obecnego na kazdej podstronie, czyli breadcrumb
Expand Down Expand Up @@ -48,7 +49,24 @@ public function push($name, $url = null)
*/
public function render()
{
return view('components/breadcrumb', ['breadcrumbs' => $this->breadcrumbs]);
return view(
'components/breadcrumb',
[
'breadcrumbs' => $this->breadcrumbs,
'schema' => Schema::breadcrumbList()
->itemListElement(array_map(
function ($breadcrumb, int $index) {
return Schema::listItem()
->position($index + 1)
->identifier($breadcrumb['url'])
->name($breadcrumb['name']);
},
$this->breadcrumbs,
array_keys($this->breadcrumbs),
)
),
]
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"rawr/t-regx": "^v0.17.0",
"rcrowe/twigbridge": "^0.12",
"sentry/sentry-laravel": "^2.3",
"spatie/schema-org": "^3.14",
"stripe/stripe-php": "^7.66",
"twig/extensions": "^1.5"
},
Expand Down
75 changes: 74 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions resources/views/components/breadcrumb.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
</ul>
</div>
</div>

{{ schema.toScript()|raw }}
14 changes: 14 additions & 0 deletions resources/views/components/schema.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% macro organization() %}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"logo": "https://www.4programmers.net/img/logo-mobile.png",
"email": "[email protected]",
"name": "4programmers.net",
"sameAs": [
"https://www.facebook.com/4programmers.net"
]
}
</script>
{% endmacro %}
2 changes: 1 addition & 1 deletion resources/views/forum/topic.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% import 'components.modals' as modals %}

{% block content %}
{{ schema.to_script|raw }}

{% if model.locked_at and model.locker.id %}
<p class="alert alert-warning">
Expand Down Expand Up @@ -36,7 +37,6 @@
</div>
{% endif %}
</div>

{% for post in posts.data %}
<div class="card card-post">
<div class="card-header d-none d-lg-block">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
{% block body %}
{% import 'components.forms' as forms %}
{% import 'components.widgets' as widgets %}
{% import 'components.schema' as schema %}

{{ schema.organization() }}

<header class="{{ auth_guest() or user('allow_sticky_header') ? ' fixed-top' }}">
<div class="navbar-border-top"></div>
Expand Down
Loading