Skip to content

Commit

Permalink
fix: content retrieval issue for the drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
one-aalam committed Dec 8, 2021
1 parent 8b393fe commit 852f5cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/pages/drafts/[...page].astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ let title = 'Drafts'
let description = 'You\'re viewing a list of unpublished articles on the site. Accuracy or correctness isn\'t guranteed...'
export async function getStaticPaths({ paginate, rss }) {
const allPosts = Astro.fetchContent('../../drafts/*.md');
const sortedPosts = allPosts.sort((a, b) => new Date(b.date) - new Date(a.date));
let allPosts = []
try {
allPosts = Astro.fetchContent('../../drafts/*.md');
} catch(error) {
console.log('No draft posts found while generating the index page for the draft pages')
}
const sortedPosts = allPosts.sort((a, b) => new Date(b.date) - new Date(a.date));
return paginate(sortedPosts, {
pageSize: PAGE_SIZE
Expand Down
7 changes: 6 additions & 1 deletion src/pages/drafts/[slug]/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { getSlugFromPathname } from '$/utils'
import PostDraftPageLayout from '$/layouts/post-draft.astro'
export async function getStaticPaths({ }) {
const allPosts = Astro.fetchContent('../../../drafts/*.md')
let allPosts = []
try {
allPosts = Astro.fetchContent('../../../drafts/*.md')
} catch(error) {
console.log('No draft posts found while generating the draft pages')
}
const allSlugs = new Set()
const allPostsWithSlug = allPosts.map(post => {
// @ts-ignore
Expand Down

0 comments on commit 852f5cf

Please sign in to comment.