valaxy 0.19.7 → 0.19.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import valaxyLogoPng from '../assets/images/valaxy-logo.png'
5
5
  <template>
6
6
  <div class="valaxy-logo-container" relative inline-flex justify="center" items="center">
7
7
  <div class="absolute bg-img" />
8
- <img w="50" aspect="420/386" m="auto" :src="valaxyLogoPng" alt="Valaxy Logo" z="1">
8
+ <img class="fly-animation" w="50" aspect="420/386" m="auto" :src="valaxyLogoPng" alt="Valaxy Logo" z="1">
9
9
  </div>
10
10
  </template>
11
11
 
@@ -6,8 +6,6 @@ const router = useRouter()
6
6
  const route = useRoute()
7
7
 
8
8
  onBeforeMount(() => {
9
- router.push('/')
10
-
11
9
  // compatible for post url ends with slash
12
10
  if (route.path !== '/' && route.path.endsWith('/'))
13
11
  router.replace(route.path.slice(0, -1))
@@ -1,21 +1,65 @@
1
- import { format } from 'date-fns'
1
+ import type { ToDateOptionsWithTZ } from 'date-fns-tz'
2
+ import { format as formatWithTZ, toZonedTime } from 'date-fns-tz'
3
+ import { format, toDate } from 'date-fns'
4
+ import { useSiteConfig } from 'valaxy'
5
+ import { useI18n } from 'vue-i18n'
6
+ import { DateTime } from 'luxon'
2
7
  import type { Post } from '../../types'
3
8
 
9
+ const referenceDate = new Date(1986, 3 /* Apr */, 4, 10, 32, 0, 900)
10
+
4
11
  /**
5
- * date-fns format date
6
- * @param date
7
- * @param template
12
+ * format the date
13
+ * @param date the original date
14
+ * @param formatStr the string of tokens
15
+ * @param timezone the time zone of this local time, can be an offset or IANA time zone
16
+ * @param options the object with options. See [Options]{@link https://date-fns.org/docs/Options}
8
17
  */
9
- export function formatDate(date: string | number | Date, template = 'yyyy-MM-dd') {
10
- return format(date, template)
18
+ export function formatDate(date: string | number | Date, formatStr = 'yyyy-MM-dd', timezone?: string, options?: ToDateOptionsWithTZ): string {
19
+ const { locale } = useI18n()
20
+ const siteConfig = useSiteConfig()
21
+
22
+ const mergedOptions: ToDateOptionsWithTZ = Object.assign({ locale: { code: locale.value } }, options)
23
+ const clientTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone
24
+
25
+ try {
26
+ /**
27
+ * Format the timezone-less date to ISO. If none is specified, use the client's timezone.
28
+ * If the input date is already in ISO format, the timezone won't be applied.
29
+ */
30
+ date = handleTimeWithZone(date, timezone || siteConfig.value.timezone || clientTimezone).toString()
31
+ // Convert to the client's timezone unless the user specifies otherwise
32
+ const zonedDate = toZonedTime(date, options?.timeZone || clientTimezone, mergedOptions)
33
+ // The format function will never change the underlying date
34
+ return formatWithTZ(zonedDate, formatStr, { timeZone: options?.timeZone })
35
+ }
36
+ catch (error) {
37
+ console.error(
38
+ 'The date format provided is non-standard. The recommended format is \'yyyy-MM-dd HH:mm:ss\'',
39
+ '\nError formatting date:',
40
+ date.toString(),
41
+ error,
42
+ )
43
+ return format(referenceDate, formatStr)
44
+ }
11
45
  }
12
46
 
13
- /**
14
- * date-fns format date with 'yyyy-MM-dd HH:mm:ss'
15
- * @param date
16
- */
17
- export function formatTimestamp(date: string | number | Date): string {
18
- return format(date, 'yyyy-MM-dd HH:mm:ss')
47
+ function handleTimeWithZone(date: string | number | Date, timezone: string) {
48
+ if (typeof date !== 'string')
49
+ date = toDate(date).toISOString()
50
+
51
+ let dateTime = DateTime.fromISO(date, { setZone: true })
52
+
53
+ const toDateTime = (date: string, zone: string) => {
54
+ // Attempt to format the date using a function that handles non-ISO 8601 formats
55
+ const isoDate = format(date, 'yyyy-MM-dd\'T\'HH:mm:ss')
56
+ return DateTime.fromISO(isoDate, { zone })
57
+ }
58
+
59
+ if (!dateTime.isValid || !dateTime.zoneName)
60
+ dateTime = toDateTime(date, timezone)
61
+
62
+ return dateTime
19
63
  }
20
64
 
21
65
  /**
@@ -14,6 +14,8 @@ export function wrap(el: HTMLElement, className: string) {
14
14
  */
15
15
  export function wrapTable(container: HTMLElement | Document = document) {
16
16
  container.querySelectorAll('table').forEach((el) => {
17
+ if (el.parentElement?.classList.contains('table-container'))
18
+ return
17
19
  const container = document.createElement('div')
18
20
  container.className = 'table-container'
19
21
  wrap(el, 'table-container')