-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
200 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,64 @@ | ||
<script lang="ts"> | ||
import { derived } from 'svelte/store'; | ||
import { displayMonthDuration, displayRange } from '$lib/date'; | ||
import { currentLang, t } from '$i18n'; | ||
import TimelineItem from './timeline-item.svelte'; | ||
import TimelineItem from '$components/about/timeline-item.svelte'; | ||
import type { WorkTimelineItem } from '$types'; | ||
export let section: WorkTimelineItem[]; | ||
const title = section[0].title; | ||
const dateDisplay = derived([currentLang, t], ([currentLang, t]) => { | ||
return (start: string, end: string | undefined) => { | ||
try { | ||
const startDate = new Date(start), | ||
endDate = end ? new Date(end) : undefined; | ||
if (!endDate) { | ||
return `${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(startDate)} - ${t('present')}`; | ||
} | ||
return `${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(startDate)} - ${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(endDate)}`; | ||
} catch (_) { | ||
return t('Invalid date'); | ||
} | ||
const title = section[0].title, | ||
totalRange = { | ||
start: section[section.length - 1].range.start, | ||
end: section[0].range.end | ||
}; | ||
}); | ||
</script> | ||
|
||
<section> | ||
<h1>{title}</h1> | ||
|
||
<div> | ||
{#each section as item} | ||
<TimelineItem | ||
title={item.subtitle} | ||
body={item.body} | ||
date={$dateDisplay(item.range.start, item.range.end)} | ||
/> | ||
{/each} | ||
<h2>{title}</h2> | ||
<p> | ||
{$displayRange(totalRange.start, totalRange.end)} • {$displayMonthDuration( | ||
totalRange.start, | ||
totalRange.end | ||
)} | ||
</p> | ||
</div> | ||
|
||
{#each section as item, i} | ||
<TimelineItem | ||
title={item.subtitle} | ||
body={item.body} | ||
range={item.range} | ||
last={i === section.length - 1} | ||
/> | ||
{/each} | ||
</section> | ||
|
||
<style lang="scss"> | ||
h1 { | ||
@apply mb-3 font-code text-2xl font-bold text-dark transition-colors; | ||
h2 { | ||
@apply pb-1 text-xl font-bold text-dark transition-colors; | ||
} | ||
p { | ||
@apply font-mono text-sm text-dark/80 transition-colors; | ||
} | ||
div { | ||
@apply pb-4; | ||
} | ||
section { | ||
@apply my-6; | ||
div { | ||
@apply flex flex-col; | ||
} | ||
} | ||
:global(.dark) { | ||
h1 { | ||
h2 { | ||
@apply text-white; | ||
} | ||
p { | ||
@apply text-light/80; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* eslint-disable func-call-spacing */ | ||
import { derived } from 'svelte/store'; | ||
|
||
import { currentLang, t } from '$i18n'; | ||
|
||
export const displayRange = derived([currentLang, t], ([currentLang, t]) => { | ||
return (start: string, end: string | undefined) => { | ||
try { | ||
const startDate = new Date(start), | ||
endDate = end ? new Date(end) : undefined; | ||
|
||
if (!endDate) { | ||
return `${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(startDate)} - ${t('present')}`; | ||
} | ||
|
||
return `${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(startDate)} - ${new Intl.DateTimeFormat(currentLang, { | ||
month: 'short', | ||
year: 'numeric' | ||
}).format(endDate)}`; | ||
} catch (_) { | ||
return t('Invalid date'); | ||
} | ||
}; | ||
}); | ||
|
||
export const displayMonthDuration = derived< | ||
typeof t, | ||
(startDate?: string | Date, endDate?: string | Date) => string | ||
>(t, (t) => { | ||
return (startDate?: string | Date, endDate?: string | Date) => { | ||
if (!startDate) { | ||
return t('{month} month', { month: 1 }); | ||
} | ||
|
||
const start = new Date(startDate), | ||
end = endDate ? new Date(endDate) : new Date(); | ||
|
||
let years = end.getFullYear() - start.getFullYear(); | ||
let months = end.getMonth() - start.getMonth(); | ||
|
||
// Adjust for cases where the end month is earlier in the year than the start month | ||
if (months < 0) { | ||
years--; | ||
months += 12; // Add the months that have passed in the current year | ||
} | ||
|
||
// Consolidate total duration into years and months | ||
years += Math.floor(months / 12); | ||
months %= 12; | ||
|
||
let yearString = '', | ||
monthString = ''; | ||
|
||
if (years > 0) { | ||
if (years === 1) { | ||
yearString = t('{year} year', { year: years }); | ||
} else { | ||
yearString = t('{year} years', { year: years }); | ||
} | ||
} | ||
|
||
if (months > 0) { | ||
if (months === 1) { | ||
monthString = t('{month} month', { month: months }); | ||
} else { | ||
monthString = t('{month} months', { month: months }); | ||
} | ||
} | ||
|
||
// Handle the case where the difference is less than one month | ||
if (years > 0 && months > 0) { | ||
monthString = t('{month} month', { month: 1 }); | ||
} | ||
|
||
return `${yearString}${yearString && monthString ? ' ' : ''}${monthString}`; | ||
}; | ||
}); |