1
1
---
2
- import { CollectionEntry } from ' astro:content'
2
+ import type { CollectionEntry , InferEntrySchema } from ' astro:content'
3
3
import { formatDate } from ' ../logics'
4
4
import { slugToLocaleData } from ' ../utils/slugs'
5
5
import { ensureLeadingSlash , stripLeadingSlash } from ' ../utils/path'
6
- import { getLocaleRoutes , Route , VitessePagesEntry } from ' ../utils/routing'
6
+ import { getLocaleRoutes , type Route } from ' ../utils/routing'
7
7
import { generateVitessePageRouteData } from ' ../utils/vitesse-page'
8
8
9
9
export interface Props {
10
10
startsWith? : string
11
11
items? : CollectionEntry <' pages' >[' data' ][]
12
12
}
13
13
14
- let { startsWith = ' posts/' , items : pagesProps } = Astro .props
14
+ const { startsWith = ' posts/' , items : pagesProps } = Astro .props
15
15
16
16
let pagesCollection: Route [] = []
17
17
@@ -23,29 +23,29 @@ if (!pagesProps?.length) {
23
23
pagesCollection = routes
24
24
}
25
25
26
- const newPagePros = [ ... ( pagesProps || [])]. map ( async ( page ) => {
27
- const { entry, slug, id, entryMeta, dir, lang, locale } = await generateVitessePageRouteData ( {
28
- url: Astro . url ,
29
- props: {
30
- frontmatter: page ,
31
- lang: localeData . locale ,
32
- } ,
33
- })
34
-
35
- return {
36
- entry ,
37
- slug ,
38
- id ,
39
- entryMeta ,
40
- dir ,
41
- lang ,
42
- locale ,
43
- }
44
- })
45
-
46
- pagesProps = await Promise . all ( newPagePros )
47
-
48
- const pages: Route [] = [... ((pagesProps .length ? pagesProps : null ) || pagesCollection )]
26
+ const newPagePros: Route [] = await Promise . all (
27
+ [ ... ( pagesProps || [])]. map ( async ( page ) : Promise < Route > => {
28
+ const { entry, slug, id, entryMeta, dir, lang, locale } = await generateVitessePageRouteData ({
29
+ url: Astro . url ,
30
+ props: {
31
+ frontmatter: page ,
32
+ lang: localeData . locale ,
33
+ },
34
+ })
35
+
36
+ return {
37
+ entry ,
38
+ slug ,
39
+ id ,
40
+ entryMeta ,
41
+ dir ,
42
+ lang ,
43
+ locale ,
44
+ }
45
+ }),
46
+ )
47
+
48
+ const pages: Route [] = [... ((newPagePros .length ? newPagePros : null ) || pagesCollection )]
49
49
.sort ((a , b ) => + new Date (b .entry .data .date ! ) - + new Date (a .entry .data .date ! ))
50
50
.map ((page ) => ({
51
51
... page ,
@@ -61,11 +61,11 @@ const pages: Route[] = [...((pagesProps.length ? pagesProps : null) || pagesColl
61
61
const getYear = (a : Date | string | number ) => new Date (a ).getFullYear ()
62
62
const isFuture = (a ? : Date | string | number ) => a && new Date (a ) > new Date ()
63
63
const isSameYear = (a ? : Date | string | number , b ? : Date | string | number ) => a && b && getYear (a ) === getYear (b )
64
- function isSameGroup(a : VitessePagesEntry , b ? : VitessePagesEntry ) {
64
+ function isSameGroup(a : InferEntrySchema < ' pages ' > , b ? : InferEntrySchema < ' pages ' > ) {
65
65
return isFuture (a .date ) === isFuture (b ?.date ) && isSameYear (a .date , b ?.date )
66
66
}
67
67
68
- function getGroupName(p : VitessePagesEntry ) {
68
+ function getGroupName(p : InferEntrySchema < ' pages ' > ) {
69
69
if (isFuture (p .date )) return ' Upcoming'
70
70
return getYear (p .date ! )
71
71
}
@@ -121,8 +121,8 @@ function getGroupName(p: VitessePagesEntry) {
121
121
href = { data .path }
122
122
class = " item block font-normal mb-6 mt-2 no-underline"
123
123
{ ... {
124
- target: data .path .startsWith (' http' ) ? ' _blank' : undefined ,
125
- rel: data .path .startsWith (' http' ) ? ' noopener noreferrer' : undefined ,
124
+ target: data .path ? .startsWith (' http' ) ? ' _blank' : undefined ,
125
+ rel: data .path ? .startsWith (' http' ) ? ' noopener noreferrer' : undefined ,
126
126
}}
127
127
>
128
128
<li class = " no-underline" flex = " ~ col md:row gap-2 md:items-center" >
0 commit comments