20
loading...
This website collects cookies to deliver better user experience
.astro
files. They are very much like .jsx
files!# Create folder and navigate to it
mkdir astro-website
cd astro-website
# Init astro project
npm init astro
# Install all dependencies
npm install
# Start Astro!
npm start
Note: The Astro init gives you super cool options for which template and framework to use!
top
endpoint.---
import Card from '../components/Card.astro'
const remoteData = await fetch('https://api.jikan.moe/v3/top/anime/1').then(response => response.json());
---
<main class="grid">
{remoteData.top.map((item) =>
<Card
title="{item.title}"
score="{item.score}"
episodes="{item.episodes}"
href="{item.url}"
image="{item.image_url}"
/>)}
</main>
<style lang="scss">
.grid {
margin: 4rem;
display: grid;
grid-template-columns: repeat(3, 1fr);
@media (max-width: 650px) {
grid-template-columns: repeat(1, 1fr);
margin: 2rem;
}
gap: 3rem;
}
</style>
Card.astro
in the components
library.--------
export interface Props {
title: string;
image: string;
episodes: number;
score: float;
href: string
}
const { title, image, episodes, score, href } = Astro.props;
--------
<article>
<img src={image} alt={title} />
<div class="content">
<a href={href}><h2>{title}</h2></a>
<p>📺 Episodes: {episodes}</p>
<p>⭐️ Rating: {score}</p>
</div>
</article>
<style>
article {
line-height: 1.5;
background: #fff;
border-radius: 8px;
color: #333;
overflow: hidden;
}
img {
max-height: 290px;
width: 100%;
-o-object-fit: cover;
object-fit: cover;
}
.content {
padding: 1rem;
}
h2 {
font-size: 1rem;
margin-bottom: 0.5rem;
}
ul {
list-style: none;
}
</style>
---
that includes our actual code.