Skip to content

Commit

Permalink
Merge pull request #255 from valerymelou/feature/published-at
Browse files Browse the repository at this point in the history
feat: sort articles by published at desc
  • Loading branch information
valerymelou authored Jul 27, 2024
2 parents ecff977 + be74c3c commit 6efbcce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions libs/blog/data-access/src/lib/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EntrySkeletonType,
TagLink,
} from 'contentful';
import { Document } from '@contentful/rich-text-types';
import { Asset } from './asset';
import { Tag } from './tag';

Expand All @@ -14,8 +15,9 @@ export class Article {
cover?: Asset;
createdAt = '';
updatedAt = '';
publishedAt = '';
tags: Tag[] = [];
content: any;
content!: Document;

static fromEntry(
entry: Entry<EntrySkeletonType, undefined, string>,
Expand All @@ -25,6 +27,7 @@ export class Article {
article.title = entry.fields['title'] as string;
article.slug = entry.fields['slug'] as string;
article.abstract = entry.fields['abstract'] as string;
article.publishedAt = entry.fields['publishedAt'] as string;
article.createdAt = entry.sys.createdAt;
article.updatedAt = entry.sys.updatedAt;
if (entry.fields['cover'] && assets) {
Expand All @@ -46,7 +49,7 @@ export class Article {
.join(),
});
});
article.content = entry.fields['content'];
article.content = entry.fields['content'] as Document;
return article;
}
}
4 changes: 3 additions & 1 deletion libs/blog/data-access/src/lib/articles.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ import { ArticleService } from './article.service';
export const articlesResolver: ResolveFn<Results<Article>> = () => {
const articleService = inject(ArticleService);

return articleService.get({});
return articleService.get({
order: '-fields.publishedAt',
});
};
4 changes: 2 additions & 2 deletions libs/blog/feature-article/src/lib/blog-article.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<dl>
<dt class="sr-only">Date</dt>
<dd class="top-0 whitespace-nowrap text-sm leading-6">
<time [attr.datetime]="article.createdAt">{{
article.createdAt | date: 'mediumDate'
<time [attr.datetime]="article.publishedAt">{{
article.publishedAt | date: 'mediumDate'
}}</time>
</dd>
</dl>
Expand Down
8 changes: 4 additions & 4 deletions libs/blog/feature-home/src/lib/blog-home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ <h2 class="text-xl lg:max-w-2xl">
>
<dt class="sr-only">Date</dt>
<dd class="whitespace-nowrap text-sm leading-6">
<time [attr.datetime]="article.createdAt">{{
article.createdAt | date: 'mediumDate'
<time [attr.datetime]="article.publishedAt">{{
article.publishedAt | date: 'mediumDate'
}}</time>
</dd>
</dl>
Expand All @@ -60,14 +60,14 @@ <h2 class="text-xl lg:max-w-2xl">
ui-link
[routerLink]="[
'/blog',
(article.createdAt | date: 'YYYY-MM-dd') + '-' + article.slug,
(article.publishedAt | date: 'YYYY-MM-dd') + '-' + article.slug,
]"
>
<span
class="absolute -inset-x-4 -inset-y-2.5 sm:rounded-2xl md:-inset-x-6 md:-inset-y-4"
>
</span>
<span class="relative">Read the article</span>
<span class="relative text-sm">Read the article</span>
</a>
</article>
}
Expand Down

0 comments on commit 6efbcce

Please sign in to comment.