Skip to content

Commit

Permalink
Merge branch 'release/3.3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Sep 18, 2023
2 parents a111101 + f8c9dfd commit d0ca705
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 3.3.3 - 2023-09-18
### Fixed
- Fixed an error when using a custom meta template ([#81](https://github.com/studioespresso/craft-seo-fields/issues/81))


## 3.3.2 - 2023-09-13
### Fixed
- Fixed an issue where sitemaps couldn't be saved for different sites
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-seo-fields",
"description": "Fields for your SEO & OG meta data",
"type": "craft-plugin",
"version": "3.3.2",
"version": "3.3.3",
"keywords": [
"craft",
"cms",
Expand Down
16 changes: 13 additions & 3 deletions src/models/SeoFieldModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class SeoFieldModel extends Model
*/
public $siteDefault;

public function init(): void
{
if ($this->siteId) {
$site = Craft::$app->getSites()->getSiteById($this->siteId);
} else {
$site = Craft::$app->getSites()->getCurrentSite();
}
$this->siteDefault = SeoFields::getInstance()->defaultsService->getDataBySite($site);
}

public function getDefaults()
{
if ($this->siteId) {
Expand Down Expand Up @@ -74,7 +84,7 @@ public function getCanonical()
return $request->hostInfo .'/' . $request->getPathInfo(true);
}

public function getOgTitle($element)
public function getOgTitle($element = null)
{
if ($this->facebookTitle) {
return $this->facebookTitle . $this->getSiteNameWithSeperator();
Expand All @@ -83,7 +93,7 @@ public function getOgTitle($element)
}
}

public function getTwitterTitle($element)
public function getTwitterTitle($element = null)
{
if ($this->twitterTitle) {
return $this->twitterTitle . $this->getSiteNameWithSeperator();
Expand Down Expand Up @@ -154,7 +164,7 @@ public function getTwitterImage(Asset $asset = null)
];
}

public function getAlternate($element)
public function getAlternate($element = null)
{
if (!$element) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/services/RenderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getSeoFromContent($context, $handle)
$meta = new SeoFieldModel();
}

return ['meta' => $meta, 'entry' => $element];
return ['meta' => $meta, 'entry' => $element, 'element' => $element];

} catch (\Exception $e) {
return null;
Expand Down
36 changes: 19 additions & 17 deletions src/templates/_meta.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,43 @@

{# Uncomment these lines when copying the template to your site templates #}
{#{% set seoFields = getSeoFields() %}#}
{#{% set element = seoFields.element %}#}
{#{% set meta = seoFields.meta %}#}

{% if meta %}

<title>{{ meta.getPageTitle(element) }}</title>
<meta name="description" content="{{ meta.getMetaDescription() }}">
{# Facebook #}
<meta property="og:url" content="{{ craft.app.request.absoluteUrl }}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="{{ meta.getOgTitle(element) }}"/>
{% set ogImage = meta.getOgImage() %}
{% if ogImage %}
<meta property="og:image" content="{{ ogImage.url }}"/>
<meta property="og:image:width" content="{{ ogImage.width }}"/>
<meta property="og:image:height" content="{{ ogImage.height }}"/>
<meta property="og:image:alt" content="{{ ogImage.alt }}"/>
{% endif %}
<meta property="og:title" content="{{ meta.getOgTitle() }}"/>
{% set ogImage = meta.getOgImage() %}
{% if ogImage %}
<meta property="og:image" content="{{ ogImage.url }}"/>
<meta property="og:image:width" content="{{ ogImage.width }}"/>
<meta property="og:image:height" content="{{ ogImage.height }}"/>
<meta property="og:image:alt" content="{{ ogImage.alt }}"/>
{% endif %}
<meta property="og:description" content="{{ meta.getOgDescription() }}"/>
<meta property="og:site_name" content=""/>
<meta property="og:locale" content="{{ currentSite.language }}"/>
{# Twitter #}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="" />
<meta name="twitter:url" content="{{ craft.app.request.absoluteUrl }}" />
<meta name="twitter:title" content="{{ meta.getTwitterTitle(element) }}" />
<meta name="twitter:title" content="{{ meta.getTwitterTitle() }}" />
<meta name="twitter:description" content="{{ meta.getTwitterDescription() }}" />
{% if ogImage %}
<meta name="twitter:image" content="{{ meta.getTwitterImage().url ?? ogImage.url }}" />
{% endif %}
{% if ogImage %}
<meta name="twitter:image" content="{{ meta.getTwitterImage().url ?? ogImage.url }}" />
{% endif %}

{% if craft.app.response.statusCode < 400 %}
<link rel="canonical" href="{{ meta.getCanonical() }}" />
<link rel="canonical" href="{{ meta.getCanonical() }}" />
{% endif %}
{% for alt in meta.getAlternate(element) %}
<link rel="alternate" hreflang="{{ alt.language }}" href="{{ alt.url }}" />
{% endfor %}

{% for alt in meta.getAlternate(element) %}
<link rel="alternate" hreflang="{{ alt.language }}" href="{{ alt.url }}" />
{% endfor %}
{% endif %}
{# SEO Fields meta fields end #}

0 comments on commit d0ca705

Please sign in to comment.