Details.client.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <LayoutContainer>
  3. <div class="news-section">
  4. <v-row class="mb-6 center-90">
  5. <v-col class="d-flex align-items-center">
  6. <v-btn
  7. to="/actualites"
  8. prepend-icon="fas fa-arrow-left"
  9. variant="outlined"
  10. class="back-button"
  11. >
  12. Retour aux actualités
  13. </v-btn>
  14. </v-col>
  15. </v-row>
  16. <div v-if="newsItem">
  17. <div class="news">
  18. <!-- <CommonMeta-->
  19. <!-- :title="() => newsItem.title!"-->
  20. <!-- :description="() => newsItem.leadText!"-->
  21. <!-- :image="() => getImageUrl(newsItem.attachment)"-->
  22. <!-- />-->
  23. <v-row class="center-90 mb-12">
  24. <v-col cols="12" md="6">
  25. <v-img
  26. :src="getImageUrl(newsItem.attachment) ?? undefined"
  27. cover
  28. />
  29. </v-col>
  30. <v-col cols="12" md="6" class="d-flex flex-column justify-center">
  31. <h3>
  32. {{ newsItem.title }}
  33. </h3>
  34. <strong>
  35. {{ newsItem.leadText }}
  36. </strong>
  37. <p>
  38. {{ formattedPublicationDate }}
  39. </p>
  40. </v-col>
  41. </v-row>
  42. <v-row class="center-90">
  43. <p class="description" v-html="newsItem.bodyText" />
  44. </v-row>
  45. <v-row class="d-flex justify-center align-center">
  46. <v-btn
  47. v-if="newsItem.linkButton"
  48. :href="newsItem.linkButton"
  49. target="_blank"
  50. class="btn-plus mb-12"
  51. >
  52. En savoir plus
  53. </v-btn>
  54. </v-row>
  55. <v-row class="d-flex justify-space-between center-90">
  56. <div>
  57. <p v-if="newsItem.tags.length > 0">MOTS CLÉS</p>
  58. </div>
  59. <div v-if="mdAndUp">
  60. <p>PARTAGER</p>
  61. </div>
  62. </v-row>
  63. <v-row class="d-flex justify-space-between mb-8 center-90">
  64. <p class="key-word mt-3">
  65. <span v-for="tag in newsItem.tags" :key="tag.id" class="mr-2">
  66. {{ tag.name }}
  67. </span>
  68. </p>
  69. <CommonShare v-if="mdAndUp" />
  70. </v-row>
  71. <div v-if="smAndDown" class="center-90">
  72. <p>PARTAGER</p>
  73. <CommonShare />
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </LayoutContainer>
  79. </template>
  80. <script setup lang="ts">
  81. import { useDisplay } from 'vuetify'
  82. import { parseISO, format } from 'date-fns'
  83. import { fr } from 'date-fns/locale'
  84. import type { ComputedRef } from 'vue'
  85. import News from '~/models/Maestro/News'
  86. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  87. import { useEntityManager } from '~/composables/data/useEntityManager'
  88. const { mdAndUp, smAndDown } = useDisplay()
  89. const route = useRoute()
  90. // const { fetch } = useEntityFetch()
  91. const config = useRuntimeConfig()
  92. const newsId: number = parseInt(route.params.id as string)
  93. if (!newsId || isNaN(newsId)) {
  94. throw new Error('Missing or invalid id')
  95. }
  96. // @ts-expect-error Until we can fix the typing of fetch
  97. // const { data: newsItem } = (await fetch(News, newsId)) as Ref<News>
  98. const { em } = useEntityManager()
  99. const { data: newsItem } = await useAsyncData(
  100. 'news_' + newsId,
  101. async () => await em.fetch(News, newsId, true),
  102. { lazy: false }
  103. )
  104. const getImageUrl = (attachment: string | null): string | null => {
  105. if (!attachment) {
  106. return null
  107. }
  108. return `${config.public.apiBaseUrl}/uploads/news/${attachment}`
  109. }
  110. const formattedPublicationDate: ComputedRef<string> = computed(() => {
  111. if (!newsItem.value || !newsItem.value.startPublication) {
  112. return ''
  113. }
  114. const date = parseISO(newsItem.value.startPublication)
  115. let formattedPublicationDate = format(date, "'Le' dd MMMM yyyy", {
  116. locale: fr,
  117. })
  118. formattedPublicationDate = formattedPublicationDate.replace(
  119. 'Le 01 ',
  120. 'Le 1er '
  121. )
  122. return formattedPublicationDate
  123. })
  124. watch(newsItem, () => {
  125. if (!newsItem.value) {
  126. return
  127. }
  128. console.log('seo on')
  129. useSeoMeta({
  130. title: newsItem.value.title!,
  131. ogTitle: newsItem.value.title!,
  132. twitterTitle: newsItem.value.title!,
  133. description: newsItem.value.leadText!,
  134. ogDescription: newsItem.value.leadText!,
  135. twitterDescription: newsItem.value.leadText!,
  136. ogImage: () => getImageUrl(newsItem.value.attachment),
  137. twitterImage: () => getImageUrl(newsItem.value.attachment),
  138. twitterCard: 'summary_large_image',
  139. ogType: 'website',
  140. ogLocale: 'fr_FR',
  141. })
  142. })
  143. </script>
  144. <style scoped>
  145. .news {
  146. .v-img {
  147. max-height: 600px;
  148. margin-left: auto;
  149. margin-right: auto;
  150. }
  151. h3 {
  152. text-decoration: none;
  153. text-transform: uppercase;
  154. font-size: 36px;
  155. font-weight: 600;
  156. color: var(--primary-color);
  157. }
  158. strong {
  159. font-size: 21px;
  160. margin-top: 16px;
  161. }
  162. .description {
  163. color: var(--primary-color);
  164. max-width: 80%;
  165. font-size: 21px;
  166. font-weight: 500;
  167. line-height: 34px;
  168. margin-left: auto;
  169. margin-right: auto;
  170. margin-bottom: 3rem;
  171. }
  172. .btn-plus {
  173. background: var(--secondary-color);
  174. color: var(--on-secondary-color);
  175. display: flex;
  176. left: 0;
  177. padding: 25px 28px;
  178. align-items: center;
  179. gap: 9px;
  180. font-size: 0.9rem;
  181. border-radius: 5px;
  182. font-weight: 700;
  183. line-height: 15px;
  184. letter-spacing: 1.3px;
  185. text-transform: uppercase;
  186. margin-bottom: -1rem;
  187. }
  188. }
  189. .back-button {
  190. text-decoration: none;
  191. color: var(--on-neutral-color);
  192. font-size: 0.9rem;
  193. font-weight: 700;
  194. line-height: 15px;
  195. letter-spacing: 1.8px;
  196. text-transform: uppercase;
  197. }
  198. .key-word {
  199. color: var(--on-neutral-color);
  200. font-size: 20px;
  201. font-weight: 500;
  202. line-height: 24px;
  203. }
  204. </style>