Skip to content

Commit 59a6631

Browse files
authored
Merge branch 'main' into APPS-3127_tech-debt-index-title-summary-and-ri-on-this-template-event-listing-2
2 parents a399b6d + d1b0c8e commit 59a6631

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

gql/queries/FTVACollectionItem.gql

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#import "../gql/fragments/Image.gql"
2+
3+
query FTVACollectionItem($collectionSlug: [String!], $slug: [String!]) {
4+
entry(section: "ftvaItemInCollection", slug:$slug ) {
5+
id
6+
title
7+
slug
8+
uri
9+
sectionHandle
10+
ftvaAssociatedCollections {
11+
id
12+
title
13+
}
14+
ftvaImage {
15+
...Image
16+
}
17+
videoEmbed
18+
richText
19+
externalResourceUrl
20+
21+
ftvaDate
22+
releaseDate
23+
episodeAirDate
24+
episodeTitle
25+
episodeSeason
26+
episodeNumber
27+
ftvaCollectionGroup {
28+
... on ftvaCollectionGroup_Category {
29+
id
30+
title
31+
}
32+
}
33+
ftvaCollectionTags {
34+
... on ftvaCollectionTags_Tag {
35+
id
36+
title
37+
}
38+
}
39+
director {
40+
... on ftvaLARebellionIndividual_ftvaLARebellionIndividual_Entry {
41+
nameFirst
42+
nameLast
43+
}
44+
}
45+
year
46+
country
47+
runtime
48+
associatedIndividuals {
49+
... on associatedIndividuals_individual_BlockType {
50+
individual {
51+
id
52+
nameFirst
53+
nameLast
54+
}
55+
roles
56+
}
57+
}
58+
}
59+
entries(section: "ftvaItemInCollection", relatedToEntries:{section:"ftvaCollection", slug:$collectionSlug}, orderBy: "random()", limit: 4) {
60+
id
61+
title
62+
slug
63+
uri
64+
ftvaImage {
65+
...Image
66+
}
67+
videoEmbed
68+
}
69+
}
70+
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

Comments
 (0)