Skip to content

Commit

Permalink
blog: redirect old blog links to news
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Aug 23, 2024
1 parent 87975c3 commit f1b6963
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 60 deletions.
74 changes: 38 additions & 36 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ChangeDetectionStrategy, Component, HostListener, Inject, LOCALE_ID} from '@angular/core';
import {routingAnimation} from "./animation/routing.animation";
import {ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive, RouterOutlet} from "@angular/router";
import {AsyncPipe, DOCUMENT, Location, NgIf, PlatformLocation} from "@angular/common";
import {BehaviorSubject, delay, filter, map, take} from "rxjs";
import {Meta, Title} from "@angular/platform-browser";
import {Language} from "./api/api.domain";
import {IconLogoComponent} from "./icons/icon-logo/icon-logo.component";
import {IconMenuComponent} from "./icons/icon-menu/icon-menu.component";
import {NotificationListComponent} from "@feel/notification";
import { ChangeDetectionStrategy, Component, HostListener, Inject, LOCALE_ID } from '@angular/core';
import { routingAnimation } from "./animation/routing.animation";
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive, RouterOutlet } from "@angular/router";
import { AsyncPipe, DOCUMENT, Location, NgIf, PlatformLocation } from "@angular/common";
import { BehaviorSubject, delay, filter, map, take, tap } from "rxjs";
import { Meta, Title } from "@angular/platform-browser";
import { Language } from "./api/api.domain";
import { IconLogoComponent } from "./icons/icon-logo/icon-logo.component";
import { IconMenuComponent } from "./icons/icon-menu/icon-menu.component";
import { NotificationListComponent } from "@feel/notification";

@Component({
selector: 'app-root',
Expand All @@ -33,6 +33,34 @@ export class AppComponent {
protected enableAnimation = new BehaviorSubject(false);

protected readonly path = this.router.events.pipe(
tap(event => {
if (!(event instanceof NavigationEnd)) {
return;
}

const url = new URL(this.platformLocation.href);
url.protocol = 'https:';
url.search = '';

this.meta.updateTag({ property: 'og:url', content: url.toString() });
this.meta.updateTag({ name: 'twitter:url', content: url.toString() });
this.updateCanonicalUrl(url.toString());
this.updateAlternativeUrl(url.toString());
this.updateCurrentAlternativeUrl(url.toString());
this.updateXDefaultAlternativeUrl(url.toString());

const title = this.route.firstChild?.snapshot?.data?.['title'] || this.route.root.firstChild?.snapshot?.data?.['title'];
if (title) {
this.title.setTitle($localize`${title} | Dresden Internet Exchange`);
this.meta.updateTag({ property: 'og:title', content: $localize`${title} | Dresden Internet Exchange` });
this.meta.updateTag({ name: 'twitter:title', content: $localize`${title} | Dresden Internet Exchange` });
} else {
this.title.setTitle($localize`Dresden Internet Exchange`);
this.meta.updateTag({ property: 'og:title', content: $localize`Dresden Internet Exchange` });
this.meta.updateTag({ name: 'twitter:title', content: $localize`Dresden Internet Exchange` });
}

}),
map(() => this.location.path() || '/'),
);

Expand All @@ -46,32 +74,6 @@ export class AppComponent {
@Inject(DOCUMENT) private readonly dom: Document,
@Inject(LOCALE_ID) private readonly locale: Language,
) {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe(() => {
const url = new URL(this.platformLocation.href);
url.protocol = 'https:';
url.search = '';

this.meta.updateTag({property: 'og:url', content: url.toString()});
this.meta.updateTag({name: 'twitter:url', content: url.toString()});
this.updateCanonicalUrl(url.toString());
this.updateAlternativeUrl(url.toString());
this.updateCurrentAlternativeUrl(url.toString());
this.updateXDefaultAlternativeUrl(url.toString());

const title = this.route.firstChild?.snapshot?.data?.['title'] || this.route.root.firstChild?.snapshot?.data?.['title'];
if (title) {
this.title.setTitle($localize`${title} | Dresden Internet Exchange`);
this.meta.updateTag({property: 'og:title', content: $localize`${title} | Dresden Internet Exchange`});
this.meta.updateTag({name: 'twitter:title', content: $localize`${title} | Dresden Internet Exchange`});
} else {
this.title.setTitle($localize`Dresden Internet Exchange`);
this.meta.updateTag({property: 'og:title', content: $localize`Dresden Internet Exchange`});
this.meta.updateTag({name: 'twitter:title', content: $localize`Dresden Internet Exchange`});
}
});

this.router.events
.pipe(
filter(event => event instanceof NavigationEnd),
Expand Down
44 changes: 26 additions & 18 deletions src/app/pages/blog/blog-post/blog-post.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ChangeDetectionStrategy, Component, SecurityContext} from '@angular/core';
import {BlogService} from "../../../api/blog.service";
import {ActivatedRoute} from "@angular/router";
import {switchMap, tap} from "rxjs";
import {DomSanitizer, Meta, Title} from "@angular/platform-browser";
import {API_URL} from "../../../api/api.domain";
import {CardComponent} from "../../../core/card/card.component";
import {AsyncPipe, DatePipe, NgIf} from "@angular/common";
import { ChangeDetectionStrategy, Component, SecurityContext } from '@angular/core';
import { BlogService } from "../../../api/blog.service";
import { ActivatedRoute, Router } from "@angular/router";
import { catchError, of, switchMap, tap, throwError } from "rxjs";
import { DomSanitizer, Meta, Title } from "@angular/platform-browser";
import { API_URL } from "../../../api/api.domain";
import { CardComponent } from "../../../core/card/card.component";
import { AsyncPipe, DatePipe, NgIf } from "@angular/common";

@Component({
selector: 'app-blog-post',
Expand All @@ -23,34 +23,42 @@ import {AsyncPipe, DatePipe, NgIf} from "@angular/common";
export class BlogPostComponent {

protected readonly post = this.activatedRoute.params.pipe(
switchMap(({slug}) => this.blogService.getBlogPost(slug)),
switchMap(({ slug }) => this.blogService.getBlogPost(slug)),
tap(post => {
this.title.setTitle(`${post.title} | Dresden Internet Exchange`);
this.meta.updateTag({property: 'og:title', content: post.title});
this.meta.updateTag({name: 'twitter:title', content: post.title});
this.meta.updateTag({property: 'og:type', content: 'article'});
this.meta.updateTag({name: "description", content: post.description});
this.meta.updateTag({property: "og:description", content: post.description});
this.meta.updateTag({name: "twitter:description", content: post.description});
this.meta.updateTag({ property: 'og:title', content: post.title });
this.meta.updateTag({ name: 'twitter:title', content: post.title });
this.meta.updateTag({ property: 'og:type', content: 'article' });
this.meta.updateTag({ name: "description", content: post.description });
this.meta.updateTag({ property: "og:description", content: post.description });
this.meta.updateTag({ name: "twitter:description", content: post.description });
this.meta.updateTag({
name: "keywords",
content: 'Dresden Internet Exchange, Dresden, Internet Exchange, DD-IX, ddix, DD-IX Dresden Internet Exchange e.V., ' + post.keywords.join(", ")
});

if (post.image) {
const image = this.buildBlogImageUrl(post.image);
this.meta.updateTag({property: 'og:image', content: image});
this.meta.updateTag({name: 'twitter:image', content: image});
this.meta.updateTag({ property: 'og:image', content: image });
this.meta.updateTag({ name: 'twitter:image', content: image });
}
}),
catchError(error => {
if ("status" in error && error.status === 404) {
this.router.navigateByUrl(`/news/${error["url"].split("/").at(-1)}`);
}

return throwError(() => error);
})
);

constructor(
private readonly blogService: BlogService,
private readonly activatedRoute: ActivatedRoute,
private readonly meta: Meta,
private readonly title: Title,
private readonly sanitizer: DomSanitizer
private readonly sanitizer: DomSanitizer,
private readonly router: Router,
) {
}

Expand Down
12 changes: 6 additions & 6 deletions src/locales/en_devel.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,30 @@
<source><x id="PH" equiv-text="title"/> | Dresden Internet Exchange</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">65</context>
<context context-type="linenumber">54</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">66</context>
<context context-type="linenumber">55</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">67</context>
<context context-type="linenumber">56</context>
</context-group>
</trans-unit>
<trans-unit id="5744023940242558359" datatype="html">
<source>Dresden Internet Exchange</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">69</context>
<context context-type="linenumber">58</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">70</context>
<context context-type="linenumber">59</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">71</context>
<context context-type="linenumber">60</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
Expand Down

0 comments on commit f1b6963

Please sign in to comment.