Refactored complex custom meta jank to use Angular SSR instead
This commit is contained in:
1 parent
d291409097
commit
febbc63f35
21 files changed
+1680
-657
No files matched your search
@@ -47,7 +47,7 @@ jobs:
|
||||
set -eux
|
||||
npm run build
|
||||
test -d dist/itzmineydev/browser
|
||||
test -d dist/itzmineydev/meta
|
||||
test -d dist/itzmineydev/server
|
||||
deploy:
|
||||
needs: test-and-build
|
||||
runs-on: self-hosted
|
||||
@@ -86,9 +86,11 @@ jobs:
|
||||
|
||||
rsync -az -e "ssh $SSH_ARGS" ./dist/itzmineydev/ itzmineydev@localhost:"$TARGET_DIR/"
|
||||
|
||||
ssh $SSH_ARGS itzmineydev@localhost "test -d $TARGET_DIR/browser && test -d $TARGET_DIR/meta"
|
||||
ssh $SSH_ARGS itzmineydev@localhost "test -d $TARGET_DIR/browser && test -d $TARGET_DIR/server"
|
||||
ssh $SSH_ARGS itzmineydev@localhost "ln -sfn $TARGET_DIR $CURRENT_LINK"
|
||||
|
||||
ssh $SSH_ARGS itzmineydev@localhost "sudo systemctl restart itzmineydev-ssr"
|
||||
|
||||
echo "Successfully published frontend release $RELEASE_ID"
|
||||
|
||||
- name: Cleanup old releases
|
||||
|
||||
+14
-2
@@ -32,8 +32,20 @@
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/brands.min.css",
|
||||
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/solid.min.css"
|
||||
],
|
||||
"scripts": [
|
||||
]
|
||||
"scripts": [],
|
||||
"server": "src/main.server.ts",
|
||||
"outputMode": "server",
|
||||
"security": {
|
||||
"allowedHosts": [
|
||||
"localhost",
|
||||
"localhost:4000",
|
||||
"itzminey.dev",
|
||||
"*.itzminey.dev"
|
||||
]
|
||||
},
|
||||
"ssr": {
|
||||
"entry": "src/server.ts"
|
||||
}
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
|
||||
Generated
+1301
-584
File diff suppressed because it is too large.
Load diff
+18
-14
@@ -4,19 +4,23 @@
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build && node ./scripts/prerender-meta.js",
|
||||
"watch": "ng build --watch --configuration development"
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"serve:ssr:itzmineydev": "node dist/itzmineydev/server/server.mjs"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/common": "^22.2.3",
|
||||
"@angular/compiler": "^22.2.3",
|
||||
"@angular/core": "^22.2.3",
|
||||
"@angular/forms": "^22.2.3",
|
||||
"@angular/platform-browser": "^22.2.3",
|
||||
"@angular/router": "^22.2.3",
|
||||
"@angular/common": "^22.2.5",
|
||||
"@angular/compiler": "^22.2.5",
|
||||
"@angular/core": "^22.2.5",
|
||||
"@angular/forms": "^22.2.5",
|
||||
"@angular/platform-browser": "^22.2.5",
|
||||
"@angular/platform-server": "^22.2.5",
|
||||
"@angular/router": "^22.2.5",
|
||||
"@angular/ssr": "^22.2.6",
|
||||
"@ngx-translate/core": "^16.0.4",
|
||||
"@ngx-translate/http-loader": "^16.0.1",
|
||||
"express": "^5.1.0",
|
||||
"marked": "^17.0.4",
|
||||
"ngx-markdown": "^22.0.0",
|
||||
"parallax-js": "^3.1.0",
|
||||
@@ -25,14 +29,14 @@
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^22.0.6",
|
||||
"@angular/cli": "^22.0.6",
|
||||
"@angular/compiler-cli": "^22.2.3",
|
||||
"@types/node": "^26.1.1",
|
||||
"@angular/build": "^22.2.6",
|
||||
"@angular/cli": "^22.2.6",
|
||||
"@angular/compiler-cli": "^22.2.5",
|
||||
"@types/express": "^5.0.1",
|
||||
"@types/node": "^22.12.0",
|
||||
"@types/parallax-js": "^3.1.3",
|
||||
"istanbul-lib-instrument": "^6.0.3",
|
||||
"typescript": "~6.0.3"
|
||||
},
|
||||
"overrides": {
|
||||
}
|
||||
"overrides": {}
|
||||
}
|
||||
@@ -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'});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
@@ -43,6 +43,6 @@ export const appConfig: ApplicationConfig = {
|
||||
deps: [HttpClient]
|
||||
}
|
||||
})
|
||||
),
|
||||
), provideClientHydration(),
|
||||
]
|
||||
};
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
+4
-1
@@ -5,10 +5,13 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts"
|
||||
"src/main.ts",
|
||||
"src/main.server.ts",
|
||||
"src/server.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.d.ts"
|
||||
|
||||
Reference in new issue
Block a user