summaryrefslogtreecommitdiff
path: root/src/components/widgets/BlogLatestPosts.astro
blob: 28f66d4b3277e83e71d551c6c56cd1c0347cd95c (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
import { APP_BLOG } from 'astrowind:config';

import Grid from '~/components/blog/Grid.astro';

import { getBlogPermalink } from '~/utils/permalinks';
import { findLatestPosts } from '~/utils/blog';
import WidgetWrapper from '~/components/ui/WidgetWrapper.astro';
import type { Widget } from '~/types';
import Button from '~/components/ui/Button.astro';

export interface Props extends Widget {
  title?: string;
  linkText?: string;
  linkUrl?: string | URL;
  information?: string;
  count?: number;
}

const {
  title = await Astro.slots.render('title'),
  linkText = 'View all posts',
  linkUrl = getBlogPermalink(),
  information = await Astro.slots.render('information'),
  count = 4,

  id,
  isDark = false,
  classes = {},
  bg = await Astro.slots.render('bg'),
} = Astro.props;

const posts = APP_BLOG.isEnabled ? await findLatestPosts({ count }) : [];
---

{
  APP_BLOG.isEnabled ? (
    <WidgetWrapper id={id} isDark={isDark} containerClass={classes?.container as string} bg={bg}>
      <div class="flex flex-col lg:justify-between lg:flex-row mb-8">
        {title && (
          <div class="md:max-w-sm">
            <h2
              class="text-3xl font-bold tracking-tight sm:text-4xl sm:leading-none group font-heading mb-2"
              set:html={title}
            />
            {APP_BLOG.list.isEnabled && linkText && linkUrl && (
              <Button variant="link" href={linkUrl}>
                {' '}
                {linkText} »
              </Button>
            )}
          </div>
        )}

        {information && <p class="text-muted dark:text-slate-400 lg:text-sm lg:max-w-md" set:html={information} />}
      </div>

      <Grid posts={posts} />
    </WidgetWrapper>
  ) : (
    <Fragment />
  )
}