File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { getCollection , type CollectionEntry } from 'astro:content' ;
2+ import type { Lang } from './i18n' ;
3+
4+ export type BlogEntry = CollectionEntry < 'blog' > ;
5+
6+ export async function getPublishedPosts ( lang : Lang ) : Promise < BlogEntry [ ] > {
7+ const posts = await getCollection ( 'blog' ) ;
8+ return posts
9+ . filter ( ( post ) => post . data . lang === lang && ! post . data . draft )
10+ . sort (
11+ ( a , b ) =>
12+ b . data . publishedAt . getTime ( ) - a . data . publishedAt . getTime ( ) ,
13+ ) ;
14+ }
15+
16+ export async function getPostBySlug (
17+ lang : Lang ,
18+ slug : string ,
19+ ) : Promise < BlogEntry | undefined > {
20+ const posts = await getCollection ( 'blog' ) ;
21+ const post = posts . find (
22+ ( entry ) => entry . data . lang === lang && entry . data . slug === slug ,
23+ ) ;
24+ if ( ! post || post . data . draft ) return undefined ;
25+ return post ;
26+ }
Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ export const ui = {
9999 sessions : 'Aulas' ,
100100 sessionsAnchor : '#sessoes' ,
101101 } ,
102+ blog : {
103+ title : 'Blog' ,
104+ breadcrumb : 'Blog' ,
105+ publishedAt : 'Publicado em' ,
106+ tags : 'Tags' ,
107+ } ,
102108 project : {
103109 title : 'Projeto Prático' ,
104110 heroLabel : 'Mão na massa' ,
@@ -233,6 +239,12 @@ export const ui = {
233239 sessions : 'Lessons' ,
234240 sessionsAnchor : '#sessions' ,
235241 } ,
242+ blog : {
243+ title : 'Blog' ,
244+ breadcrumb : 'Blog' ,
245+ publishedAt : 'Published' ,
246+ tags : 'Tags' ,
247+ } ,
236248 project : {
237249 title : 'Hands-on Project' ,
238250 heroLabel : 'Hands-on' ,
@@ -323,6 +335,12 @@ export function getSessionHref(lang: Lang, slug: string): string {
323335 return withBase ( `${ prefix } sessions/${ slug } ` ) ;
324336}
325337
338+ export function getBlogHref ( lang : Lang , slug ?: string ) : string {
339+ const prefix = lang === defaultLang ? '' : `${ languages [ lang ] . pathPrefix } /` ;
340+ const base = `${ prefix } blog` ;
341+ return slug ? withBase ( `${ base } /${ slug } ` ) : withBase ( `${ base } /` ) ;
342+ }
343+
326344const projectSlugs : Record < Lang , string > = {
327345 'pt-BR' : 'projeto' ,
328346 en : 'project' ,
You can’t perform that action at this time.
0 commit comments