Skip to content

Commit 6bfc05b

Browse files
authored
Merge pull request #1 from nelsonr-lopez/feat/sorted-dates
Feat/sorted dates
2 parents 75191a0 + c2153b8 commit 6bfc05b

File tree

3 files changed

+86
-48
lines changed

3 files changed

+86
-48
lines changed

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

src/lib/utils.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DEFAULT_CONFIGURATION } from './constants';
2+
import type { CollectionEntry } from 'astro:content';
23

34
export const formatDate = (date: Date) => {
45
const formatter = new Intl.DateTimeFormat('en-US', {
@@ -7,16 +8,29 @@ export const formatDate = (date: Date) => {
78
day: 'numeric',
89
timeZone: 'UTC', // Default to UTC to prevent timezone issues
910
});
10-
11+
1112
// Ensure we're parsing the date correctly
1213
return formatter.format(new Date(date));
13-
}
14+
};
1415

15-
export const generateAbsoluteUrl = (path: string) => DEFAULT_CONFIGURATION.baseUrl.concat(path);
16+
export const generateAbsoluteUrl = (path: string) =>
17+
DEFAULT_CONFIGURATION.baseUrl.concat(path);
1618

1719
export const isDevelopment = () => import.meta.env.MODE === 'development';
1820

1921
export const includeDraft = (draft: boolean) => {
2022
if (isDevelopment()) return true;
2123
return draft !== true;
22-
};
24+
};
25+
26+
export const sortJobsByDate = (jobs: CollectionEntry<'jobs'>[]) => {
27+
// Convert "Now" to current year, otherwise returns the year as is
28+
const getEndYear = (job: CollectionEntry<'jobs'>) =>
29+
job.data.to === 'Now' ? new Date().getFullYear() : job.data.to;
30+
31+
return jobs.sort((current, next) => {
32+
// Compare end years first, then fall back to start years if end years are equal
33+
const [currentEnd, nextEnd] = [getEndYear(current), getEndYear(next)];
34+
return nextEnd - currentEnd || next.data.from - current.data.from;
35+
});
36+
};

src/pages/index.astro

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import Author from '@/components/ui/Author.astro';
66
import { DEFAULT_CONFIGURATION } from '@/lib/constants';
77
import WorkExperience from '@/components/ui/WorkExperience.astro';
88
import Talk from '@/components/ui/Talk.astro';
9+
import { sortJobsByDate } from '@/lib/utils';
910
1011
const entry = await getEntry('pages', 'homepage');
1112
const { Content } = await render(entry);
1213
1314
const links = await getCollection('links');
1415
const jobs = await getCollection('jobs');
16+
const sortedJobs = sortJobsByDate(jobs);
1517
const talks = await getCollection('talks');
1618
---
1719

@@ -33,47 +35,66 @@ const talks = await getCollection('talks');
3335
</div>
3436
</Container>
3537
</section>
36-
{ links.length > 0 && (
37-
<section class="py-8">
38-
<Container>
39-
<div class="flex flex-col gap-5">
40-
<span class="text-headings">Contact</span>
41-
<ul class="flex flex-col gap-3">
42-
{links.map((link) => (
43-
<li class="py-0.5">
44-
<div class="flex items-center gap-5">
45-
<span class="min-w-28 text-muted-foreground">{link.data.label}</span>
46-
<a class="text-headings font-medium" rel="noopener noreferrer" target="_blank" href={link.data.url}>{link.data.name}</a>
47-
</div>
48-
</li>
49-
))}
50-
</ul>
51-
</div>
52-
</Container>
53-
</section>
54-
)}
55-
{ jobs.length > 0 && (
56-
<section class="py-6">
57-
<Container>
58-
<div class="flex flex-col gap-5">
59-
<span class="text-headings">Work Experience</span>
60-
<ul class="flex flex-col gap-8">
61-
{jobs.map((job) => <WorkExperience entry={job} />)}
62-
</ul>
63-
</div>
64-
</Container>
65-
</section>
66-
)}
67-
{talks.length > 0 && (
68-
<section class="py-6">
69-
<Container>
70-
<div class="flex flex-col gap-5">
71-
<span class="text-headings">Speaking</span>
72-
<ul class="flex flex-col gap-8">
73-
{talks.map((talk) => <Talk entry={talk} />)}
74-
</ul>
75-
</div>
76-
</Container>
77-
</section>
78-
)}
79-
</BaseLayout>
38+
{
39+
links.length > 0 && (
40+
<section class="py-8">
41+
<Container>
42+
<div class="flex flex-col gap-5">
43+
<span class="text-headings">Contact</span>
44+
<ul class="flex flex-col gap-3">
45+
{links.map((link) => (
46+
<li class="py-0.5">
47+
<div class="flex items-center gap-5">
48+
<span class="min-w-28 text-muted-foreground">
49+
{link.data.label}
50+
</span>
51+
<a
52+
class="text-headings font-medium"
53+
rel="noopener noreferrer"
54+
target="_blank"
55+
href={link.data.url}
56+
>
57+
{link.data.name}
58+
</a>
59+
</div>
60+
</li>
61+
))}
62+
</ul>
63+
</div>
64+
</Container>
65+
</section>
66+
)
67+
}
68+
{
69+
sortedJobs.length > 0 && (
70+
<section class="py-6">
71+
<Container>
72+
<div class="flex flex-col gap-5">
73+
<span class="text-headings">Work Experience</span>
74+
<ul class="flex flex-col gap-8">
75+
{sortedJobs.map((job) => (
76+
<WorkExperience entry={job} />
77+
))}
78+
</ul>
79+
</div>
80+
</Container>
81+
</section>
82+
)
83+
}
84+
{
85+
talks.length > 0 && (
86+
<section class="py-6">
87+
<Container>
88+
<div class="flex flex-col gap-5">
89+
<span class="text-headings">Speaking</span>
90+
<ul class="flex flex-col gap-8">
91+
{talks.map((talk) => (
92+
<Talk entry={talk} />
93+
))}
94+
</ul>
95+
</div>
96+
</Container>
97+
</section>
98+
)
99+
}
100+
</BaseLayout>

0 commit comments

Comments
 (0)