Skip to content

Commit

Permalink
feat: show article series
Browse files Browse the repository at this point in the history
  • Loading branch information
d-koppenhagen committed Jan 1, 2024
1 parent 667cff7 commit 0276fc5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
15 changes: 15 additions & 0 deletions src/app/components/series-list/series-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<section class="article-series">
<h2 class="sub-heading">Artikelserie</h2>
<ol class="alt">
@for (related of relatedPosts; track related.slug) {
<li>
<a
[routerLink]="['..', related.slug]"
routerLinkActive="current"
ariaCurrentWhenActive="page"
>{{ related.attributes.title }}</a
>
</li>
}
</ol>
</section>
7 changes: 7 additions & 0 deletions src/app/components/series-list/series-list.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import '../../../sass/libs/vars';

.article-series {
li:has(.current:not(:hover)) {
background-color: lighten($c12, 3%);
}
}
23 changes: 23 additions & 0 deletions src/app/components/series-list/series-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SeriesListComponent } from './series-list.component';

describe('SeriesListComponent', () => {
let component: SeriesListComponent;
let fixture: ComponentFixture<SeriesListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SeriesListComponent]
})
.compileComponents();

fixture = TestBed.createComponent(SeriesListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
23 changes: 23 additions & 0 deletions src/app/components/series-list/series-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { injectContentFiles } from '@analogjs/content';
import { Component, Input } from '@angular/core';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { PostAttributes } from '../../types';

@Component({
selector: 'dk-series-list',
standalone: true,
imports: [RouterLink, RouterLinkActive],
templateUrl: './series-list.component.html',
styleUrl: './series-list.component.scss',
})
export class SeriesListComponent {
@Input({ required: true }) series!: string;

readonly allPosts = injectContentFiles<PostAttributes>();

get relatedPosts() {
return this.allPosts.filter(
(p) => p.attributes.series && p.attributes.series === this.series,
);
}
}
20 changes: 4 additions & 16 deletions src/app/pages/blog/[slug].page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MetaService } from '../../meta.service';

import { PostAttributes } from '../../types';
import { SharePostComponent } from '../../components/share-post/share-post.component';
import { SeriesListComponent } from '../../components/series-list/series-list.component';

@Component({
standalone: true,
Expand All @@ -20,6 +21,7 @@ import { SharePostComponent } from '../../components/share-post/share-post.compo
DatePipe,
RouterLink,
SharePostComponent,
SeriesListComponent,
],
template: `
<article class="wrapper alt">
Expand Down Expand Up @@ -109,22 +111,8 @@ import { SharePostComponent } from '../../components/share-post/share-post.compo
}
</section>
}
@if (post.attributes.related) {
<section class="article-series">
<h2 class="sub-heading">Artikelserie</h2>
<ol class="alt">
@for (related of post.attributes.related; track related.slug) {
<li
[routerLink]="related.slug"
[class.current]="post.slug === related.slug"
>
<a [routerLink]="['..', related.slug]">{{
related.title
}}</a>
</li>
}
</ol>
</section>
@if (post.attributes.series) {
<dk-series-list [series]="post.attributes.series"></dk-series-list>
}
<section class="blog-content">
Expand Down
6 changes: 0 additions & 6 deletions src/app/pages/blog/slug.page.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ h2.sub-heading {
gap: 0.2rem;
}

.article-series {
.current {
background-color: lighten($c01, 3%);
}
}

.published-at,
.external-links,
.edit-on-github {
Expand Down

0 comments on commit 0276fc5

Please sign in to comment.