From 963f460e8a981b5484dbf154e243ce5abf0b32cd Mon Sep 17 00:00:00 2001 From: Techit Thawiang Date: Mon, 25 Aug 2025 21:13:08 +0700 Subject: [PATCH] add support for blog --- components/post-card.vue | 26 ++++++++++++++ components/posts-article-list.vue | 26 ++++++++++++++ composables/formatDate.ts | 11 ++++++ composables/relativeDate.ts | 10 ++++++ pages/posts/[...slug].vue | 58 +++++++++++++++++++++++++++++++ pages/posts/index.vue | 29 ++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 components/post-card.vue create mode 100644 components/posts-article-list.vue create mode 100644 composables/formatDate.ts create mode 100644 composables/relativeDate.ts create mode 100644 pages/posts/[...slug].vue create mode 100644 pages/posts/index.vue diff --git a/components/post-card.vue b/components/post-card.vue new file mode 100644 index 0000000..0246472 --- /dev/null +++ b/components/post-card.vue @@ -0,0 +1,26 @@ + + + \ No newline at end of file diff --git a/components/posts-article-list.vue b/components/posts-article-list.vue new file mode 100644 index 0000000..8a464e0 --- /dev/null +++ b/components/posts-article-list.vue @@ -0,0 +1,26 @@ + + + diff --git a/composables/formatDate.ts b/composables/formatDate.ts new file mode 100644 index 0000000..4e44e65 --- /dev/null +++ b/composables/formatDate.ts @@ -0,0 +1,11 @@ +import dayjs from 'dayjs' +import localizedFormat from 'dayjs/plugin/localizedFormat' +import 'dayjs/locale/th' +import 'dayjs/locale/en' + +dayjs.extend(localizedFormat) + +export const useFormatDate = (date: string) => { + const localizedDayjs = dayjs(date).locale('en') + return localizedDayjs.format('D MMMM YYYY - HH:mm') +} diff --git a/composables/relativeDate.ts b/composables/relativeDate.ts new file mode 100644 index 0000000..0bc52ac --- /dev/null +++ b/composables/relativeDate.ts @@ -0,0 +1,10 @@ +import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' +import 'dayjs/locale/en' + +dayjs.extend(relativeTime) + +export const useRelativeDate = (date: string) => { + dayjs.locale('en') + return dayjs().to(dayjs(date)) +} \ No newline at end of file diff --git a/pages/posts/[...slug].vue b/pages/posts/[...slug].vue new file mode 100644 index 0000000..80ad994 --- /dev/null +++ b/pages/posts/[...slug].vue @@ -0,0 +1,58 @@ + + + \ No newline at end of file diff --git a/pages/posts/index.vue b/pages/posts/index.vue new file mode 100644 index 0000000..c3eabc8 --- /dev/null +++ b/pages/posts/index.vue @@ -0,0 +1,29 @@ + + + \ No newline at end of file