|  | 
|  | 1 | +import { b as createAstro, c as createComponent, m as maybeRenderHead, e as addAttribute, r as renderComponent, F as Fragment, a as renderTemplate } from './astro/server_DdaBn-83.mjs'; | 
|  | 2 | +import 'kleur/colors'; | 
|  | 3 | +import dayjs from 'dayjs'; | 
|  | 4 | +import utc from 'dayjs/plugin/utc.js'; | 
|  | 5 | +import timezone from 'dayjs/plugin/timezone.js'; | 
|  | 6 | +import relativeTime from 'dayjs/plugin/relativeTime.js'; | 
|  | 7 | +import { S as SITE } from './config_JJhEf13K.mjs'; | 
|  | 8 | + | 
|  | 9 | +function calculateReadingTime(content, wordsPerMinute = 200) { | 
|  | 10 | +  const words = content.trim().split(/\s+/).length; | 
|  | 11 | +  const readingTime = Math.ceil(words / wordsPerMinute); | 
|  | 12 | +  return readingTime; | 
|  | 13 | +} | 
|  | 14 | +function formatReadingTime(minutes) { | 
|  | 15 | +  if (minutes === 1) { | 
|  | 16 | +    return "1 min read time"; | 
|  | 17 | +  } | 
|  | 18 | +  return `${minutes} min read time`; | 
|  | 19 | +} | 
|  | 20 | + | 
|  | 21 | +dayjs.extend(relativeTime); | 
|  | 22 | +function getRelativeTime(date) { | 
|  | 23 | +  const dayjsDate = dayjs(date); | 
|  | 24 | +  const now = dayjs(); | 
|  | 25 | +  const diffInYears = now.diff(dayjsDate, "year"); | 
|  | 26 | +  const diffInMonths = now.diff(dayjsDate, "month"); | 
|  | 27 | +  const diffInWeeks = now.diff(dayjsDate, "week"); | 
|  | 28 | +  const diffInDays = now.diff(dayjsDate, "day"); | 
|  | 29 | +  const diffInHours = now.diff(dayjsDate, "hour"); | 
|  | 30 | +  const diffInMinutes = now.diff(dayjsDate, "minute"); | 
|  | 31 | +  const isFuture = diffInYears < 0 || diffInMonths < 0 || diffInWeeks < 0 || diffInDays < 0 || diffInHours < 0 || diffInMinutes < 0; | 
|  | 32 | +  const absYears = Math.abs(diffInYears); | 
|  | 33 | +  const absMonths = Math.abs(diffInMonths); | 
|  | 34 | +  const absWeeks = Math.abs(diffInWeeks); | 
|  | 35 | +  const absDays = Math.abs(diffInDays); | 
|  | 36 | +  const absHours = Math.abs(diffInHours); | 
|  | 37 | +  const absMinutes = Math.abs(diffInMinutes); | 
|  | 38 | +  if (absYears >= 1) { | 
|  | 39 | +    const timeText = absYears === 1 ? "a year" : `${absYears} years`; | 
|  | 40 | +    return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 41 | +  } else if (absMonths >= 1) { | 
|  | 42 | +    const timeText = absMonths === 1 ? "a month" : `${absMonths} months`; | 
|  | 43 | +    return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 44 | +  } else if (absWeeks >= 1) { | 
|  | 45 | +    const timeText = absWeeks === 1 ? "a week" : `${absWeeks} weeks`; | 
|  | 46 | +    return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 47 | +  } else if (absDays >= 1) { | 
|  | 48 | +    if (absDays === 1) { | 
|  | 49 | +      return isFuture ? "tomorrow" : "yesterday"; | 
|  | 50 | +    } else { | 
|  | 51 | +      const timeText = `${absDays} days`; | 
|  | 52 | +      return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 53 | +    } | 
|  | 54 | +  } else if (absHours >= 1) { | 
|  | 55 | +    const timeText = absHours === 1 ? "an hour" : `${absHours} hours`; | 
|  | 56 | +    return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 57 | +  } else if (absMinutes >= 1) { | 
|  | 58 | +    const timeText = absMinutes === 1 ? "a minute" : `${absMinutes} minutes`; | 
|  | 59 | +    return isFuture ? `in ${timeText}` : `${timeText} ago`; | 
|  | 60 | +  } else { | 
|  | 61 | +    return isFuture ? "in a few seconds" : "a few seconds ago"; | 
|  | 62 | +  } | 
|  | 63 | +} | 
|  | 64 | + | 
|  | 65 | +const $$Astro = createAstro("https://jeoste.github.io/"); | 
|  | 66 | +const $$Datetime = createComponent(($$result, $$props, $$slots) => { | 
|  | 67 | +  const Astro2 = $$result.createAstro($$Astro, $$props, $$slots); | 
|  | 68 | +  Astro2.self = $$Datetime; | 
|  | 69 | +  dayjs.extend(utc); | 
|  | 70 | +  dayjs.extend(timezone); | 
|  | 71 | +  dayjs.extend(relativeTime); | 
|  | 72 | +  const { | 
|  | 73 | +    pubDatetime, | 
|  | 74 | +    modDatetime, | 
|  | 75 | +    size = "sm", | 
|  | 76 | +    class: className = "", | 
|  | 77 | +    timezone: postTimezone, | 
|  | 78 | +    showRelative = true | 
|  | 79 | +  } = Astro2.props; | 
|  | 80 | +  const pubDate = dayjs(pubDatetime).tz(postTimezone || SITE.timezone); | 
|  | 81 | +  const modDate = modDatetime ? dayjs(modDatetime).tz(postTimezone || SITE.timezone) : null; | 
|  | 82 | +  const formatDate = (date) => date.format("D MMM, YYYY"); | 
|  | 83 | +  const formatTime = (date) => date.format("hh:mm A"); | 
|  | 84 | +  const pubRelativeDate = getRelativeTime(pubDatetime); | 
|  | 85 | +  const modRelativeDate = modDatetime ? getRelativeTime(modDatetime) : null; | 
|  | 86 | +  const shouldShowRelative = showRelative; | 
|  | 87 | +  const displayPubDate = shouldShowRelative ? pubRelativeDate : formatDate(pubDate); | 
|  | 88 | +  const displayModDate = modDatetime && shouldShowRelative ? modRelativeDate : modDatetime ? formatDate(modDate) : null; | 
|  | 89 | +  return renderTemplate`${maybeRenderHead()}<div${addAttribute(["flex items-end space-x-2 opacity-80", className], "class:list")}> <span${addAttribute(["text-sm italic", { "sm:text-base": size === "lg" }], "class:list")}> <span>Publication date:${" "}</span> <time${addAttribute(pubDate.toISOString(), "datetime")}${addAttribute(`${formatDate(pubDate)} | ${formatTime(pubDate)}`, "title")}> ${displayPubDate} </time> ${!shouldShowRelative && renderTemplate`${renderComponent($$result, "Fragment", Fragment, {}, { "default": ($$result2) => renderTemplate` <span aria-hidden="true"> | </span> <span class="sr-only"> at </span> <span class="text-nowrap">${formatTime(pubDate)}</span> ` })}`} ${modDatetime && modDate && renderTemplate`${renderComponent($$result, "Fragment", Fragment, {}, { "default": ($$result2) => renderTemplate` <span class="mx-2">•</span> <span>Last update:${" "}</span> <time${addAttribute(modDate.toISOString(), "datetime")}${addAttribute(`${formatDate(modDate)} | ${formatTime(modDate)}`, "title")}> ${displayModDate} </time> ${!shouldShowRelative && renderTemplate`${renderComponent($$result2, "Fragment", Fragment, {}, { "default": ($$result3) => renderTemplate` <span aria-hidden="true"> | </span> <span class="sr-only"> at </span> <span class="text-nowrap">${formatTime(modDate)}</span> ` })}`}` })}`} </span> </div>`; | 
|  | 90 | +}, "C:/GitHubPro/jeoste.github.io/src/components/Datetime.astro", void 0); | 
|  | 91 | + | 
|  | 92 | +export { $$Datetime as $, calculateReadingTime as c, formatReadingTime as f }; | 
0 commit comments