Sfoglia il codice sorgente

news: show the publication date

Olivier Massot 1 anno fa
parent
commit
68f47dd2b0
1 ha cambiato i file con 25 aggiunte e 0 eliminazioni
  1. 25 0
      components/News/Details.vue

+ 25 - 0
components/News/Details.vue

@@ -40,6 +40,10 @@
               <strong>
                 {{ newsItem.leadText }}
               </strong>
+
+              <p>
+                {{ formattedPublicationDate }}
+              </p>
             </v-col>
           </v-row>
 
@@ -90,6 +94,8 @@
 
 <script setup lang="ts">
 import { useDisplay } from 'vuetify'
+import { parseISO, format } from 'date-fns'
+import { fr } from 'date-fns/locale'
 import { useEntityFetch } from '~/composables/data/useEntityFetch'
 import News from '~/models/Maestro/News'
 
@@ -112,6 +118,25 @@ const getImageUrl = (attachment: string): string | null => {
   }
   return `${config.public.apiBaseUrl}/uploads/news/${attachment}`
 }
+
+const formattedPublicationDate = computed(() => {
+  if (pending.value || !newsItem.value) {
+    return ''
+  }
+
+  const date = parseISO(newsItem.value.startPublication)
+
+  let formattedPublicationDate = format(date, "'Le' dd MMMM yyyy", {
+    locale: fr,
+  })
+
+  formattedPublicationDate = formattedPublicationDate.replace(
+    'Le 01 ',
+    'Le 1er '
+  )
+
+  return formattedPublicationDate
+})
 </script>
 
 <style scoped>