Skip to content

Commit

Permalink
chor: move around and formating.
Browse files Browse the repository at this point in the history
  • Loading branch information
pr0xity committed Sep 29, 2024
1 parent 0e1248c commit a83cdb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/components/NewsComp.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import H2 from './H2.astro';
import H2 from "./H2.astro";
interface Article {
id: number;
meta: {
Expand All @@ -25,18 +26,16 @@ interface Article {
}
type Props = {
articleLimit?: number;
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(
`${baseurl}${validLimit}`,
);
const validLimit = articleLimit >= 1 ? `&limit=${articleLimit}` : "";
const response = await fetch(`${baseurl}${validLimit}`);
const data = await response.json();
const articles: Article[] = data.items;
return articles;
Expand All @@ -63,23 +62,24 @@ const articles = await fetchArticles();
<h3 class="text-xl text-white font-bold mt-2">{article.title}</h3>
<time
datetime={article.meta.first_published_at}
class="text-sm text-gray-500"
>
class="text-sm text-gray-500">
{new Date(article.meta.first_published_at).toLocaleDateString(
"en-US",
{
year: "numeric",
month: "long",
day: "numeric",
},
}
)}
</time>
</div>
{article.main_image && <img
src={article.main_image.full_url}
alt={article.main_image.alt}
class="w-24 h-24 object-cover ml-2 rounded-lg"
/>}
{article.main_image && (
<img
src={article.main_image.full_url}
alt={article.main_image.alt}
class="w-24 h-24 object-cover ml-2 rounded-lg"
/>
)}
</article>
</a>
))
Expand Down
17 changes: 8 additions & 9 deletions src/pages/news/index.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
import Main from '../../components/Main.astro';
import NewsComp from '../../components/NewsComp.astro';
import Layout from '../../layouts/Layout.astro';
import Main from "../../components/Main.astro";
import NewsComp from "../../components/NewsComp.astro";
import Layout from "../../layouts/Layout.astro";
---


<Layout title="The Gathering - News">
<Main>
<NewsComp />
</Main>
</Layout>
<Layout title="The Gathering - News">
<Main>
<NewsComp />
</Main>
</Layout>

0 comments on commit a83cdb5

Please sign in to comment.