Skip to content

Commit

Permalink
Merge pull request #581 from Gencaster/579-add-meta-tags-to-player
Browse files Browse the repository at this point in the history
added metaHeader
  • Loading branch information
capital-G authored Oct 3, 2023
2 parents 519d98d + fb8cfbe commit 5d11e7f
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
80 changes: 80 additions & 0 deletions caster-front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions caster-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@element-plus/icons-vue": "^2.1.0",
"@sentry/vue": "^7.57.0",
"@unhead/vue": "^1.7.4",
"@urql/vue": "^1.0.4",
"element-plus": "^2.3.5",
"graphql": "^16.6.0",
Expand Down
6 changes: 6 additions & 0 deletions caster-front/src/components/GraphPlayer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import { type Ref, ref, computed, watch, reactive } from "vue";
import { useHead } from "@unhead/vue";
import { metaHead } from "@/composables/metaHead";
import {
ElButton,
ElCheckbox,
Expand Down Expand Up @@ -325,6 +327,10 @@ const startStream = async () => {
playerState.value = PlayerState.Playing;
startingTimestamp.value = new Date().getTime();
};
// meta stuff
const meta = metaHead(props.graph.displayName, props.graph.startText);
useHead(meta);
</script>

<template>
Expand Down
42 changes: 42 additions & 0 deletions caster-front/src/composables/metaHead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const metaHead = (
metaTitle: string,
metaDescription: string,
metaImageUrl?: string,
siteUrl?: string,
) => {
const meta = {
title: metaTitle,
meta: [
{ name: "description", content: metaDescription },
{ hid: "description", name: "description", content: metaDescription },

// Twitter Card data
{ name: "twitter:title", content: metaTitle, hid: "custom" },
{ name: "twitter:description", content: metaDescription, hid: "custom" },

// Open Graph
{ property: "og:title", content: metaTitle, hid: "custom" },
{
property: "og:description",
content: metaDescription,
hid: "og:description",
},
{ property: "og:image", content: metaImageUrl, hid: "og:image" },
],
};

if (metaImageUrl) {
meta.meta.push({ name: "og:image", content: metaImageUrl });
meta.meta.push({
name: "twitter:image",
content: metaImageUrl,
hid: "custom",
});
}

if (siteUrl) {
meta.meta.push({ property: "og:url", content: siteUrl, hid: "custom" });
}

return meta;
};
4 changes: 4 additions & 0 deletions caster-front/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createApp } from "vue";
import { createHead } from "@unhead/vue";
import { createPinia } from "pinia";
import urql, { fetchExchange, subscriptionExchange } from "@urql/vue";
import { SubscriptionClient } from "subscriptions-transport-ws";
Expand All @@ -13,6 +14,9 @@ import "./assets/main.scss";

const app = createApp(App);

const head = createHead();
app.use(head);

if (
import.meta.env.VITE_BACKEND_URL &&
import.meta.env.VITE_SENTRY_DSN_CASTER_FRONT
Expand Down
1 change: 1 addition & 0 deletions caster-front/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compilerOptions": {
"composite": true,
"baseUrl": ".",
"allowImportingTsExtensions": true,
"paths": {
"@/*": ["./src/*"]
}
Expand Down

0 comments on commit 5d11e7f

Please sign in to comment.