Skip to content

Commit b93a420

Browse files
committed
refactor: improve SEO
1 parent 774638b commit b93a420

File tree

4 files changed

+97
-38
lines changed

4 files changed

+97
-38
lines changed

angular-hub/src/app/pages/communities/index.page.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component } from '@angular/core';
22
import { CommunityCardComponent } from '../../components/cards/community-card.component';
33
import { toSignal } from '@angular/core/rxjs-interop';
44
import { injectLoad, RouteMeta } from '@analogjs/router';
5-
import { HeaderService } from '../../services/header.service';
65
import { load } from './index.server';
6+
import { Title } from '@angular/platform-browser';
7+
import { JsonLdService } from '../../services/json-ld.service';
78

89
export const routeMeta: RouteMeta = {
9-
title: 'ANGULAR HUB - Curated list of Angular communities',
1010
meta: [
1111
{
1212
name: 'description',
1313
content: 'Curated list of Angular communities',
1414
},
1515
],
16-
data: {
17-
header: 'Communities',
18-
},
1916
};
2017

2118
@Component({
@@ -39,14 +36,40 @@ export const routeMeta: RouteMeta = {
3936
}
4037
</ul>
4138
`,
42-
styles: ``,
4339
})
44-
export default class EvenementsComponent {
40+
export default class CommunitiesComponent {
4541
communities = toSignal(injectLoad<typeof load>(), { requireSync: true });
4642

47-
@Input() set header(header: string) {
48-
this.headerService.setHeaderTitle(header);
43+
constructor(
44+
private title: Title,
45+
private jsonldService: JsonLdService,
46+
) {
47+
this.title.setTitle('Angular HUB - Communities');
48+
this.jsonldService.updateJsonLd(this.setJsonLd());
4949
}
5050

51-
constructor(private readonly headerService: HeaderService) {}
51+
setJsonLd() {
52+
return {
53+
'@context': 'https://schema.org',
54+
'@type': 'ItemList',
55+
itemListElement: this.communities().map((community, index) => ({
56+
'@type': 'ListItem',
57+
position: index + 1,
58+
item: {
59+
'@type': 'Organization',
60+
name: community.name,
61+
url: community.url,
62+
...(community.location
63+
? {
64+
address: {
65+
'@type': 'PostalAddress',
66+
addressLocality: community.location,
67+
},
68+
}
69+
: {}),
70+
knowsAbout: 'Angular',
71+
},
72+
})),
73+
};
74+
}
5275
}

angular-hub/src/app/pages/index.page.ts

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Component, computed, inject, Input, signal } from '@angular/core';
1+
import { Component, computed, signal } from '@angular/core';
22
import { RouterLink, RouterLinkActive } from '@angular/router';
3-
import { HeaderService } from '../services/header.service';
43
import { toSignal } from '@angular/core/rxjs-interop';
5-
import { injectLoad } from '@analogjs/router';
4+
import { injectLoad, RouteMeta } from '@analogjs/router';
65
import { load } from './index.server';
76
import { EventCardComponent } from '../components/cards/event-card.component';
87
import { CalendarModule } from 'primeng/calendar';
@@ -11,9 +10,20 @@ import { isSameDay } from 'date-fns';
1110
import { ButtonModule } from 'primeng/button';
1211
import { DropdownModule } from 'primeng/dropdown';
1312
import { InputSwitchModule } from 'primeng/inputswitch';
13+
import { Title } from '@angular/platform-browser';
14+
import { JsonLdService } from '../services/json-ld.service';
15+
16+
export const routeMeta: RouteMeta = {
17+
meta: [
18+
{
19+
name: 'description',
20+
content: 'Curated list of Angular Events',
21+
},
22+
],
23+
};
1424

1525
@Component({
16-
selector: 'app-home',
26+
selector: 'app-events',
1727
standalone: true,
1828
template: `
1929
<aside
@@ -86,9 +96,7 @@ import { InputSwitchModule } from 'primeng/inputswitch';
8696
InputSwitchModule,
8797
],
8898
})
89-
export default class HomeComponent {
90-
#headerService = inject(HeaderService);
91-
99+
export default class EventsComponent {
92100
events = toSignal(injectLoad<typeof load>(), { requireSync: true });
93101
date = signal(undefined);
94102
selectedLanguage = signal(null);
@@ -112,7 +120,52 @@ export default class HomeComponent {
112120
return Array.from(new Set(this.events().map((event) => event.language)));
113121
});
114122

115-
@Input() set header(header: string) {
116-
this.#headerService.setHeaderTitle(header);
123+
constructor(
124+
private title: Title,
125+
private jsonldService: JsonLdService,
126+
) {
127+
this.title.setTitle('Angular HUB - Events');
128+
this.jsonldService.updateJsonLd(this.setJsonLd());
129+
}
130+
131+
setJsonLd() {
132+
return {
133+
'@context': 'https://schema.org',
134+
'@type': 'ItemList',
135+
itemListElement: this.events().map((event, index) => ({
136+
'@type': 'ListItem',
137+
position: index + 1,
138+
item: {
139+
'@type': 'Event',
140+
name: event.name,
141+
url: event.url,
142+
startDate: event.date,
143+
...(event.location
144+
? {
145+
location: {
146+
'@type': 'Place',
147+
name: event.location,
148+
},
149+
}
150+
: {}),
151+
...(event.isRemote
152+
? {
153+
location: {
154+
'@type': 'VirtualLocation',
155+
name: 'Online',
156+
},
157+
}
158+
: {}),
159+
...(event.language
160+
? {
161+
inLanguage: {
162+
'@type': 'Language',
163+
name: event.language,
164+
},
165+
}
166+
: {}),
167+
},
168+
})),
169+
};
117170
}
118171
}

angular-hub/src/app/pages/podcasts/index.page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class PodcastsComponent {
4848
private title: Title,
4949
private jsonldService: JsonLdService,
5050
) {
51-
this.title.setTitle('Angular Hub - Podcasts');
51+
this.title.setTitle('Angular HUB - Podcasts');
5252
this.jsonldService.updateJsonLd(this.setJsonLd());
5353
}
5454

angular-hub/src/app/services/header.service.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)