Refactored complex custom meta jank to use Angular SSR instead
Frontend CI/CD / test-and-build (push) Successful in 25s
Frontend CI/CD / deploy (push) Canceled after 25s

This commit is contained in:
itzMiney committed 2026-11-08 00:51:09 +01:00
1 parent d291409097
commit febbc63f35
21 files changed
+1680 -657

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
import {Inject, Injectable} from '@angular/core';
import { Title, Meta } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/common';
export interface DiscordButton {
label: string;
url: string;
}
@Injectable({
providedIn: 'root'
})
export class SeoService {
private readonly rootDomain = 'https://itzminey.dev';
private readonly defaultImage = 'https://meta.itzminey.dev/assets/ogimg.png';
private readonly siteColor = '#0095a4';
constructor(
private titleService: Title,
private metaService: Meta,
private router: Router,
@Inject(DOCUMENT) private document: Document
) {}
update(config: { title: string; desc: string; img?: string; suffix?: boolean; buttons?: DiscordButton[];}) {
const siteName = 'itzMiney';
const appendSuffix = config.suffix ?? true;
const title = appendSuffix && !config.title.includes(siteName)
? `${config.title} | ${siteName}`
: config.title;
const description = config.desc;
const image = config.img || this.defaultImage;
const currentUrl = `${this.rootDomain}${this.router.url}`;
this.titleService.setTitle(title );
this.metaService.updateTag({ name: 'description', content: description });
this.metaService.updateTag({ property: 'og:title', content: title });
this.metaService.updateTag({ property: 'og:description', content: description });
this.metaService.updateTag({ property: 'og:image', content: image });
this.metaService.updateTag({ property: 'og:url', content: currentUrl });
this.metaService.updateTag({ name: 'theme-color', content: this.siteColor });
this.injectDiscordButtons(config.buttons);
}
private injectDiscordButtons( buttons?: DiscordButton[] ) {
const existingScript = this.document.getElementById('discord:component-embed');
if (existingScript) {
existingScript.remove();
}
if (!buttons || buttons.length === 0) return;
const componentPayload = {
component: {
type: 17,
components: [
{
type: 1,
components: buttons.map(btn => ({
type: 2,
label: btn.label,
style: 5,
url: btn.url
}))
}
]
}
};
const script = this.document.createElement('script');
script.id = 'discord:component-embed';
script.type = 'application/json';
script.text = JSON.stringify(componentPayload, null, 2);
this.document.head.appendChild(script);
}
}