|
1 | | -import config from '../../config.json'; |
2 | | -import { useLanguage, useTranslation } from '../../lib/i18n'; |
| 1 | +import { blogPosts } from '../../route-config.js'; |
| 2 | +import { useTranslate, useBlogTranslate } from '../../lib/i18n'; |
3 | 3 | import { Time } from '../time'; |
4 | 4 | import { prefetchContent } from '../../lib/use-content'; |
5 | 5 | import { BlogPage } from '../routes.jsx'; |
6 | 6 | import s from './style.module.css'; |
7 | 7 |
|
8 | 8 | export default function BlogOverview() { |
9 | | - const [lang] = useLanguage(); |
10 | | - const continueReading = useTranslation('continueReading'); |
| 9 | + const translate = useTranslate(); |
| 10 | + const translateBlog = useBlogTranslate(); |
11 | 11 |
|
12 | | - return ( |
13 | | - <div> |
14 | | - <div class={s.postList}> |
15 | | - {config.blog.map(post => { |
16 | | - //const name = getRouteName(post, lang); |
17 | | - const name = 'FIXME'; |
18 | | - const excerpt = post.excerpt[lang] || post.excerpt.en; |
| 12 | + const posts = []; |
| 13 | + for (const post in blogPosts) { |
| 14 | + const translatedBlog = translateBlog( |
| 15 | + /** @type {keyof typeof blogPosts} */ (post) |
| 16 | + ); |
| 17 | + |
| 18 | + const prefetchAndPreload = () => { |
| 19 | + BlogPage.preload(); |
| 20 | + prefetchContent(post); |
| 21 | + }; |
19 | 22 |
|
20 | | - const prefetchAndPreload = () => { |
21 | | - BlogPage.preload(); |
22 | | - prefetchContent(post.path); |
23 | | - }; |
| 23 | + posts.push( |
| 24 | + <article class={s.post}> |
| 25 | + <div class={s.meta}> |
| 26 | + <Time value={blogPosts[post].date} /> |
| 27 | + </div> |
| 28 | + <h2 class={s.title}> |
| 29 | + <a |
| 30 | + href={post} |
| 31 | + onMouseOver={prefetchAndPreload} |
| 32 | + onTouchStart={prefetchAndPreload} |
| 33 | + > |
| 34 | + {translatedBlog.label} |
| 35 | + </a> |
| 36 | + </h2> |
| 37 | + <p class={s.excerpt}>{translatedBlog.excerpt}</p> |
| 38 | + <a |
| 39 | + href={post} |
| 40 | + onMouseOver={prefetchAndPreload} |
| 41 | + onTouchStart={prefetchAndPreload} |
| 42 | + class="btn-small" |
| 43 | + > |
| 44 | + {translate('i18n', 'continueReading')} → |
| 45 | + </a> |
| 46 | + </article> |
| 47 | + ); |
| 48 | + } |
24 | 49 |
|
25 | | - return ( |
26 | | - <article class={s.post}> |
27 | | - <div class={s.meta}> |
28 | | - <Time value={post.date} /> |
29 | | - </div> |
30 | | - <h2 class={s.title}> |
31 | | - <a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload}>{name}</a> |
32 | | - </h2> |
33 | | - <p class={s.excerpt}>{excerpt}</p> |
34 | | - <a href={post.path} onMouseOver={prefetchAndPreload} onTouchStart={prefetchAndPreload} class="btn-small"> |
35 | | - {continueReading} → |
36 | | - </a> |
37 | | - </article> |
38 | | - ); |
39 | | - })} |
40 | | - </div> |
| 50 | + return ( |
| 51 | + <div> |
| 52 | + <div class={s.postList}>{posts}</div> |
41 | 53 | </div> |
42 | 54 | ); |
43 | 55 | } |
0 commit comments