Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Seo
  • Loading branch information
NaysKutzu committed Dec 13, 2024
1 parent 128e4f1 commit c9d3c54
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions frontend/src/components/client/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!-- src/components/Auth/Layout.vue -->
<script setup lang="ts">

</script>
<template>
<div class="min-h-screen bg-[#0a0a1f] relative overflow-hidden">
<!-- Background elements -->
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createI18n } from 'vue-i18n';
import EN from '@/locale/en.yml';
import Settings from '@/mythicalclient/Settings';
import 'sweetalert2/dist/sweetalert2.min.css';
import SeoManager from '@/mythicalclient/SeoManager';

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

Check failure on line 11 in frontend/src/main.ts

View workflow job for this annotation

GitHub Actions / Frontend Lint (20)

'SeoManager' is defined but never used

const app = createApp(App);

Expand All @@ -25,3 +26,4 @@ app.use(i18n);
Settings.initializeSettings();

app.mount('#app');

3 changes: 0 additions & 3 deletions frontend/src/mythicalclient/Permissions.ts

This file was deleted.

91 changes: 91 additions & 0 deletions frontend/src/mythicalclient/SeoManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class SeoManager {

static setFavicon(url: string) {
const link: HTMLLinkElement = document.createElement('link');
link.rel = 'icon';
link.href = url;

const existingLink = document.querySelector("link[rel='icon']");
if (existingLink) {
document.head.removeChild(existingLink);
}

document.head.appendChild(link);
}

static setTitle(title: string) {
document.title = title;
SeoManager.setOgTitle(title);
SeoManager.setMetaTag('og:type', 'website');
SeoManager.setTwitterCard('summary_large_image');
SeoManager.setTwitterTitle(title);
}

static setDescription(description: string) {
SeoManager.setMetaTag('description', description);
SeoManager.setOgDescription(description);
SeoManager.setTwitterDescription(description);
}

static setTwitterCard(cardType: string) {
SeoManager.setMetaTag('twitter:card', cardType);
}

static setTwitterTitle(title: string) {
SeoManager.setMetaTag('twitter:title', title);
}

static setTwitterDescription(description: string) {
SeoManager.setMetaTag('twitter:description', description);
}

static setTwitterImage(imageUrl: string) {
SeoManager.setMetaTag('twitter:image', imageUrl);
}

static setOgTitle(title: string) {
SeoManager.setMetaProperty('og:title', title);
}

static setOgDescription(description: string) {
SeoManager.setMetaProperty('og:description', description);
}

static setOgImage(imageUrl: string) {
SeoManager.setMetaProperty('og:image', imageUrl);
}

static setOgUrl(url: string) {
SeoManager.setMetaProperty('og:url', url);
}

static setKeywords(keywords: string) {
SeoManager.setMetaTag('keywords', keywords);
}

static setAuthor(author: string) {
SeoManager.setMetaTag('author', author);
}

private static setMetaTag(name: string, content: string) {
let meta = document.querySelector(`meta[name='${name}']`) as HTMLMetaElement | null;
if (!meta) {
meta = document.createElement('meta');
meta.name = name;
document.head.appendChild(meta);
}
meta.content = content;
}

private static setMetaProperty(property: string, content: string) {
let meta = document.querySelector(`meta[property='${property}']`);
if (!meta) {
meta = document.createElement('meta');
meta.setAttribute('property', property);
document.head.appendChild(meta);
}
(meta as HTMLMetaElement).content = content;
}
}

export default SeoManager;

0 comments on commit c9d3c54

Please sign in to comment.