Skip to content

Commit 12312ff

Browse files
committed
Improve twitter and og fallbacks
1 parent c6044bd commit 12312ff

File tree

9 files changed

+683
-662
lines changed

9 files changed

+683
-662
lines changed

blueprints/fields/open_graph.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ fields:
66
numbered: false
77
og_title:
88
label: OG Title
9-
help: The title of your object as it should appear within the graph.
9+
help: The title of your object as it should appear within the graph. Will use *page title* as fallback.
1010
type: text
1111
og_description:
1212
label: OG Description
13-
help: A one to two sentence description of your object.
13+
help: A one to two sentence description of your object. Will use *page description* and *site description* as fallbacks.
1414
type: text
1515
og_image:
1616
label: OG Image (1200x630)
17-
help: An image which should represent your object within the graph. Will be cropped automatically.
17+
help: An image which should represent your object within the graph. Will be cropped automatically. Will use *site OG image* as fallback.
1818
type: files
1919
multiple: false
2020
uploads: seo-image
2121
og_site_name:
2222
label: OG Site Name
23-
help: If your object is part of a larger web site, the name which should be displayed for the overall site.
23+
help: If your object is part of a larger web site, the name which should be displayed for the overall site. Will use *site title* as fallback.
2424
type: text
2525
width: 1/2
2626
og_url:

blueprints/fields/twitter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ fields:
88
label: Twitter Title
99
type: text
1010
limit: 70
11-
help: The title of your page as it should appear on Twitter
11+
help: The title of your page as it should appear on Twitter. Will use *page title* as fallback.
1212
twitter_description:
1313
label: Twitter Description
1414
type: text
1515
limit: 300
16-
help: A one to two sentence description of your page.
16+
help: A one to two sentence description of your page. Will use *page description* and *site description* as fallbacks.
1717
twitter_image:
1818
label: Twitter Image (1200x675)
1919
help: Will be cropped automatically.

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
"recognizeSelfClosing": true
88
},
99
"devDependencies": {
10-
"@vue/component-compiler-utils": "^3.1.1",
10+
"@vue/component-compiler-utils": "^3.2.0",
1111
"cssnano": "^4.1.10",
12-
"sass": "^1.25.0",
13-
"vue-template-compiler": "^2.6.11"
12+
"sass": "^1.32.8",
13+
"vue-template-compiler": "^2.6.12"
1414
},
1515
"dependencies": {
16+
"core-js": "^3.9.0",
1617
"global": "^4.4.0",
1718
"parcel": "^1.12.4",
18-
"vue": "^2.6.11",
19+
"vue": "^2.6.12",
1920
"vue-hot-reload-api": "^2.3.4"
2021
}
2122
}

sections/twitter_card_preview.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
},
1313
'url' => function () {
1414
return $this->model()->url();
15+
},
16+
'siteTitleAfterPageTitle' => function () {
17+
return option('diesdasdigital.meta-knight.siteTitleAfterPageTitle', true);
1518
}
1619
]
1720
];

snippets/meta_information.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656

5757
<?php // Open Graph ?>
5858

59-
<meta property="og:title" content="<?= $page->og_title()->or($page->title()) ?>">
59+
<meta property="og:title" content="<?= $page->og_title()->or($page->meta_title())->or($page->title()) ?>">
6060

61-
<meta property="og:description" content="<?= $page->og_description()->or($site->og_description()) ?>">
61+
<meta property="og:description" content="<?= $page->og_description()->or($page->meta_description())->or($site->meta_description()) ?>">
6262

6363
<?php if ($ogimage = $page->og_image()->toFile() ?? $site->og_image()->toFile()): ?>
6464
<meta property="og:image" content="<?= $ogimage->thumb($og_image)->url() ?>">
@@ -103,9 +103,9 @@
103103

104104
<meta name="twitter:card" content="summary">
105105

106-
<meta name="twitter:title" content="<?= $page->twitter_title()->or($site->twitter_title()) ?>">
106+
<meta name="twitter:title" content="<?= $page->twitter_title()->or($page->meta_title())->or($page->title()) ?>">
107107

108-
<meta name="twitter:description" content="<?= $page->twitter_description()->or($site->twitter_description()) ?>">
108+
<meta name="twitter:description" content="<?= $page->twitter_description()->or($page->meta_description())->or($site->meta_description()) ?>">
109109

110110
<?php if ($twitterimage = $page->twitter_image()->toFile() ?? $site->twitter_image()->toFile()): ?>
111111
<meta name="twitter:image" content="<?= $twitterimage->thumb($twitter_image)->url() ?>">

src/components/sections/facebook_sharing_preview.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,33 @@ export default {
4848
computed: {
4949
og_title() {
5050
let og_title = this.$store.getters["content/values"]().og_title;
51+
let meta_title = this.$store.getters["content/values"]().meta_title;
52+
let page_title = this.page_title;
5153
5254
if (og_title.length < 1) {
53-
og_title = this.page_title;
55+
if (meta_title.length > 0) {
56+
og_title = meta_title;
57+
} else {
58+
og_title = page_title;
59+
}
5460
}
5561
5662
return og_title;
5763
},
5864
og_description() {
5965
let og_description = this.$store.getters["content/values"]()
6066
.og_description;
67+
let meta_description = this.$store.getters["content/values"]()
68+
.meta_description;
6169
6270
if (og_description.length < 1) {
63-
og_description = "[OG Description Missing]";
64-
return og_description;
65-
} else {
66-
return og_description;
71+
og_description = meta_description;
72+
if (meta_description.length < 1) {
73+
og_description = "[OG Description and Fallback Description Missing]";
74+
}
6775
}
76+
77+
return og_description;
6878
},
6979
og_site_name() {
7080
let og_site_name = this.$store.getters["content/values"]().og_site_name;
@@ -84,7 +94,7 @@ export default {
8494
store_image: {
8595
handler() {
8696
if (this.store_image.length === 0) {
87-
this.og_image = null;
97+
this.og_image = this.site_og_image_url;
8898
} else {
8999
this.$api.files
90100
.get(

0 commit comments

Comments
 (0)