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

+28 -7
View File
@@ -1,11 +1,15 @@
import {AfterViewInit, Component, ElementRef, HostListener, OnInit, ViewChild, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {
AfterViewInit, Component, ElementRef, HostListener, OnInit, ViewChild, ViewEncapsulation, ChangeDetectionStrategy,
inject, PLATFORM_ID
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import {ViewportService} from '../shared/services/viewport.service';
import {Title} from '@angular/platform-browser';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {NgStyle} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {TerminalEmulatorComponent} from '../shared/terminal-emulator/terminal-emulator.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-about',
@@ -22,6 +26,7 @@ import {TerminalEmulatorComponent} from '../shared/terminal-emulator/terminal-em
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit, AfterViewInit {
private platformId = inject(PLATFORM_ID);
isNarrow: boolean = false;
terminalShouldBoot: boolean = false;
@@ -29,22 +34,36 @@ export class AboutComponent implements OnInit, AfterViewInit {
constructor(
private deviceService: ViewportService,
private titleService: Title
private seo: SeoService,
) {
}
ngOnInit() {
this.titleService.setTitle('itzMiney\'s Home');
this.seo.update({
title: 'itzMiney\'s Home',
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' }
]
});
this.isNarrow = this.deviceService.isNarrow;
}
ngAfterViewInit() {
this.checkTerminalTrigger();
if (isPlatformBrowser(this.platformId)) {
this.checkTerminalTrigger();
}
}
@HostListener('window:scroll')
onWindowScroll() {
this.checkTerminalTrigger();
if (isPlatformBrowser(this.platformId)) {
this.checkTerminalTrigger();
}
}
private checkTerminalTrigger() {
@@ -58,6 +77,8 @@ export class AboutComponent implements OnInit, AfterViewInit {
}
scrollDown() {
document.getElementById('content')?.scrollIntoView({behavior: 'smooth'});
if (isPlatformBrowser(this.platformId)) {
document.getElementById('content')?.scrollIntoView({behavior: 'smooth'});
}
}
}
+7 -3
View File
@@ -2,11 +2,11 @@ import {Component, OnDestroy, OnInit, ChangeDetectionStrategy} from '@angular/co
import {Router, RouterLink} from '@angular/router';
import {ArticleService} from '../shared/services/article.service';
import {UserService} from '../shared/services/user.service';
import {SeoService} from '../shared/services/seo.service';
import {NgClass, NgStyle, TitleCasePipe} from '@angular/common';
import {Observer, Subscription, interval} from 'rxjs';
import {FormsModule, NgForm} from '@angular/forms';
import {ViewportService} from '../shared/services/viewport.service';
import {Title} from '@angular/platform-browser';
import {ModalComponent} from '../shared/modal/modal.component';
import {AuthService} from '../shared/services/auth.service';
import {ShortenerComponent} from '../shared/shortener/shortener.component';
@@ -89,13 +89,17 @@ export class AdminComponent implements OnInit, OnDestroy {
private articleService: ArticleService,
private userService: UserService,
private router: Router,
private seo: SeoService,
private deviceService: ViewportService,
private titleService: Title,
protected authService: AuthService
) {}
ngOnInit() {
this.titleService.setTitle('Admin Panel | itzMiney')
this.seo.update({
title: 'Admin Panel',
desc: 'Management & Administration Panel'
});
this.isNarrow = this.deviceService.isNarrow;
this.startTokenValidation();
this.loadArticles();
+12
View File
@@ -0,0 +1,12 @@
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
import { provideServerRendering, withRoutes } from '@angular/ssr';
import { appConfig } from './app.config';
import { serverRoutes } from './app.routes.server';
const serverConfig: ApplicationConfig = {
providers: [
provideServerRendering(withRoutes(serverRoutes))
]
};
export const config = mergeApplicationConfig(appConfig, serverConfig);
+1 -1
View File
@@ -43,6 +43,6 @@ export const appConfig: ApplicationConfig = {
deps: [HttpClient]
}
})
),
), provideClientHydration(),
]
};
+8
View File
@@ -0,0 +1,8 @@
import { RenderMode, ServerRoute } from '@angular/ssr';
export const serverRoutes: ServerRoute[] = [
{
path: '**',
renderMode: RenderMode.Server
}
];
@@ -1,8 +1,8 @@
import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {DatePipe, NgClass, NgStyle} from '@angular/common';
import {ArticleService} from '../../shared/services/article.service';
import { SeoService } from '../../shared/services/seo.service';
import {ActivatedRoute} from '@angular/router';
import {Title} from '@angular/platform-browser';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../../shared/parallax/parallax.component';
import {MarkdownModule} from 'ngx-markdown';
@@ -52,7 +52,7 @@ export class ArticlePageComponent implements OnInit {
constructor(
private articleService: ArticleService,
private titleService: Title,
private seo: SeoService,
private route: ActivatedRoute,
private viewportService: ViewportService
) {
@@ -69,7 +69,9 @@ export class ArticlePageComponent implements OnInit {
this.isNarrow = this.viewportService.isNarrow;
if (!slug) {
this.titleService.setTitle('Error | itzMiney');
this.seo.update({ title: 'Error', desc: 'Page not found' });
this.error = true;
this.loading = false;
return;
}
@@ -79,13 +81,23 @@ export class ArticlePageComponent implements OnInit {
this.article = null;
this.loading = false;
this.error = true;
this.seo.update({
title: '404 | Article Not Found',
desc: 'The requested article could not be found.',
suffix: false
});
return;
}
this.article = article;
this.renderedContent = this.transformCustomBlocks(article.content);
this.titleService.setTitle(`${article.title} | itzMiney`);
this.loading = false;
this.seo.update({
title: article.title,
desc: article.content.substring(0, 150).replace(/[#*`_]/g, '') + '...', // Clean excerpt for description
img: article.thumb_url || undefined
});
},
error: (error) => {
console.error('Error fetching article:', error);
@@ -94,6 +106,11 @@ export class ArticlePageComponent implements OnInit {
if (error.status === 404) {
this.error = true;
this.seo.update({
title: '404 | Article Not Found',
desc: 'The requested article could not be found.',
suffix: false
});
}
}
});
+29 -19
View File
@@ -12,27 +12,37 @@
</div>
<hr class="rounded">
<div class="blog-container">
@if (articles$ | async; as articles) {
<div>
@for (article of articles.slice(); track article) {
<div (click)="navigateToArticle(article.slug)" class="article-card" [ngClass]="{ 'narrow': isNarrow }">
<img
class="article-card-thumb"
[src]="article.thumb_url || defaultThumbUrl"
[alt]="article.title + ' thumbnail'"
(error)="onThumbError($event)"
[ngClass]="{ 'narrow': isNarrow}"
/>
<div class="article-card-content">
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
<p>{{ truncateContent(article.content, 80) }}</p>
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
</div>
</div>
}
@if (hasError) {
<div class="error-state">
<h2>Error: Couldn't fetch articles!</h2>
</div>
} @else {
<h2>{{ 'ARTICLES_NONE' | translate }}</h2>
@if (articles$ | async; as articles) {
@if (articles.length === 0) {
<div class="empty-state">
<h2>{{ 'ARTICLES_NONE' | translate }}</h2>
</div>
} @else {
<div>
@for (article of articles.slice(); track article) {
<div (click)="navigateToArticle(article.slug)" class="article-card" [ngClass]="{ 'narrow': isNarrow }">
<img
class="article-card-thumb"
[src]="article.thumb_url || defaultThumbUrl"
[alt]="article.title + ' thumbnail'"
(error)="onThumbError($event)"
[ngClass]="{ 'narrow': isNarrow}"
/>
<div class="article-card-content">
<h2>{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}</h2>
<p>{{ truncateContent(article.content, 80) }}</p>
<p><small>By {{ article.authorName }} | {{ article.createdAt | date: 'dd/MM/yy, HH:mm' }}</small></p>
</div>
</div>
}
</div>
}
}
}
</div>
</div>
+17 -5
View File
@@ -3,10 +3,11 @@ import {ViewportService} from '../shared/services/viewport.service'
import {DatePipe, AsyncPipe, SlicePipe, NgStyle, NgClass} from '@angular/common';
import { ArticleService } from '../shared/services/article.service';
import { Router } from '@angular/router';
import {Observable} from 'rxjs';
import {Title} from '@angular/platform-browser';
import {Observable, of} from 'rxjs';
import {catchError} from 'rxjs/operators';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-blog',
@@ -25,6 +26,7 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
})
export class BlogComponent implements OnInit {
articles$: Observable<any[]> | undefined;
hasError: boolean = false;
isNarrow: boolean = false;
readonly defaultThumbUrl = '/assets/ogimg.png';
@@ -32,13 +34,23 @@ export class BlogComponent implements OnInit {
private deviceService: ViewportService,
private articleService: ArticleService,
private router: Router,
private titleService: Title
private seo: SeoService
) {}
ngOnInit() {
this.titleService.setTitle('Blog | itzMiney')
this.seo.update({
title: 'Blog',
desc: 'I post updates on the stuff I do here! (sometimes)'
});
this.isNarrow = this.deviceService.isNarrow;
this.articles$ = this.articleService.getAllArticles();
this.articles$ = this.articleService.getAllArticles().pipe(
catchError((err) => {
console.error('Failed to fetch articles from API:', err);
this.hasError = true;
return of([]);
})
);
}
onThumbError(event: Event): void {
+6 -3
View File
@@ -3,8 +3,8 @@ import {AuthService} from '../shared/services/auth.service';
import {Router} from '@angular/router';
import {FormsModule} from '@angular/forms';
import {ViewportService} from '../shared/services/viewport.service';
import { Title } from '@angular/platform-browser';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-login',
@@ -27,11 +27,14 @@ export class LoginComponent implements OnInit {
private authService: AuthService,
private router: Router,
private deviceService: ViewportService,
private titleService: Title,
private seo: SeoService,
) {}
ngOnInit() {
this.titleService.setTitle('Login | itzMiney')
this.seo.update({
title:'Login',
desc: 'Admin Panel Login'
})
this.isNarrow = this.deviceService.isNarrow;
if (this.authService.token) {
+7 -3
View File
@@ -1,6 +1,6 @@
import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-not-found',
@@ -15,11 +15,15 @@ import {ParallaxComponent} from '../shared/parallax/parallax.component';
export class NotFoundComponent implements OnInit {
isNarrow: boolean = false;
constructor(
private titleService: Title,
private seo: SeoService,
) {
}
ngOnInit() {
this.titleService.setTitle('404 | Page Not Found')
this.seo.update({
title: '404 | Page Not Found',
desc: 'How the hell did you end up here?',
suffix: false
})
}
}
+6 -3
View File
@@ -1,10 +1,10 @@
import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {ViewportService} from '../shared/services/viewport.service';
import { CommonModule, NgStyle } from '@angular/common';
import {Title} from '@angular/platform-browser';
import {AudioPlayerComponent} from '../shared/audio-player/audio-player.component';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-portfolio',
@@ -47,11 +47,14 @@ export class PortfolioComponent implements OnInit {
isNarrow: boolean = false;
constructor(
private deviceService: ViewportService,
private titleService: Title,
private seo: SeoService,
) {}
ngOnInit() {
this.titleService.setTitle('Portfolio | itzMiney');
this.seo.update({
title: 'Portfolio',
desc: 'This is my portfolio where you can find examples of my designs and other projects!'
})
this.isNarrow = this.deviceService.isNarrow;
}
+6 -3
View File
@@ -1,8 +1,8 @@
import {AfterViewInit, Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {ViewportService} from '../shared/services/viewport.service';
import {Title} from '@angular/platform-browser';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-services',
@@ -22,7 +22,7 @@ export class PrivacyComponent implements OnInit, AfterViewInit {
constructor(
private deviceService: ViewportService,
private titleService: Title,
private seo: SeoService,
) {}
scrollToSection(event: Event, targetId: string): void {
@@ -39,7 +39,10 @@ export class PrivacyComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
this.titleService.setTitle('Privacy Policy | itzMiney');
this.seo.update({
title: 'Privacy Policy',
desc: 'Information about the data collected on this site and how it is used.'
});
this.isNarrow = this.deviceService.isNarrow;
}
+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);
}
}
+6 -3
View File
@@ -1,9 +1,9 @@
import {Component, OnInit, ChangeDetectionStrategy} from '@angular/core';
import {NgStyle} from '@angular/common';
import {ViewportService} from '../shared/services/viewport.service';
import {Title} from '@angular/platform-browser';
import {TranslatePipe} from '@ngx-translate/core';
import {ParallaxComponent} from '../shared/parallax/parallax.component';
import {SeoService} from '../shared/services/seo.service';
@Component({
selector: 'app-socials',
@@ -22,11 +22,14 @@ export class SocialsComponent implements OnInit {
constructor(
private deviceService: ViewportService,
private titleService: Title
private seo: SeoService,
) {}
ngOnInit() {
this.titleService.setTitle('Socials | itzMiney');
this.seo.update({
title: 'Socials',
desc: 'Here you can find links to all the places I exist on!'
})
this.isNarrow = this.deviceService.isNarrow;
}
}
+8
View File
@@ -0,0 +1,8 @@
import { BootstrapContext, bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { config } from './app/app.config.server';
const bootstrap = (context: BootstrapContext) =>
bootstrapApplication(AppComponent, config, context);
export default bootstrap;
+95
View File
@@ -0,0 +1,95 @@
import {
AngularNodeAppEngine,
createNodeRequestHandler,
isMainModule,
writeResponseToNodeResponse,
} from '@angular/ssr/node';
import express from 'express';
import { join } from 'node:path';
const browserDistFolder = join(import.meta.dirname, '../browser');
const app = express();
const angularApp = new AngularNodeAppEngine();
app.use(express.json());
/**
* Proxy /api requests to backend API server on port 7020
*/
app.use('/api', async (req, res) => {
try {
const backendUrl = `http://127.0.0.1:7020${req.originalUrl}`;
const headers = new Headers();
for (const [key, value] of Object.entries(req.headers)) {
if (value && key !== 'host' && key !== 'connection') {
headers.set(key, Array.isArray(value) ? value.join(', ') : value);
}
}
const fetchOptions: RequestInit = {
method: req.method,
headers,
};
if (!['GET', 'HEAD'].includes(req.method)) {
fetchOptions.body = JSON.stringify(req.body);
}
const apiRes = await fetch(backendUrl, fetchOptions);
res.status(apiRes.status);
apiRes.headers.forEach((val, key) => {
res.setHeader(key, val);
});
const buffer = await apiRes.arrayBuffer();
res.send(Buffer.from(buffer));
} catch (err) {
res.status(500).json({ error: 'SSR API Proxy failed', details: String(err) });
}
});
/**
* Serve static files from /browser
*/
app.use(
express.static(browserDistFolder, {
maxAge: '1y',
index: false,
redirect: false,
}),
);
/**
* Handle all other requests by rendering the Angular application.
*/
app.use((req, res, next) => {
angularApp
.handle(req)
.then((response) =>
response ? writeResponseToNodeResponse(response, res) : next(),
)
.catch(next);
});
/**
* Start the server if this module is the main entry point, or it is ran via PM2.
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
*/
if (isMainModule(import.meta.url) || process.env['pm_id']) {
const port = process.env['PORT'] || 4000;
app.listen(port, (error) => {
if (error) {
throw error;
}
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
/**
* Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions.
*/
export const reqHandler = createNodeRequestHandler(app);