Skip to content

Commit

Permalink
Merge branch 'v3-dev' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Sep 3, 2018
2 parents 0ef8c6d + 679474e commit b917148
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 27 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.3.1 - 2018-09-03
### Fixed
- `craft.seo.custom` social images now fallback to the default social image from global settings. #113
- Fixed bug where some requests would 404 when injecting 🤖's #130

### Changed
- SEO robots no longer return empty values #110
- Text in the keyword input will automatically be turned into a tag on blur #114

## 3.3.0 - 2018-05-25
**Heads up:** This update includes changes to the SEO `meta.twig`. If you are using a custom version you can review the changes [here](https://github.com/ethercreative/seo/commits/v3/src/templates/_seo/meta.twig).

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": "ether/seo",
"license": "MIT",
"description": "SEO utilities including a unique field type, sitemap, & redirect manager",
"version": "3.3.0",
"version": "3.3.1",
"type": "craft-plugin",
"minimum-stability": "dev",
"require": {
Expand Down
10 changes: 9 additions & 1 deletion resources/js/field/FocusKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,16 @@ export default class FocusKeywords {
/**
* Fired when the keywords input is blurred
*/
onInputBlur = () => {
onInputBlur = e => {
this.inputWrap.classList.remove('focused');

if (e.target.value.trim() !== "") {
this.onInputKeyDown({
target: e.target,
keyCode: 13,
preventDefault: () => {},
});
}
};

/**
Expand Down
10 changes: 3 additions & 7 deletions resources/js/settings/Redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,13 @@ export default class Redirects {
onSuccess = () => {},
onError = () => {}
) {
const formData = new FormData()
, jsonData = {};

formData.append(this.csrf.name, this.csrf.token);
const jsonData = {};

jsonData[this.csrf.name] = this.csrf.token;

Object.keys(fields).forEach(key => {
if (fields.hasOwnProperty(key)) {
formData.append(key, fields[key]);
if (fields.hasOwnProperty(key))
jsonData[key] = fields[key];
}
});

$.ajax({
Expand Down
39 changes: 33 additions & 6 deletions src/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ether\seo;

use craft\elements\Asset;
use craft\helpers\Template;
use craft\helpers\UrlHelper;
use ether\seo\fields\SeoField;

Expand All @@ -14,12 +15,15 @@ public function custom (
$includeTitleSuffix = true,
$social = []
) {
$settings = Seo::$i->getSettings();
$socialImage = $this->_socialImageFallback();

$text = [
'title' =>
$title
? $title . (
$includeTitleSuffix
? ' ' . Seo::$i->getSettings()['titleSuffix']
? ' ' . $settings['titleSuffix']
: ''
) : '',
'description' => $description ?: '',
Expand All @@ -34,6 +38,9 @@ public function custom (
$ret['social'][$key],
$value
);

if (!$ret['social'][$key]['image'] && $socialImage)
$ret['social'][$key]['image'] = $socialImage;
}

return $ret;
Expand All @@ -52,6 +59,7 @@ public function custom (
public function social ($value)
{
$social = [];
$socialImage = $this->_socialImageFallback();

if (!array_key_exists('social', $value)) {
return SeoField::$defaultValue['social'];
Expand All @@ -60,7 +68,7 @@ public function social ($value)
foreach ($value['social'] as $name => $v) {
$social[$name] = [
'title' => $v['title'] ?: $value['title'],
'image' => $v['image'],
'image' => $v['image'] ?: $socialImage,
'description' => $v['description'] ?: $value['description'],
];
}
Expand All @@ -74,7 +82,7 @@ public function social ($value)
/**
* @param Asset|null $image
*
* @return string
* @return \Twig_Markup|string
* @throws \yii\base\Exception
*/
public function twitterImage ($image)
Expand All @@ -88,7 +96,7 @@ public function twitterImage ($image)
/**
* @param Asset|null $image
*
* @return string
* @return \Twig_Markup|string
* @throws \yii\base\Exception
*/
public function facebookImage ($image)
Expand All @@ -103,7 +111,7 @@ public function facebookImage ($image)
* @param Asset|null $image
* @param array $transform
*
* @return string
* @return \Twig_Markup|string
* @throws \yii\base\Exception
*/
private function _socialImage ($image, array $transform)
Expand All @@ -115,7 +123,26 @@ private function _socialImage ($image, array $transform)
if ($transformUrl && strpos($transformUrl, 'http') === false)
$transformUrl = UrlHelper::siteUrl($transformUrl);

return $transformUrl;
return Template::raw($transformUrl);
}

/**
* Returns fallback image from global settings
*
* @return Asset|null
*/
private function _socialImageFallback ()
{
static $fallback = null;

if (!$fallback)
{
$settings = Seo::$i->getSettings();
if (!empty($settings['socialImage']))
$fallback = \Craft::$app->assets->getAssetById((int) $settings['socialImage'][0]);
}

return $fallback;
}

}
33 changes: 33 additions & 0 deletions src/fields/SeoField.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ public function normalizeValue ($value, ElementInterface $element = null)
$settings = $this->getSettings();
$settingsGlobal = Seo::$i->getSettings();

// Backwards compatibility to Craft 2
// ---------------------------------------------------------------------

// Convert keyword -> keywords

if ($value && array_key_exists('keyword', $value)) {
if (!empty($value['keyword'])) {
$value['keywords'] = [
[
'keyword' => $value['keyword'],
'rating' => [
'' => 'neutral',
'good' => 'good',
'ok' => 'average',
'bad' => 'poor',
][$value['score']],
],
];
} else {
$value['keywords'] = [];
}
unset($value['keyword']);
$value['keywords'] = json_encode($value['keywords']);
$value['score'] = 'neutral';
}

// ---------------------------------------------------------------------

// Title

$titleSuffix = $settings['titleSuffix'] ?: $settingsGlobal['titleSuffix'];
Expand Down Expand Up @@ -146,6 +174,11 @@ public function normalizeValue ($value, ElementInterface $element = null)
$value['advanced'] ?? []
);

// Filter out empty robots
if (array_key_exists('robots', $value['advanced']))
$value['advanced']['robots'] =
array_filter($value['advanced']['robots']);

return $value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/SeoField.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/resources/js/SeoField.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/resources/js/SeoSettings.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/resources/js/SeoSettings.min.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/services/SeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ class SeoService extends Component
*/
public function injectRobots ()
{
try {
$resolve = \Craft::$app->request->resolve();
} catch (\Exception $e) {
$resolve = [null, []];
}

$headers = \Craft::$app->getResponse()->getHeaders();
$resolve = \Craft::$app->request->resolve()[1];
$resolve = $resolve[1];
$variables = array_key_exists('variables', $resolve)
? $resolve['variables']
: [];
Expand Down
19 changes: 12 additions & 7 deletions src/templates/redirects.twig
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@
required: true
}) }}

{{ forms.text({
name: "separator",
placeholder: "Separator",
required: true
}) }}
<label class="type-select">
{{ forms.text({
name: "separator",
placeholder: "Separator",
required: true
}) }}
<span class="instructions">
The character used to separate each column. In a CSV, for example, this would be a comma (,).
</span>
</label>

<label class="type-select">
{{ ui.selectField({
Expand All @@ -107,8 +112,8 @@
}) }}

<span class="instructions">
The default redirect type (if one isn't defined)
</span>
The default redirect type (if one isn't defined)
</span>
</label>
</div>

Expand Down

0 comments on commit b917148

Please sign in to comment.