-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blog Support 1/3: Data fetching (#62)
* Add example blog * Add author data * Improve navigation * Style nav * Add friendly error message * Throw error if import glob used for non-Markdown files * Use import.meta.collection() API instead * README fixes
- Loading branch information
Showing
36 changed files
with
2,359 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
export let author; | ||
--- | ||
|
||
<style lang="scss"> | ||
.card { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.avatar { | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
margin-right: 0.5rem; | ||
object-fit: cover; | ||
border-radius: 50%; | ||
overflow: hidden; | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
</style> | ||
|
||
<div class="card"> | ||
<div class="avatar"> | ||
<img class="avatar" src={author.img} alt={author.name} /> | ||
</div> | ||
{author.name} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
// props | ||
export let title: string; | ||
export let description: string; | ||
export let image: string | undefined; | ||
export let type: string | undefined; | ||
// internal data | ||
const OG_TYPES = { | ||
'movie': 'video.movie', | ||
'television': 'video.tv_show' | ||
} | ||
--- | ||
|
||
<!-- Common --> | ||
<meta charset="UTF-8" /> | ||
<title>{title}</title> | ||
<meta name="description" content={description} /> | ||
<link rel="stylesheet" href="/global.css" /> | ||
|
||
<!-- OpenGraph --> | ||
<meta property="og:title" content={title} /> | ||
<meta property="og:description" content={description} /> | ||
{image && (<meta property="og:image" content={image} />)} | ||
{OG_TYPES[type] && (<meta property="og:type" content={OG_TYPES[type]} />)} | ||
|
||
<!-- Twitter --> | ||
<meta name="twitter:card" content={image ? 'summary_large_image' : 'summary'} /> | ||
<meta name="twitter:site" content="@astro" /> | ||
<meta name="twitter:title" content={title} /> | ||
<meta name="twitter:description" content={description} /> | ||
{image && (<meta name="twitter:image" content={image} />)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<style lang="scss"> | ||
.header { | ||
display: flex; | ||
align-items: center; | ||
padding: 2rem; | ||
} | ||
|
||
.title { | ||
margin: 0; | ||
font-size: 1em; | ||
margin-right: 2rem; | ||
} | ||
|
||
.nav { | ||
display: flex; | ||
} | ||
|
||
ul { | ||
display: flex; | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
margin: 0; | ||
} | ||
|
||
a { | ||
display: block; | ||
margin-left: 1rem; | ||
margin-right: 1rem; | ||
} | ||
</style> | ||
|
||
<nav class="header"> | ||
<h1 class="title">Muppet Blog</h1> | ||
<ul class="nav"> | ||
<li><a href="/">All Posts</a></li> | ||
<li><a href="/?tag=movies">Movies</a></li> | ||
<li><a href="/?tag=television">Television</a></li> | ||
<li><a href="/about">About</a></li> | ||
</ul> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
export let currentPage: number; | ||
export let maxPages: number; | ||
--- | ||
|
||
<nav> | ||
<a href="">Prev</a> | ||
<a href="?p=1">1</a> | ||
<a href="?p=2">2</a> | ||
<a href="?p=3">3</a> | ||
<a href="?p=2">Next</a> | ||
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
export let post; | ||
export let author; | ||
import AuthorCard from './AuthorCard.astro'; | ||
function formatDate(date) { | ||
return new Date(date).toUTCString(); | ||
} | ||
--- | ||
|
||
<style lang="scss"> | ||
.post { | ||
display: grid; | ||
grid-template-columns: 8rem auto; | ||
grid-gap: 1.5rem; | ||
margin-top: 1.5rem; | ||
margin-bottom: 1.5rem; | ||
} | ||
|
||
.thumb { | ||
width: 8rem; | ||
height: 8rem; | ||
object-fit: cover; | ||
border-radius: 0.25rem; | ||
overflow: hidden; | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
|
||
h1 { | ||
font-weight: 700; | ||
font-size: 1em; | ||
margin-bottom: 0; | ||
} | ||
|
||
time { | ||
display: block; | ||
margin-top: 0.5em; | ||
margin-bottom: 0.5em; | ||
} | ||
</style> | ||
|
||
<article class="post"> | ||
<div class="thumb"> | ||
<img src={post.image} alt={post.title} /> | ||
</div> | ||
<div class="data"> | ||
<h1>{post.title}</h1> | ||
<AuthorCard author={author} /> | ||
<time>{formatDate(post.date)}</time> | ||
<p>{post.description}</p> | ||
<a href={post.url}>Read</a> | ||
</div> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"animal": { | ||
"name": "Animal", | ||
"email": "[email protected]", | ||
"img": "/images/animal.jpg" | ||
}, | ||
"kermit": { | ||
"name": "Kermit the Frog", | ||
"email": "[email protected]", | ||
"img": "/images/kermit.jpg" | ||
}, | ||
"ms-piggy": { | ||
"name": "Animal", | ||
"email": "[email protected]", | ||
"img": "/images/ms-piggy.jpg" | ||
}, | ||
"gonzo": { | ||
"name": "Gonzo", | ||
"email": "[email protected]", | ||
"img": "/images/gonzo.jpg" | ||
}, | ||
"rizzo": { | ||
"name": "Rizzo the Rat", | ||
"email": "[email protected]", | ||
"img": "/images/rizzo.jpg" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
import AuthorCard from '../components/AuthorCard.astro'; | ||
import MainHead from '../components/MainHead.astro'; | ||
import Nav from '../components/Nav.astro'; | ||
export let content; | ||
import authorData from '../data/authors.json'; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>{content.title}</title> | ||
<MainHead title={content.title} description={content.description} image={content.image} /> | ||
</head> | ||
|
||
<body> | ||
<Nav /> | ||
|
||
<main class="wrapper"> | ||
<h1>{content.title}</h1> | ||
<AuthorCard author={authorData[content.author]} /> | ||
<article> | ||
<slot /> | ||
</article> | ||
</main> | ||
|
||
<footer> | ||
</footer> | ||
</body> | ||
</html> |
Oops, something went wrong.