Skip to content

Commit dfe5173

Browse files
authored
Merge pull request #25 from lucky-media/v2.5
🚀 v2.5
2 parents 6b6be09 + a874e66 commit dfe5173

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

app/Tags/LuckySeo.php

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
namespace App\Tags;
4+
5+
use Statamic\Tags\Tags;
6+
7+
class LuckySeo extends Tags
8+
{
9+
/**
10+
* The {{ lucky_seo:title }} tag.
11+
*
12+
* @return string|array
13+
*/
14+
public function title()
15+
{
16+
$title = $this->context->get('title');
17+
$title_config = $this->context->raw('seo_title');
18+
$prepend = $this->context->get('seo:prepend_on_title');
19+
$append = $this->context->get('seo:append_on_title');
20+
21+
22+
if ($title_config === 'custom') {
23+
$title = $this->context->get('seo_custom_meta_title');
24+
}
25+
26+
if ($append) {
27+
return "$title - $append";
28+
}
29+
30+
if ($prepend) {
31+
return "$prepend - $title";
32+
}
33+
34+
return $title;
35+
}
36+
37+
/**
38+
* The {{ lucky_seo:description }} tag.
39+
*
40+
* @return string|array
41+
*/
42+
public function description()
43+
{
44+
$desc_config = $this->context->raw('seo_meta_description');
45+
46+
if ($desc_config === 'general') {
47+
return $this->context->get('seo:meta_description');;
48+
}
49+
50+
if ($desc_config === 'custom') {
51+
return $this->context->get('seo_custom_meta_description');
52+
}
53+
54+
return null;
55+
}
56+
57+
/**
58+
* The {{ lucky_seo:canonical }} tag.
59+
*
60+
* @return string|array
61+
*/
62+
public function canonical()
63+
{
64+
$canon_config = $this->context->raw('seo_canonical');
65+
66+
if ($canon_config === 'url') {
67+
return $this->context->get('seo_canonical_url');
68+
}
69+
70+
if ($canon_config === 'entry') {
71+
return $this->context->get('seo_canonical_custom_entry');
72+
}
73+
74+
return $this->context->get('permalink');
75+
}
76+
77+
/**
78+
* The {{ lucky_seo:og_title }} tag.
79+
*
80+
* @return string|array
81+
*/
82+
public function ogTitle()
83+
{
84+
$title_config = $this->context->raw('seo_og_title');
85+
86+
if ($title_config === 'custom') {
87+
return $this->context->get('seo_custom_og_title');
88+
}
89+
90+
return $this->title();
91+
}
92+
93+
/**
94+
* The {{ lucky_seo:og_description }} tag.
95+
*
96+
* @return string|array
97+
*/
98+
public function ogDescription()
99+
{
100+
$desc_config = $this->context->raw('seo_og_description');
101+
102+
if ($desc_config === 'meta') {
103+
return $this->description();
104+
}
105+
106+
107+
if ($desc_config === 'general') {
108+
return $this->context->get('seo:og_description');
109+
}
110+
111+
if ($desc_config === 'custom') {
112+
return $this->context->get('seo_custom_og_desc');
113+
}
114+
115+
return null;
116+
}
117+
118+
/**
119+
* The {{ lucky_seo:tw_title }} tag.
120+
*
121+
* @return string|array
122+
*/
123+
public function twTitle()
124+
{
125+
$title_config = $this->context->raw('seo_tw_title');
126+
127+
if ($title_config === 'custom') {
128+
return $this->context->get('seo_custom_tw_title');
129+
}
130+
131+
return $this->title();
132+
}
133+
134+
/**
135+
* The {{ lucky_seo:tw_description }} tag.
136+
*
137+
* @return string|array
138+
*/
139+
public function twDescription()
140+
{
141+
$desc_config = $this->context->raw('seo_og_description');
142+
143+
if ($desc_config === 'meta') {
144+
return $this->description();
145+
}
146+
147+
148+
if ($desc_config === 'general') {
149+
return $this->context->get('seo:og_description');
150+
}
151+
152+
if ($desc_config === 'custom') {
153+
return $this->context->get('seo_custom_og_desc');
154+
}
155+
156+
return null;
157+
}
158+
159+
/**
160+
* The {{ lucky_seo:og_image }} tag.
161+
*
162+
* @return string|array
163+
*/
164+
public function ogImage()
165+
{
166+
$og_image = $this->context->raw('seo_og_image');
167+
168+
if (!$og_image) {
169+
return $this->context->get('seo:og_image');
170+
}
171+
}
172+
}

starter-kit.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export_paths:
2+
- app/Tags
23
- app/Widgets
34
- app/ViewModels
45
- content/assets

0 commit comments

Comments
 (0)