fix issues in blog-multiple-authors (#1621)
This commit is contained in:
parent
d1a73e4c38
commit
dff64574c4
6 changed files with 27 additions and 30 deletions
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"don": {
|
"don": {
|
||||||
"name": "Don Quixote",
|
"name": "Don Quixote",
|
||||||
"image": "/authors/don.jpg"
|
"image": "/images/don.jpg"
|
||||||
},
|
},
|
||||||
"sancho": {
|
"sancho": {
|
||||||
"name": "Sancho Panza",
|
"name": "Sancho Panza",
|
||||||
"image": "/authors/sancho.jpg"
|
"image": "/images/sancho.jpg"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
import MainHead from '../../components/MainHead.astro';
|
import MainHead from '../../components/MainHead.astro';
|
||||||
import Nav from '../../components/Nav.astro';
|
import Nav from '../../components/Nav.astro';
|
||||||
import PostPreview from '../../components/PostPreview.astro';
|
import PostPreview from '../../components/PostPreview.astro';
|
||||||
import Pagination from '../../components/Pagination.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';
|
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 {
|
interface MarkdownFrontmatter {
|
||||||
date: number;
|
date: number;
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -19,14 +19,10 @@ interface MarkdownFrontmatter {
|
||||||
author: string;
|
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 { 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 */
|
/** filter posts by author, sort by date */
|
||||||
const posts = allPosts
|
const posts = allPosts
|
||||||
|
|
|
@ -3,20 +3,8 @@ import MainHead from '../../components/MainHead.astro';
|
||||||
import Nav from '../../components/Nav.astro';
|
import Nav from '../../components/Nav.astro';
|
||||||
import PostPreview from '../../components/PostPreview.astro';
|
import PostPreview from '../../components/PostPreview.astro';
|
||||||
import Pagination from '../../components/Pagination.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';
|
import authorData from '../../data/authors.json';
|
||||||
|
|
||||||
export async function getStaticPaths({paginate, rss}) {
|
export async function getStaticPaths({paginate, rss}) {
|
||||||
const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md');
|
const allPosts = Astro.fetchContent<MarkdownFrontmatter>('../post/*.md');
|
||||||
const sortedPosts = allPosts.sort((a, b) => new Date(b.date).valueOf() - new Date(a.date).valueOf());
|
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});
|
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;
|
const { page } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ export async function ssr({ astroConfig, filePath, logging, mode, origin, pathna
|
||||||
props,
|
props,
|
||||||
request: {
|
request: {
|
||||||
canonicalURL,
|
canonicalURL,
|
||||||
params: {},
|
params,
|
||||||
url,
|
url,
|
||||||
},
|
},
|
||||||
slots: Object.fromEntries(Object.entries(slots || {}).map(([slotName]) => [slotName, true])),
|
slots: Object.fromEntries(Object.entries(slots || {}).map(([slotName]) => [slotName, true])),
|
||||||
|
|
Loading…
Add table
Reference in a new issue