refactored seo helper, adjusted meta tags & added a shitload more buttons to discord component embeds
This commit is contained in:
1 parent
c0b75c341a
commit
e7ed9f047f
12 files changed
+253
-94
No files matched your search
@@ -44,10 +44,10 @@ export class AboutComponent implements OnInit, AfterViewInit {
|
||||
desc: 'Welcome to itzMiney\'s Homepage! Here you can find my portfolio and other cool stuff.',
|
||||
suffix: false,
|
||||
buttons: [
|
||||
{ label: 'About', url: 'https://itzminey.dev/about' },
|
||||
{ label: 'Portfolio', url: 'https://itzminey.dev/portfolio' },
|
||||
{ label: 'Socials', url: 'https://itzminey.dev/socials' },
|
||||
{ label: 'Blog', url: 'https://itzminey.dev/blog' }
|
||||
{ label: 'About', url: this.seo.getpath('root') },
|
||||
{ label: 'Portfolio', url: this.seo.getpath('portfolio') },
|
||||
{ label: 'Socials', url: this.seo.getpath('socials') },
|
||||
{ label: 'Blog', url: this.seo.getpath('blog') }
|
||||
]
|
||||
});
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
|
||||
@@ -97,7 +97,8 @@ export class AdminComponent implements OnInit, OnDestroy {
|
||||
ngOnInit() {
|
||||
this.seo.update({
|
||||
title: 'Admin Panel',
|
||||
desc: 'Management & Administration Panel'
|
||||
desc: 'Management & Administration Panel',
|
||||
buttons: [{ label: 'Log-in', url: this.seo.getpath('root')}]
|
||||
});
|
||||
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
|
||||
@@ -111,60 +111,98 @@ h1 {
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
font-size: 1rem;
|
||||
color: #D6DAEFBD;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
font-size: 0.95rem;
|
||||
color: rgb(168 168 211);
|
||||
text-align: left;
|
||||
margin: 25px 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.article-meta strong, .article-meta .meta-left i {
|
||||
color: rgb(214 217 255);
|
||||
}
|
||||
|
||||
.article-meta p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.article-meta .meta-right strong {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.article-meta .meta-left, .article-meta .meta-right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
}
|
||||
|
||||
.article-buttons {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
color: white;
|
||||
justify-content: space-between;
|
||||
margin: 0 0 5px 15px;
|
||||
}
|
||||
|
||||
.article-buttons button {
|
||||
background-color: #444893FF;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 1rem;
|
||||
cursor: pointer;
|
||||
border-radius: 25px;
|
||||
transition: background-color 0.3s;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.article-buttons button:hover {
|
||||
background-color: #707ec5;
|
||||
}
|
||||
|
||||
#shareBtn {
|
||||
background-color: transparent;
|
||||
.article-buttons i {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.article-buttons .buttons-left {
|
||||
display: inline-flex;
|
||||
gap: 20px;
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.article-buttons .buttons-right {
|
||||
display: inline-flex;
|
||||
margin-top: auto;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.article-buttons .buttons-right i {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.article-buttons .buttons-right p {
|
||||
margin: 0;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.article-buttons a {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
color: white;
|
||||
margin: 0;
|
||||
transition: all ease-in-out 0.2s;
|
||||
}
|
||||
|
||||
#shareBtn:hover {
|
||||
color: #cfd7f8;
|
||||
.article-buttons #shareBtn:hover {
|
||||
color: #b9ecff;
|
||||
}
|
||||
|
||||
#shareBtn.copied {
|
||||
color: #8798dc;
|
||||
.article-buttons #shareBtn:focus, #shareBtn.copied {
|
||||
color: #5ee0ff;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
margin-right: 64px;
|
||||
justify-content: center;
|
||||
.article-buttons #backBtn:hover {
|
||||
color: #ffb2b6;
|
||||
}
|
||||
|
||||
.article-buttons #backBtn:focus {
|
||||
color: #c62d46;
|
||||
}
|
||||
|
||||
.error-message h1 {
|
||||
font-size: 10rem;
|
||||
margin: 0;
|
||||
font-weight: 700;
|
||||
color: white;
|
||||
color: #ffd0d0;
|
||||
}
|
||||
|
||||
.error-message p {
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
<div>
|
||||
<img
|
||||
class="article-thumb"
|
||||
[src]="article.thumb_url"
|
||||
[src]="article.thumb_url || defaultThumbUrl"
|
||||
[alt]="article.title + ' thumbnail'"
|
||||
(error)="onThumbError($event)"
|
||||
[ngClass]="{ 'narrow': isNarrow }"
|
||||
/>
|
||||
<h1 [ngStyle]="{'font-size': isNarrow ? '2rem' : 'font-size: 2.5rem'}">{{ article.title }}</h1>
|
||||
@@ -31,15 +30,31 @@
|
||||
(click)="onArticleContentClick($event)"
|
||||
></markdown>
|
||||
<div class="article-buttons">
|
||||
<button id="shareBtn" (click)="copyLink()" [class.copied]="copied" class="fa-solid fa-share"></button>
|
||||
<div class="back-btn">
|
||||
<a href="/blog"><button id="backBtn">{{ 'ARTICLE_BACK' | translate }}</button></a>
|
||||
<div class="buttons-left">
|
||||
<a id="backBtn" [title]="'BUTTONS.BACK' | translate" href="/blog"><i class="fa-solid fa-turn-up fa-rotate-270"></i></a>
|
||||
<a id="shareBtn" [title]="'BUTTONS.SHARE' | translate" (click)="shareArticle()" [class.copied]="copied"><i class="fa-solid fa-share-nodes"></i></a>
|
||||
</div>
|
||||
<div class="buttons-right">
|
||||
<p><strong>{{ article.views }}</strong> Views</p>
|
||||
<i class="fa-solid fa-eye"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="article-meta">
|
||||
<p><strong>Author:</strong> {{ article.authorName}}</p>
|
||||
<p><strong>Views:</strong> {{ article.views }}</p>
|
||||
<p><strong>{{ 'CREATED_AT' | translate }}</strong> {{ article.createdAt | date:'MMM dd, yyyy, HH:mm' }}</p>
|
||||
<div class="meta-left">
|
||||
<p title="Author"><i class="fa-solid fa-user"></i><strong> {{ article.authorName}}</strong></p>
|
||||
<p [title]="'RELEASED_AT' | translate">
|
||||
{{ article.createdAt | date: 'mediumDate' }}<br>
|
||||
{{ 'TIME.PREFIX' | translate}}
|
||||
{{ article.createdAt | date:('TIME.FORMAT' | translate) }}
|
||||
{{ 'TIME.SUFFIX' | translate }}</p>
|
||||
</div>
|
||||
<div class="meta-right">
|
||||
<p><strong>{{ 'UPDATED_AT' | translate }}</strong></p>
|
||||
<p>{{ article.updatedAt | date:'mediumDate' }}<br>
|
||||
{{ 'TIME.PREFIX' | translate}}
|
||||
{{ article.updatedAt | date:('TIME.FORMAT' | translate) }}
|
||||
{{ 'TIME.SUFFIX' | translate }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -45,10 +45,8 @@ export class ArticlePageComponent implements OnInit {
|
||||
loading: boolean = true;
|
||||
|
||||
renderedContent: string = '';
|
||||
|
||||
readonly defaultThumbUrl = '/assets/ogimg.png';
|
||||
|
||||
isNarrow: boolean = false;
|
||||
defaultThumbUrl: string = '';
|
||||
|
||||
constructor(
|
||||
private articleService: ArticleService,
|
||||
@@ -62,6 +60,8 @@ export class ArticlePageComponent implements OnInit {
|
||||
this.route.params.subscribe((params) => {
|
||||
const slug = params['slug'];
|
||||
|
||||
this.defaultThumbUrl = this.seo.getpath('assets/ogimg.png');
|
||||
|
||||
this.loading = true;
|
||||
this.error = false;
|
||||
this.article = null;
|
||||
@@ -93,10 +93,18 @@ export class ArticlePageComponent implements OnInit {
|
||||
this.renderedContent = this.transformCustomBlocks(article.content);
|
||||
this.loading = false;
|
||||
|
||||
const thumbUrl = article.thumb_url || this.defaultThumbUrl;
|
||||
|
||||
this.seo.update({
|
||||
title: article.title,
|
||||
desc: article.content.substring(0, 150).replace(/[#*`_]/g, '') + '...', // Clean excerpt for description
|
||||
img: article.thumb_url || undefined
|
||||
desc: article.content.substring(0, 150).replace(/[#*`_]/g, '') + '...',
|
||||
gallery: [{
|
||||
url: thumbUrl
|
||||
}],
|
||||
buttons: [
|
||||
{ label: 'Read Post', url: this.seo.getpath() },
|
||||
{ label: 'View All', url: this.seo.getpath('blog') }
|
||||
]
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
@@ -117,14 +125,6 @@ export class ArticlePageComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
onThumbError(event: Event): void {
|
||||
const img = event.target as HTMLImageElement;
|
||||
|
||||
if (img.src.endsWith(this.defaultThumbUrl)) return;
|
||||
|
||||
img.src = this.defaultThumbUrl;
|
||||
}
|
||||
|
||||
onArticleContentClick(event: MouseEvent) {
|
||||
const target = event.target as HTMLElement;
|
||||
|
||||
@@ -171,15 +171,33 @@ export class ArticlePageComponent implements OnInit {
|
||||
this.selectedImage = null;
|
||||
}
|
||||
|
||||
copyLink() {
|
||||
const slug = this.route.snapshot.paramMap.get('slug') || '';
|
||||
const shareLink: string = 'https://itzminey.dev/blog/' + slug;
|
||||
this.copied = true;
|
||||
async shareArticle() {
|
||||
const shareUrl = this.seo.getpath();
|
||||
|
||||
setTimeout(() => {
|
||||
this.copied = false;
|
||||
}, 3000);
|
||||
if (navigator.share) {
|
||||
try {
|
||||
await navigator.share({
|
||||
title: document.title,
|
||||
url: shareUrl
|
||||
});
|
||||
return;
|
||||
} catch (err) {
|
||||
if ((err as Error).name !== 'AbortError') {
|
||||
console.error('Error sharing:', err);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
navigator.clipboard.writeText(shareLink).then()
|
||||
try {
|
||||
await navigator.clipboard.writeText(shareUrl);
|
||||
this.copied = true;
|
||||
setTimeout(() => {
|
||||
this.copied = false;
|
||||
}, 3000);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy link:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,8 @@ export class BlogComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
this.seo.update({
|
||||
title: 'Blog',
|
||||
desc: 'I post updates on the stuff I do here! (sometimes)'
|
||||
desc: 'I post updates on the stuff I do here! (sometimes)',
|
||||
buttons: [{ label: 'View Posts', url: this.seo.getpath() }]
|
||||
});
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
|
||||
|
||||
@@ -32,8 +32,9 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.seo.update({
|
||||
title:'Login',
|
||||
desc: 'Admin Panel Login'
|
||||
title: 'Admin Panel',
|
||||
desc: 'Management & Administration Panel',
|
||||
buttons: [{ label: 'Log-in', url: this.seo.getpath() }]
|
||||
})
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ export class NotFoundComponent implements OnInit {
|
||||
this.seo.update({
|
||||
title: '404 | Page Not Found',
|
||||
desc: 'How the hell did you end up here?',
|
||||
suffix: false
|
||||
suffix: false,
|
||||
buttons: [{ label: 'Visit Homepage', url: this.seo.getpath('root') }]
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,8 @@ export class PortfolioComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
this.seo.update({
|
||||
title: 'Portfolio',
|
||||
desc: 'This is my portfolio where you can find examples of my designs and other projects!'
|
||||
desc: 'This is my portfolio where you can find examples of my designs and other projects!',
|
||||
buttons: [{ label: 'View Projects', url: this.seo.getpath() }]
|
||||
})
|
||||
this.isNarrow = this.deviceService.isNarrow;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user