Skip to content

Commit

Permalink
feat: add limiter to the newscomp
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0xity committed Sep 16, 2024
1 parent 45f6ada commit 737defb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/components/NewsComp.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ interface Article {
};
}
type Props = {
articleLimit?: number;
};
const { articleLimit = 0 } = Astro.props;
const fetchArticles = async (): Promise<Article[]> => {
const baseurl = `${import.meta.env.API_URL}api/v2/news/?fields=title,tags,first_published_at,main_image&order=-first_published_at`;
const validLimit = articleLimit >= 1 ? `&limit=${articleLimit}` : '';
const response = await fetch(
`${import.meta.env.API_URL}api/v2/news/?fields=title,tags,first_published_at,main_image&order=-first_published_at&limit=4`,
`${baseurl}${validLimit}`,
);
const data = await response.json();
const articles: Article[] = data.items;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import Hero from '../components/Hero.astro';
<H1 text="JOIN NORWAY'S LARGEST EASTER HUT"/>
</div>
<Hero image="/images/tg23-oversikt.jpg" />
<NewsComp />
<NewsComp articleLimit={4} />
</Main>
</Layout>

0 comments on commit 737defb

Please sign in to comment.