summaryrefslogtreecommitdiff
path: root/examples/blog-multiple-authors/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/blog-multiple-authors/src')
-rw-r--r--examples/blog-multiple-authors/src/data/authors.json4
-rw-r--r--examples/blog-multiple-authors/src/pages/authors/[author].astro24
-rw-r--r--examples/blog-multiple-authors/src/pages/posts/[...page].astro27
3 files changed, 26 insertions, 29 deletions
diff --git a/examples/blog-multiple-authors/src/data/authors.json b/examples/blog-multiple-authors/src/data/authors.json
index e958e7cd1..1eeff3766 100644
--- a/examples/blog-multiple-authors/src/data/authors.json
+++ b/examples/blog-multiple-authors/src/data/authors.json
@@ -1,10 +1,10 @@
{
"don": {
"name": "Don Quixote",
- "image": "/authors/don.jpg"
+ "image": "/images/don.jpg"
},
"sancho": {
"name": "Sancho Panza",
- "image": "/authors/sancho.jpg"
+ "image": "/images/sancho.jpg"
}
}
diff --git a/examples/blog-multiple-authors/src/pages/authors/[author].astro b/examples/blog-multiple-authors/src/pages/authors/[author].astro
index 13f24c829..a4dbeb129 100644
--- a/examples/blog-multiple-authors/src/pages/authors/[author].astro
+++ b/examples/blog-multiple-authors/src/pages/authors/[author].astro
@@ -1,17 +1,17 @@
---
+
import MainHead from '../../components/MainHead.astro';
import Nav from '../../components/Nav.astro';
import PostPreview from '../../components/PostPreview.astro';
import Pagination from '../../components/Pagination.astro';
-
-// page
-let title = 'Don’s Blog';
-let description = 'An example blog on Astro';
-let canonicalURL = Astro.request.canonicalURL;
-
-// collection
import authorData from '../../data/authors.json';
+export function getStaticPaths() {
+ const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md');
+ let allAuthorsUnique = [...new Set(allPosts.map(p => p.author))];
+ return allAuthorsUnique.map(author => ({params: {author}, props: {allPosts}}));
+}
+
interface MarkdownFrontmatter {
date: number;
description: string;
@@ -19,14 +19,10 @@ interface MarkdownFrontmatter {
author: string;
}
-export function getStaticPaths() {
- const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md');
- let allAuthorsUnique = [...new Set(allPosts.map(p => p.author))];
- return allAuthorsUnique.map(author => ({params: {author}, props: {allPosts}}));
-}
-
const { allPosts } = Astro.props;
-const { params } = Astro.request;
+const { params, canonicalURL } = Astro.request;
+const title = 'Don’s Blog';
+const description = 'An example blog on Astro';
/** filter posts by author, sort by date */
const posts = allPosts
diff --git a/examples/blog-multiple-authors/src/pages/posts/[...page].astro b/examples/blog-multiple-authors/src/pages/posts/[...page].astro
index 65b4067fc..b615d762f 100644
--- a/examples/blog-multiple-authors/src/pages/posts/[...page].astro
+++ b/examples/blog-multiple-authors/src/pages/posts/[...page].astro
@@ -3,20 +3,8 @@ import MainHead from '../../components/MainHead.astro';
import Nav from '../../components/Nav.astro';
import PostPreview from '../../components/PostPreview.astro';
import Pagination from '../../components/Pagination.astro';
-
-// page
-let title = 'Don’s Blog';
-let description = 'An example blog on Astro';
-let canonicalURL = Astro.request.canonicalURL;
-
-// collection
-interface MarkdownFrontmatter {
- date: number;
- description: string;
- title: string;
-}
-
import authorData from '../../data/authors.json';
+
export async function getStaticPaths({paginate, rss}) {
const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md');
const sortedPosts = allPosts.sort((a, b) => new Date(b.date).valueOf() - new Date(a.date).valueOf());
@@ -39,6 +27,19 @@ export async function getStaticPaths({paginate, rss}) {
return paginate(sortedPosts, {pageSize: 1});
}
+// page
+let title = 'Don’s Blog';
+let description = 'An example blog on Astro';
+let canonicalURL = Astro.request.canonicalURL;
+
+// collection
+interface MarkdownFrontmatter {
+ date: number;
+ description: string;
+ title: string;
+}
+
+
const { page } = Astro.props;
---