diff --git a/components/content/ArticleDoi.vue b/components/content/ArticleDoi.vue index 82f15dcc94ba25e0b76314da14c09f33f969a414..f5ea016766522bc500953bc917df1b28fa482d67 100644 --- a/components/content/ArticleDoi.vue +++ b/components/content/ArticleDoi.vue @@ -1,6 +1,7 @@ <script setup lang="ts"> import { useDisplay } from "vuetify"; import type { WikiArticle } from '@/types/articles'; +import { useFetchArticle } from "../../composables/useFetchArticle"; export interface Props { index?: number; @@ -19,16 +20,15 @@ const props = withDefaults(defineProps<Props>(), { isRelevant: false, }); -const article = ref<WikiArticle | undefined>(undefined) +// const article = ref<WikiArticle | undefined>(undefined) const { mobile } = useDisplay(); const show = ref(false); -onMounted(() => { - const { article: articleOnMounted } = useFetchArticle(props.doi); - article.value = articleOnMounted.value -}) + +const { article } = useFetchArticle(props.doi); + const articleTitle = computed(() => { return props?.title ?? article?.value?.title ?? props.doi; @@ -38,8 +38,8 @@ const articleAbstract = computed(() => { }); </script> <template> - <v-list-item :href="article?.href" :id="`ref-${props.doi}`" :target="article?.target" density="compact" - color="transparent" class="px-1"> + <v-list-item v-if="article?.DOI" :href="article?.href" :id="`ref-${props.doi}`" :target="article?.target" + density="compact" color="transparent" class="px-1"> <template v-if="!mobile" #prepend> <v-icon icon="md:star" :color="props.isRelevant ? 'info' : 'transparent'"></v-icon> </template> diff --git a/composables/useFetchArticle.ts b/composables/useFetchArticle.ts index 86738ff04edd0e8cab4370972eb3ffd1bf91464c..d16679b8d6624a6816c3e4cdca3e82d02b3562c0 100644 --- a/composables/useFetchArticle.ts +++ b/composables/useFetchArticle.ts @@ -6,6 +6,7 @@ import type { SearchParams } from 'meilisearch' export function useFetchArticle(doi: string = "") { const doiBaseUrl = ref(new URL("https://doi.org/")); const article = useSessionStorage<WikiArticle | undefined>(doi, null, { serializer: StorageSerializers.object }) + // const article = ref<WikiArticle | undefined>(null) const client = useMeiliSearchRef() const index = ref("article") const params = ref<SearchParams>({ @@ -24,6 +25,7 @@ export function useFetchArticle(doi: string = "") { .join(", "); } function zoteroArticleToArticle(zoteroArticle: CslJson): WikiArticle | undefined { + console.log(zoteroArticle) if (zoteroArticle != undefined) { const { DOI, @@ -50,10 +52,13 @@ export function useFetchArticle(doi: string = "") { } if (!article.value) { - client.index(toValue(index)).search<CslJson>("", toValue(params)).then((response) => { - const sanitizedData = zoteroArticleToArticle(response.hits[0]) - article.value = sanitizedData + client.index(toValue(index)).search<CslJson>("", toValue(params)).then((data) => { + if (data !== undefined && data?.hits.length >= 1) { + const sanitizedData = zoteroArticleToArticle(data.hits[0]) + article.value = sanitizedData + } }).catch((error) => { + console.log(error) article.value = { DOI: doi } }) } diff --git a/pages/[...slug].vue b/pages/[...slug].vue index 0711392d4f23381f69ee93e19d0df1b317310868..d9956ab0fdc1643a88d13e4211e00d590967d2ef 100644 --- a/pages/[...slug].vue +++ b/pages/[...slug].vue @@ -6,7 +6,6 @@ function resetError(error) { <template> <v-card-text> <NuxtErrorBoundary> - <!-- ... --> <template #error="{ error }"> <ErrorAlert :error="error" @clear-error="resetError(error)"></ErrorAlert> </template>