Skip to content

Commit c01e122

Browse files
authored
Merge pull request #52 from CodeandoMexico/feat/dates
stylized date, reading time, blog
2 parents 940e7de + c10b710 commit c01e122

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

src/components/BlogHero.svelte

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<script>
22
import Badge from './Badge.svelte';
3+
import ReadingTime from './ReadingTime.svelte';
4+
import HumanDate from './HumanDate.svelte';
35
export let tag = '';
46
export let title = 'Blog';
57
export let slug = '';
68
export let date = '';
79
export let image =
810
'https://images.unsplash.com/photo-1582005450386-52b25f82d9bb?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D';
911
export let authors = '';
12+
export let content = '';
1013
</script>
1114

1215
<a href="/blog/{slug}">
@@ -69,13 +72,17 @@
6972
p-10
7073
"
7174
>
72-
<div class=" bottom-0">
73-
<p class="text-left text-white font-thin">
75+
<div class="bottom-0">
76+
<p class="text-2xl text-left text-white font-thin">
7477
{#each authors as author, i}
7578
<span>{author.authors_id.name || ''}{#if i < (authors.length-1)}, {/if}</span>
7679
{/each}
7780
</p>
78-
<p class="text-left text-gray-300 font-bold">{date}</p>
81+
<p class="text-left text-gray-300 font-bold">
82+
<HumanDate date={date}/>
83+
<span class="mx-2">·</span>
84+
<ReadingTime text={content}/>
85+
</p>
7986
</div>
8087
</div>
8188

src/components/Cards/ArticleCard.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script>
22
import Badge from "@/components/Badge.svelte";
3+
import HumanDate from "../HumanDate.svelte";
34
export let slug;
45
export let title;
56
export let date;
67
export let image;
78
export let tag;
89
export let authors;
9-
1010
</script>
1111

1212
<a href="/blog/{slug}">
@@ -28,7 +28,7 @@
2828
{/each}
2929
</p>
3030
{/if}
31-
<p class="text-sm text-gray-400">{date}</p>
31+
<p class="text-sm text-gray-400"><HumanDate date={date}/></p>
3232
</div>
3333
</div>
3434
</a>

src/components/HumanDate.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
export let date = '';
3+
export let locale;
4+
function processDate(dateString, locale) {
5+
locale ??= 'es-MX'
6+
let formattedDate = new Date(dateString)
7+
let finalDate = formattedDate.toLocaleString(locale, { day: 'numeric', month: 'short', year: 'numeric' })
8+
return finalDate
9+
}
10+
let finalDate = processDate(date, locale)
11+
</script>
12+
13+
{finalDate}

src/components/ReadingTime.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
export let text = '';
3+
function readingTime(text) {
4+
const words = text.trim().split(/\s+/).length;
5+
const wpm = 255 //average adult reading speed (words per minute).
6+
const time = Math.ceil(words / wpm);
7+
return time;
8+
}
9+
let minutos = readingTime(text)
10+
</script>
11+
12+
Tiempo de lectura: {minutos} minutos
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<script>
22
export let data
3+
import HumanDate from '@/components/HumanDate.svelte';
34
const { aviso } = data
4-
const date_updated = processDate(aviso.date_updated)
5-
function processDate(dateObject, locale) {
6-
locale ??= 'es-mx'
7-
let formattedDate = new Date(dateObject)
8-
let finalDate = formattedDate.toLocaleString(locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' })
9-
return finalDate
10-
}
115
</script>
126

137
<div id="aviso" class="container mx-auto py-20">
148
<div class="w-10/12 p-5 mx-auto w-1/2 mx-auto bg-[url('/grid-bg.png')] bg-slate-200 prose" style={`box-shadow: 7px 7px 1px black;`}>
159
{@html aviso.content}
16-
<p>Ultima actualización: {date_updated}</p>
10+
<p>Ultima actualización: <HumanDate date={aviso.date_updated}/></p>
1711
</div>
1812
</div>
1913

src/routes/blog/+page.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
slug={blog.highlight_post.slug}
1515
title={blog.highlight_post.title}
1616
tag={blog.highlight_post.tags[0]}
17-
date={new Date(blog.highlight_post.date_created).toLocaleString('es-MX')}
17+
date={blog.highlight_post.date_published || blog.highlight_post.date_created}
1818
image={`https://content.codeandomexico.org/assets/${blog.highlight_post.post_image}`}
1919
authors={blog.highlight_post.authors}
20+
content={blog.highlight_post.content}
2021
/>
2122
</div>
2223
<div class="container m-auto p-3">
@@ -27,7 +28,7 @@
2728
title={post.title}
2829
tag={post.tags[0]}
2930
authors={post.authors}
30-
date={new Date(post.date_created).toLocaleString('es-MX')}
31+
date={post.date_published || post.date_created}
3132
image={`https://content.codeandomexico.org/assets/${post.post_image}`}
3233
/>
3334
{/each}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
import ReadingTime from '@/components/ReadingTime.svelte';
3+
import HumanDate from '@/components/HumanDate.svelte';
24
export let data
35
const { post } = data
46
</script>
@@ -13,20 +15,22 @@
1315

1416
<section class="my-10">
1517

16-
<div class="container m-auto p-3 prose">
17-
<h1 class="text-center font-bold">{post.title}</h1>
18+
<div class="container m-auto max-w-prose my-8">
19+
<h1 class="text-5xl font-black my-8">{post.title}</h1>
1820
{#if post.authors}
19-
<p class="text-center">Por
21+
<p class="text-xl my-3">Por
2022
{#each post.authors as author, i }
2123
<span>{author.authors_id.name || ''}{#if i < (post.authors.length-1)}, {/if}</span>
2224
{/each}
2325
</p>
2426
{/if}
25-
<p class="text-center text-sm text-gray-400">{new Date(post.date_created).toLocaleString('es-MX')}</p>
27+
<p class="text-lg text-gray-500">
28+
<ReadingTime text={post.content}/><span class="mx-2">·</span><HumanDate date={post.date_published || post.date_created}/>
29+
</p>
2630
</div>
2731
<img src={`https://content.codeandomexico.org/assets/${post.post_image}`} alt="Imagen de blog" class="w-full max-h-[450px] object-cover" />
2832
<div class="container m-auto p-3 prose prose-blockquote:text-2xl prose-blockquote:border-green-400">
29-
<p>{@html post.content}</p>
30-
</div>
33+
<p class="prose text-lg">{@html post.content}</p>
34+
</div>
3135

3236
</section>

0 commit comments

Comments
 (0)