All files / apps/huella-legal/layers/reading/app/composables useArticle.ts

82.6% Statements 19/23
100% Branches 6/6
69.23% Functions 9/13
80.95% Lines 17/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 493x 12x   12x       12x       12x                 12x     12x   1x     12x 12x   12x 2x 2x           2x     12x   12x   11x    
export const useArticle = async () => {
    const route = useRoute("article");
 
    const { data: related } = useCachedFetch<ArticleSummary[]>(
        `/api/articles/${route.params.slug}/related`,
        {
            lazy: true,
            default: () => [],
        },
    );
 
    const { data: comments } = useCachedFetch<ArticleComments>(
        `/api/articles/${route.params.slug}/comments`,
        {
            key: `article-comments-${route.params.slug}`,
            server: false,
            lazy: true,
        },
    );
 
    const { data: authorCounts } = useCachedFetch("/api/authors", {
        key: "author-counts",
        lazy: true,
        default: () => ({}),
        transform: (authors): Record<string, number> =>
            Object.fromEntries(authors.map(({ value, count }) => [value.id, count])),
    });
 
    const request = useCachedFetch<Article>(`/api/articles/${route.params.slug}`);
    const { data: article } = request;
 
    useSeoMeta({
        title: () => article.value?.seo?.title ?? article.value?.title,
        description: () => article.value?.seo?.description ?? article.value?.excerpt,
        ogType: "article",
        ogImage: () => article.value?.image?.url,
        ogImageAlt: () => article.value?.image?.alt,
        articlePublishedTime: () => article.value?.publishedAt,
        articleModifiedTime: () => article.value?.updatedAt,
        robots: () => (article.value?.seo?.noindex ? "noindex" : undefined),
    });
 
    useSeoTitleTemplate(() => article.value?.seo?.title);
 
    await useFailOnError(request);
 
    return { article, related, authorCounts, comments };
};