diff --git a/src/lib/components/CountdownClock.svelte b/src/lib/components/CountdownClock.svelte new file mode 100644 index 0000000..71c95c9 --- /dev/null +++ b/src/lib/components/CountdownClock.svelte @@ -0,0 +1,99 @@ + + +
+ {#if daysLeft > 0} +
{dateDurationLong.format({ days: daysLeft })}
+ {/if} +
+
{hoursLeft[0]}
+
{hoursLeft[1]}
+
:
+
{minutesLeft[0]}
+
{minutesLeft[1]}
+
:
+
{secondsLeft[0]}
+
{secondsLeft[1]}
+
+
+ + diff --git a/src/lib/util/Blogs.ts b/src/lib/util/Blogs.ts index 5878e26..e10d18d 100644 --- a/src/lib/util/Blogs.ts +++ b/src/lib/util/Blogs.ts @@ -1,6 +1,28 @@ export const THUMBNAIL_DEFAULT = "https://teasanctuary.ru/common/background-day.webp"; export const BLOG_POST_FRESHNESS_MILLIS = 3 * 24 * 60 * 60 * 1000; // 3 дня +export enum EventStatus { + NotEvent = 0, + NotStarted, + InProgress, + IsOver +} + +export function postEventStatus(post: App.BlogPost): EventStatus { + if (post.type !== 'event' || post.dateEventFrom === undefined || post.dateEventTo === undefined) { + return EventStatus.NotEvent; + } + + const currentTime = new Date().valueOf(); + const eventStart = new Date(post.dateEventFrom).valueOf(); + if (currentTime < eventStart) return EventStatus.NotStarted; + + const eventEnd = new Date(post.dateEventTo).valueOf(); + if (currentTime < eventEnd) return EventStatus.InProgress; + + return EventStatus.IsOver; +} + export type PostComparer = (a: App.BlogPost, b: App.BlogPost) => number; export const sortPostsByPostDate: PostComparer = (a, b) => new Date(b.date!).valueOf() - new Date(a.date!).valueOf(); diff --git a/src/routes/blog/[slug]/+page.svelte b/src/routes/blog/[slug]/+page.svelte index 0b0b105..b891e4d 100644 --- a/src/routes/blog/[slug]/+page.svelte +++ b/src/routes/blog/[slug]/+page.svelte @@ -1,12 +1,20 @@ @@ -63,6 +93,50 @@ {/each} +{#if type === 'event'} +
+ {#if eventStatus === EventStatus.NotStarted || eventStatus === EventStatus.InProgress} + + ДО {eventStatus === EventStatus.NotStarted ? 'НАЧАЛА' : 'КОНЦА'} ОСТАЛОСЬ + + + {:else if eventStatus === EventStatus.IsOver} + СОБЫТИЕ ЗАВЕРШЕНО + {/if} + + Событие {eventStatus === EventStatus.IsOver ? 'проводилось' : 'проводится'} с + + по + + ({durationHumanReadable( + new Date(data.blogPost.dateEventFrom!), + new Date(data.blogPost.dateEventTo!) + )}) + +
+{/if} + {#if page.data.blogPost.projects?.length > 0}

В данной заметке упоминаются наши проекты:

@@ -93,4 +167,4 @@ sm:text-xl lg:p-8" > - \ No newline at end of file +