fix issues in blog-multiple-authors (#1621)

This commit is contained in:
Fred K. Schott 2021-10-22 05:30:05 -07:00 committed by Drew Powers
parent d1a73e4c38
commit dff64574c4
6 changed files with 27 additions and 30 deletions

View file

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -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"
}
}

View file

@ -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 = 'Dons 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 = 'Dons Blog';
const description = 'An example blog on Astro';
/** filter posts by author, sort by date */
const posts = allPosts

View file

@ -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 = 'Dons 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 = 'Dons 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;
---

View file

@ -128,7 +128,7 @@ export async function ssr({ astroConfig, filePath, logging, mode, origin, pathna
props,
request: {
canonicalURL,
params: {},
params,
url,
},
slots: Object.fromEntries(Object.entries(slots || {}).map(([slotName]) => [slotName, true])),