Teacher: Traversy Media
- https://github.com/bradtraversy/astro-blog
- Video tutorial: https://www.youtube.com/watch?v=XoIHKO6AkoM
npm create astro@latest- Empty
- Typescript? Yes
- TypeScript? Strict
- npx astro add tailwind
- src image
- public image
---
import { Image } from 'astro:assets'
import logo from '../images/logo.png'
---
<image
src="{logo}"
class="h-14"
alt="TechPeople Logo"
width="{55}"
height="{65}"
/>
<image
src="/images/image1.png"
alt="Article Image"
class="w-full h-auto rounded-2xl"
width="{600}"
height="{350}"
/>---
const name = 'John Doe'
console.log(name);
const users = [
{name: 'Goku', age: 36},
{name: 'Gohan', age: 18},
{name: 'Trunks', age: 19},
]
---
<h1>Hello {name}</h1>
<ul>
{users.map((user) => (
<li>{user.name}, {user.age}</li>
))}
</ul>
<script>
const name = 'John Doe'
console.log(name);
</script><MainLayout title='Articles, Stories & Tutorials For Tech People'>
Set up AstroJS types: npx astro sync
---
import MainLayout from '../../layouts/MainLayout.astro'
import { getCollection } from 'astro:content'
import type { CollectionEntry } from 'astro:content'
export async function getStaticPaths() {
const allBlogArticles: CollectionEntry<'blog'>[] = await getCollection('blog')
return allBlogArticles.map((entry) => ({
params: {
slug: entry.slug
},
props: {entry}
}) )
}
const { entry } = Astro.props
---
<MainLayout>
<h1>{entry.data.title}</h1>
</MainLayout>Console.log the slug in the terminal
---
import MainLayout from '../../layouts/MainLayout.astro'
import { getEntry } from 'astro:content'
const { slug } = Astro.params
console.log(slug);
---
<MainLayout>
<h1>Article</h1>
</MainLayout>Printing the data in the console
const { slug } = Astro.params
// console.log(slug);
if (slug === undefined) {
throw new Error('Slug is required')
}
const entry = await getEntry('blog', slug)
console.log(entry)http://localhost:4321/api/search.json?query=boundless
http://localhost:4321/api/search.json?query=test
npx astro add vercel (https://docs.astro.build/en/guides/deploy/)
npm create astro@latest -- --template minimalπ§βπ Seasoned astronaut? Delete this file. Have fun!
Inside of your Astro project, you'll see the following folders and files:
/
βββ public/
βββ src/
β βββ pages/
β βββ index.astro
βββ package.json
Astro looks for .astro or .md files in the src/pages/ directory. Each page is exposed as a route based on its file name.
There's nothing special about src/components/, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
Any static assets, like images, can be placed in the public/ directory.
All commands are run from the root of the project, from a terminal:
| Command | Action |
|---|---|
npm install |
Installs dependencies |
npm run dev |
Starts local dev server at localhost:4321 |
npm run build |
Build your production site to ./dist/ |
npm run preview |
Preview your build locally, before deploying |
npm run astro ... |
Run CLI commands like astro add, astro check |
npm run astro -- --help |
Get help using the Astro CLI |
Feel free to check our documentation or jump into our Discord server.