This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 4: Displaying the contents of a single post
- Loading branch information
1 parent
cc125d2
commit 86ce899
Showing
1 changed file
with
23 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
--- | ||
export const prerender = true; | ||
import { Query } from 'appwrite'; | ||
import { databases } from '@/lib/appwrite'; | ||
import Layout from '@/layouts/Layout.astro'; | ||
import Container from '@/components/Container.astro'; | ||
const { postSlug } = Astro.params; | ||
const { documents } = await databases.listDocuments( | ||
import.meta.env.PUBLIC_APPWRITE_DATABASE_ID, | ||
import.meta.env.PUBLIC_APPWRITE_COLLECTION_ID, | ||
[Query.equal('slug', String(postSlug))] | ||
); | ||
if ( !documents.length ) { | ||
return Astro.redirect('/404'); | ||
} | ||
const post = documents[0]; | ||
const publishedDate = new Date(post.$createdAt); | ||
console.log('documents', documents) | ||
--- | ||
<Layout title="Title - My Blog"> | ||
<Layout title={`${post.title} - My Blog`}> | ||
<Container> | ||
<article class="prose mx-auto"> | ||
<h1 class="text-4xl font-extrabold mb-6">Post Title</h1> | ||
|
||
<h1 class="text-4xl font-extrabold mb-6">{ post.title }</h1> | ||
<p class="text-slate-500 mb-14"> | ||
<time datetime="2024-01-15T03:51:30.421Z">Published 1/14/2024</time> | ||
<time datetime={publishedDate.toISOString()}>Published { publishedDate.toLocaleDateString() }</time> | ||
</p> | ||
|
||
<p>Content</p> | ||
<Fragment set:html={post.content} /> | ||
</article> | ||
</Container> | ||
</Layout> |