Skip to content

Commit 6a554d4

Browse files
committed
Meta tags for social media previews
1 parent f4f9aa0 commit 6a554d4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/views/TipsAndComments.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Loading from '../components/Loading.vue';
5050
import backendAuthMixin from '../utils/backendAuthMixin';
5151
import SendComment from '../components/SendComment.vue';
5252
import { EventBus } from '../utils/eventBus';
53+
import Backend from '../utils/backend';
5354
5455
export default {
5556
components: {
@@ -126,10 +127,29 @@ export default {
126127
},
127128
metaInfo() {
128129
const title = {
129-
tip: 'Comments for a Tip',
130+
tip: `Tip ${this.tipId}`,
130131
comment: 'Comment View',
131132
}[this.$route.name];
132-
return { title };
133+
const author = this.id ? this.record?.author : this.record?.sender;
134+
const avatar = Backend.getProfileImageUrl(author);
135+
136+
const ogImage = this.record?.media?.length ? this.record.media[0] : avatar;
137+
const ogUrl = window.location.href.split('?')[0];
138+
const ogTitle = `Superhero ${this.id ? 'Comment' : `Tip ${this.tipId.split('_')[1]}`}`;
139+
const ogDescription = this.id ? this.record?.text : this.record?.title;
140+
141+
const meta = [
142+
{ property: 'og:image', content: ogImage },
143+
{ property: 'og:url', content: ogUrl },
144+
{ property: 'og:title', content: ogTitle },
145+
{ property: 'og:description', content: ogDescription },
146+
{ property: 'og:site_name', content: 'Superhero' },
147+
{ name: 'twitter:card', content: 'summary' },
148+
{ name: 'twitter:site', content: '@superhero_chain' },
149+
{ name: 'twitter:creator', content: '@superhero_chain' },
150+
{ name: 'twitter:image:alt', content: 'Superhero post' },
151+
];
152+
return { title, meta };
133153
},
134154
};
135155
</script>

0 commit comments

Comments
 (0)