refactored seo helper, adjusted meta tags & added a shitload more buttons to discord component embeds
Frontend CI/CD / test-and-build (push) Successful in 25s
Frontend CI/CD / deploy (push) Successful in 26s

This commit is contained in:
itzMiney committed 2026-11-08 21:27:37 +01:00
1 parent c0b75c341a
commit e7ed9f047f
12 files changed
+253 -94

No files matched your search

+79 -20
View File
@@ -1,23 +1,35 @@
import {Inject, Injectable} from '@angular/core';
import { Title, Meta } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import {Meta, Title} from '@angular/platform-browser';
import {Router} from '@angular/router';
import {DOCUMENT} from '@angular/common';
export interface DiscordButton {
label: string;
url: string;
}
export interface DiscordGalleryItem {
url: string;
description?: string;
spoiler?: boolean;
}
export interface SeoConfig {
title: string;
desc: string;
img?: string;
url?: string;
col?: string;
suffix?: boolean;
buttons?: DiscordButton[];
gallery?: DiscordGalleryItem[];
}
@Injectable({
providedIn: 'root'
})
export class SeoService {
private readonly rootDomain = 'https://itzminey.dev';
private readonly defaultImage = 'https://itzminey.dev/assets/ogimg.png';
private readonly defaultThumb = 'https://itzminey.dev/assets/thumb.png';
private readonly siteColor = '#0095a4';
constructor(
private titleService: Title,
private metaService: Meta,
@@ -25,39 +37,72 @@ export class SeoService {
@Inject(DOCUMENT) private document: Document
) {}
update(config: { title: string; desc: string; img?: string; suffix?: boolean; buttons?: DiscordButton[];}) {
private readonly defaultColor = '#0095a4';
private readonly rootDomain = 'https://itzminey.dev';
getpath(path?: string ) {
if (!path) return `${this.rootDomain}${this.router.url}`;
if (path === 'root') return this.rootDomain;
return `${this.rootDomain}/${path.replace(/^\//, '')}`;
}
private readonly defaultImage = this.getpath('assets/ogimg.png');
private readonly siteThumb = this.getpath('assets/thumb.png');
update(config: SeoConfig) {
const siteName = 'itzMiney';
const appendSuffix = config.suffix ?? true;
const title = appendSuffix && !config.title.includes(siteName)
const title = appendSuffix && !config.title.endsWith(`| ${siteName}`)
? `${config.title} | ${siteName}`
: config.title;
const description = config.desc;
const image = config.img || this.defaultImage;
const currentUrl = `${this.rootDomain}${this.router.url}`;
const currentUrl = this.getpath();
const siteColor = config.col || this.defaultColor;
const gallery = config.gallery;
this.titleService.setTitle(title );
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.metaService.updateTag({ name: 'theme-color', content: siteColor });
this.injectDiscordComponentEmbed(config.buttons, { title, description, image, currentUrl });
this.injectDiscordComponentEmbed(config.buttons, gallery, {
title,
description,
image,
currentUrl,
siteColor
});
}
private injectDiscordComponentEmbed(buttons?: DiscordButton[], meta?: { title: string; description: string; image: string; currentUrl: string }) {
private injectDiscordComponentEmbed(
buttons?: DiscordButton[],
gallery?: DiscordGalleryItem[],
meta?: {
title: string;
description: string;
image: string;
currentUrl: string;
siteColor: string
},
) {
const existingScript = this.document.getElementById('discord:component-embed');
if (existingScript) {
existingScript.remove();
}
const thumb = meta?.image || this.defaultThumb;
const thumb = this.siteThumb;
const siteColor = meta?.siteColor || this.defaultColor;
const sectionComponent = {
const containerComponents: any[] = [];
containerComponents.push({
type: 9,
components: [
{
@@ -71,9 +116,23 @@ export class SeoService {
url: thumb
}
}
};
});
const containerComponents: any[] = [sectionComponent];
if (gallery && gallery.length > 0) {
containerComponents.push({
type: 12,
items: gallery.map(item => {
const galleryItem: any = {
media: {
url: item.url
}
};
if (item.description) galleryItem.description = item.description;
if (item.spoiler !== undefined) galleryItem.spoiler = item.spoiler;
return galleryItem;
})
});
}
if (buttons && buttons.length > 0) {
containerComponents.push({
@@ -91,7 +150,7 @@ export class SeoService {
flags: 32768,
component: {
type: 17,
accent_color: parseInt(this.siteColor.replace('#', ''), 16),
accent_color: parseInt(siteColor.replace('#', ''), 16),
components: containerComponents
}
};