瀏覽代碼

test to setup meta tags before rendering

Olivier Massot 1 年之前
父節點
當前提交
86783b44b4
共有 4 個文件被更改,包括 43 次插入13 次删除
  1. 2 1
      .eslintrc.cjs
  2. 37 8
      components/News/Details.client.vue
  3. 0 0
      error.vue.off
  4. 4 4
      pages/actualites/[id]-[slug].vue

+ 2 - 1
.eslintrc.cjs

@@ -55,6 +55,7 @@ module.exports = {
     Ref: 'readonly',
     watch: 'readonly',
     useGtag: 'readonly',
-    defineEmits: 'readonly'
+    defineEmits: 'readonly',
+    useAsyncData: 'readonly',
   },
 }

+ 37 - 8
components/News/Details.client.vue

@@ -14,13 +14,13 @@
         </v-col>
       </v-row>
 
-      <div>
+      <div v-if="newsItem">
         <div class="news">
-          <CommonMeta
-            :title="() => newsItem.title!"
-            :description="() => newsItem.leadText!"
-            :image="() => getImageUrl(newsItem.attachment)"
-          />
+          <!--          <CommonMeta-->
+          <!--            :title="() => newsItem.title!"-->
+          <!--            :description="() => newsItem.leadText!"-->
+          <!--            :image="() => getImageUrl(newsItem.attachment)"-->
+          <!--          />-->
 
           <v-row class="center-90 mb-12">
             <v-col cols="12" md="6">
@@ -95,12 +95,13 @@ import { parseISO, format } from 'date-fns'
 import { fr } from 'date-fns/locale'
 import type { ComputedRef } from 'vue'
 import News from '~/models/Maestro/News'
+import { useEntityFetch } from '~/composables/data/useEntityFetch'
 import { useEntityManager } from '~/composables/data/useEntityManager'
 
 const { mdAndUp, smAndDown } = useDisplay()
 
 const route = useRoute()
-const { em } = useEntityManager()
+// const { fetch } = useEntityFetch()
 const config = useRuntimeConfig()
 
 const newsId: number = parseInt(route.params.id as string)
@@ -109,7 +110,15 @@ if (!newsId || isNaN(newsId)) {
 }
 
 // @ts-expect-error Until we can fix the typing of fetch
-const newsItem: Ref<News> = ref(await em.fetch(News, newsId))
+// const { data: newsItem } = (await fetch(News, newsId)) as Ref<News>
+
+const { em } = useEntityManager()
+
+const { data: newsItem } = await useAsyncData(
+  'news_' + newsId,
+  async () => await em.fetch(News, newsId, true),
+  { lazy: false }
+)
 
 const getImageUrl = (attachment: string | null): string | null => {
   if (!attachment) {
@@ -136,6 +145,26 @@ const formattedPublicationDate: ComputedRef<string> = computed(() => {
 
   return formattedPublicationDate
 })
+
+watch(newsItem, () => {
+  if (!newsItem.value) {
+    return
+  }
+  console.log('seo on')
+  useSeoMeta({
+    title: newsItem.value.title!,
+    ogTitle: newsItem.value.title!,
+    twitterTitle: newsItem.value.title!,
+    description: newsItem.value.leadText!,
+    ogDescription: newsItem.value.leadText!,
+    twitterDescription: newsItem.value.leadText!,
+    ogImage: () => getImageUrl(newsItem.value.attachment),
+    twitterImage: () => getImageUrl(newsItem.value.attachment),
+    twitterCard: 'summary_large_image',
+    ogType: 'website',
+    ogLocale: 'fr_FR',
+  })
+})
 </script>
 
 <style scoped>

+ 0 - 0
error.vue → error.vue.off


+ 4 - 4
pages/actualites/[id]-[slug].vue

@@ -1,9 +1,9 @@
 <template>
   <div>
-    <CommonMeta
-      title="Actualité de l'éditeur de logiciel de gestion et de communication Opentalent"
-      description="Suivez l’actualité d’Opentalent : événements incontournables, opportunité de carrières et innovations logicielles. Suivez-nous et faites partie de l'évolution culturelle."
-    />
+    <!--    <CommonMeta-->
+    <!--      title="Actualité de l'éditeur de logiciel de gestion et de communication Opentalent"-->
+    <!--      description="Suivez l’actualité d’Opentalent : événements incontournables, opportunité de carrières et innovations logicielles. Suivez-nous et faites partie de l'évolution culturelle."-->
+    <!--    />-->
 
     <LayoutUITitlePage>
       Actualités