|
| 1 | +<script setup> |
| 2 | +// HELPERS |
| 3 | +import _get from 'lodash/get' |
| 4 | +
|
| 5 | +// GQL |
| 6 | +import FTVACollectionItem from '../gql/queries/FTVACollectionItem.gql' |
| 7 | +
|
| 8 | +// COMPOSABLE |
| 9 | +import { useContentIndexer } from '~/composables/useContentIndexer' |
| 10 | +
|
| 11 | +const { $graphql } = useNuxtApp() |
| 12 | +
|
| 13 | +const route = useRoute() |
| 14 | +
|
| 15 | +const { collectionSlug, slug } = route.params |
| 16 | +
|
| 17 | +// DATA |
| 18 | +const { data, error } = await useAsyncData(`collection-item-${slug}`, async () => { |
| 19 | + const data = await $graphql.default.request(FTVACollectionItem, { slug, collectionSlug }) |
| 20 | + return data |
| 21 | +}) |
| 22 | +
|
| 23 | +if (error.value) { |
| 24 | + throw createError({ |
| 25 | + ...error.value, statusMessage: 'Page not found.' + error.value, fatal: true |
| 26 | + }) |
| 27 | +} |
| 28 | +
|
| 29 | +if (!data.value.entry) { |
| 30 | + throw createError({ |
| 31 | + statusCode: 404, |
| 32 | + statusMessage: 'Page Not Found', |
| 33 | + fatal: true |
| 34 | + }) |
| 35 | +} |
| 36 | +
|
| 37 | +// This is creating an index of the main content (not related content) |
| 38 | +if (data.value.entry && import.meta.prerender) { |
| 39 | + try { |
| 40 | + // Call the composable to use the indexing function |
| 41 | + const { indexContent } = useContentIndexer() |
| 42 | + // Index the data using the composable during static build |
| 43 | + await indexContent(data.value.entry, slug) |
| 44 | + } catch (error) { |
| 45 | + // eslint-disable-next-line no-console |
| 46 | + console.error('FAILED TO INDEX COLLECTION ITEM during static build:', error) |
| 47 | + } |
| 48 | +} |
| 49 | +
|
| 50 | +console.log('Data: ', data.value) |
| 51 | +
|
| 52 | +const page = ref(_get(data.value, 'entry', {})) |
| 53 | +const relatedContent = ref(_get(data.value, 'entries', {})) |
| 54 | +
|
| 55 | +// Entries query returns 4 random articles; main article might be included in the randomized return; to prevent duplication, filter out the main article; use remaining content in the related section. |
| 56 | +const parsedRelatedContent = computed(() => { |
| 57 | + const mainContentId = page.value.id |
| 58 | +
|
| 59 | + const filteredRelatedContent = relatedContent.value.filter(obj => obj.id !== mainContentId) |
| 60 | +
|
| 61 | + return filteredRelatedContent.slice(0, 3) |
| 62 | +}) |
| 63 | +
|
| 64 | +useHead({ |
| 65 | + title: page.value ? page.value.title : '... loading', |
| 66 | + meta: [ |
| 67 | + { |
| 68 | + hid: 'description', |
| 69 | + name: 'description', |
| 70 | + content: removeTags(page.value.summary) |
| 71 | + } |
| 72 | + ] |
| 73 | +}) |
| 74 | +
|
| 75 | +</script> |
| 76 | +
|
| 77 | +<template> |
| 78 | + <main |
| 79 | + class="page page-collection-item-detail" |
| 80 | + style="padding: 25px 100px;" |
| 81 | + > |
| 82 | + <section-wrapper> |
| 83 | + <h2>Collection Item</h2> |
| 84 | + <pre>{{ page }}</pre> |
| 85 | + <divider-general /> |
| 86 | + <h2>Related Content</h2> |
| 87 | + <div |
| 88 | + v-for="item in parsedRelatedContent" |
| 89 | + :key="item.id" |
| 90 | + > |
| 91 | + <NuxtLink :to="`/${item.uri}`"> |
| 92 | + <h4>Title-Link: {{ item.title }}</h4> |
| 93 | + </NuxtLink> |
| 94 | + <p>uri: {{ item.uri }}</p> |
| 95 | + <p>id: {{ item.id }}</p> |
| 96 | + <p>image: {{ item.ftvaImage[0] }}</p> |
| 97 | + <divider-general /> |
| 98 | + </div> |
| 99 | + </section-wrapper> |
| 100 | + </main> |
| 101 | +</template> |
| 102 | +
|
| 103 | +<style lang="scss" scoped></style> |
0 commit comments