Skip to content

Commit cf34b5b

Browse files
committed
agrego autores a páginas de blog y corrijo en página de recursos
1 parent 5274f91 commit cf34b5b

7 files changed

Lines changed: 45 additions & 23 deletions

File tree

src/components/BlogHero.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export let date = '';
77
export let image =
88
'https://images.unsplash.com/photo-1582005450386-52b25f82d9bb?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D';
9+
export let authors = '';
910
</script>
1011

1112
<a href="/blog/{slug}">
@@ -69,7 +70,11 @@
6970
"
7071
>
7172
<div class=" bottom-0">
72-
<p class="text-left text-white font-thin">Hector Garrido</p>
73+
<p class="text-left text-white font-thin">
74+
{#each authors as author, i}
75+
<span>{author.authors_id.name || ''}{#if i < (authors.length-1)}, {/if}</span>
76+
{/each}
77+
</p>
7378
<p class="text-left text-gray-300 font-bold">{date}</p>
7479
</div>
7580
</div>

src/components/Cards/ArticleCard.svelte

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
export let date;
66
export let image;
77
export let tag;
8-
export let author
8+
export let authors;
99
1010
</script>
1111

@@ -21,7 +21,11 @@
2121
{/if}
2222
</div>
2323
<h2 class="font-extrabold text-xl">{title}</h2>
24-
<p class="text-sm">{author || ''}</p>
24+
<p class="text-sm">
25+
{#each authors as author, i }
26+
<span>{author.authors_id.name || ''}{#if i < (authors.length-1)}, {/if}</span>
27+
{/each}
28+
</p>
2529
<p class="text-sm text-gray-400">{date}</p>
2630
</div>
2731
</div>

src/components/Cards/RecursosCard.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
<div>
1010
<h4 class="text-xl font-bold">{title}</h4>
1111
{#if authors }
12-
{#each authors as author }
13-
<p>{author.authors_id.name}</p>
12+
<p>
13+
{#each authors as author, i }
14+
<span>{author.authors_id.name || ''}{#if i < (authors.length-1)}, {/if}</span>
1415
{/each}
16+
</p>
1517
{/if }
1618
</div>
1719
<img src="/flecha-verde.png" alt="Ir al recurso" class="inline h-[20px] w-[20px] self-end">

src/routes/blog/+page.server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { readSingleton, readItems } from '@directus/sdk'
33

44
export async function load() {
55
const blog = await client.request(readSingleton('blog', {
6-
fields: ['*', "highlight_post.*"]
6+
fields: ['*', "highlight_post.*", "highlight_post.authors.authors_id.*"],
77
}))
88

99
// get and sort posts
1010
const posts = await client.request(readItems('Blog_Posts', {
11-
fields: ['*', "user_created.*"],
11+
fields: ['*', "user_created.*", {
12+
authors: [{authors_id: ['*']}]
13+
}
14+
],
1215
filter: {
1316
status: {
1417
_eq: "published"

src/routes/blog/+page.svelte

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@
44
export let data
55
const { blog, posts } = data
66
</script>
7+
<div class="container my-20 mx-auto">
78

8-
<div class="container m-auto px-3 ">
9-
<div class="my-7">
10-
<h1 class="text-5xl text-green-400 font-bold">Blog</h1>
11-
</div>
12-
<BlogHero
9+
<div class="container m-auto px-3">
10+
<div class="my-7">
11+
<h1 class="text-5xl text-cmxblack font-bold">Blog</h1>
12+
</div>
13+
<BlogHero
1314
slug={blog.highlight_post.slug}
1415
title={blog.highlight_post.title}
1516
tag={blog.highlight_post.tags[0]}
1617
date={new Date(blog.highlight_post.date_created).toLocaleString('es-MX')}
1718
image={`https://content.codeandomexico.org/assets/${blog.highlight_post.post_image}`}
18-
/>
19-
</div>
20-
<div class="container m-auto p-3">
21-
<div class="md:grid grid-cols-3 gap-5">
19+
authors={blog.highlight_post.authors}
20+
/>
21+
</div>
22+
<div class="container m-auto p-3">
23+
<div class="md:grid grid-cols-3 gap-5">
2224
{#each posts as post}
2325
<ArticleCard
24-
slug={post.slug}
25-
title={post.title}
26-
tag={post.tags[0]}
27-
author={post.user_created.first_name + ' ' + post.user_created.last_name}
28-
date={new Date(post.date_created).toLocaleString('es-MX')}
29-
image={`https://content.codeandomexico.org/assets/${post.post_image}`}
26+
slug={post.slug}
27+
title={post.title}
28+
tag={post.tags[0]}
29+
authors={post.authors}
30+
date={new Date(post.date_created).toLocaleString('es-MX')}
31+
image={`https://content.codeandomexico.org/assets/${post.post_image}`}
3032
/>
3133
{/each}
32-
34+
</div>
3335
</div>
3436
</div>

src/routes/blog/[slug]/+page.server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export async function entries() {
2121
export async function load({ params }) {
2222
const slug = params.slug
2323
const data = await client.request(readItems('Blog_Posts', {
24+
fields: ['*', 'authors.authors_id.*'],
2425
filter: {
2526
slug: {
2627
_eq: slug

src/routes/blog/[slug]/+page.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
<section class="container m-auto p-3 prose">
1515
<h1 class="text-center font-bold">{post.title}</h1>
16+
<p class="text-center">Por
17+
{#each post.authors as author, i }
18+
<span>{author.authors_id.name || ''}{#if i < (post.authors.length-1)}, {/if}</span>
19+
{/each}
20+
</p>
1621
<p class="text-center text-sm text-gray-400">{new Date(post.date_created).toLocaleString('es-MX')}</p>
1722
</section>
1823
<img src={`https://content.codeandomexico.org/assets/${post.post_image}`} alt="Imagen de blog" class="w-full max-h-[450px] object-cover" />

0 commit comments

Comments
 (0)