Custom components
PreCheck
Get ready to...
- Run the
create astro
setup wizard to create a new Astro project - Start the Astro server in development (dev) mode
- View a live preview of your website in your browser
ReadMore
Quiz (Box + MultipleChoice + Option)
Test your knowledge
Which of the following is…
-
A
code
editor, for making changes to your files and their content?
-
An online version control provider for your repository?
-
An application for running commands?
Box with challenge
Try it yourself - Customize your blog post layout
Challenge: Identify items common to every blog post, and use MarkdownPostLayout.astro
to render them, instead of writing them in your Markdown in post-1.md
and in every future blog post.
Here’s an example of refactoring your code to include the pubDate
in the layout component instead of writing it in the body of your Markdown:
Refactor as much as you think is useful to you, and add as much to your layout as you want, remembering that everything that you add to your layout is one less thing you will write in each and every blog post!
Here is an example of a refactored layout that leaves only individual blog post content rendered by the slot. Feel free to use this, or create your own!
Box with challenge and steps
Try it yourself - Add a Blog page
Add a third page blog.astro
to your site, following the same steps as above.
(Don’t forget to add a third navigation link to every page.)
Show me the steps.
- Create a new file at
src/pages/blog.astro
. - Copy the entire contents of
index.astro
and paste them intoblog.astro
. - Add a third navigation link to the top of every page:
Box with spoilers
Analyze the Pattern
Given the following .astro
script:
For each Astro template expression, can you predict the HTML (if any!) that will be sent to the browser? Click to reveal if you’re right!
<p>{operatingSystem}</p>
{student && <p>I am still in school.</p>}
<p>I have {quantity + 8} pairs of {footwear}</p>
{operatingSystem === "MacOS" ? <p>I am using a Mac.</p> : <p>I am not using a Mac.</p>}