Skip to content

Instantly share code, notes, and snippets.

@sumitkharche
Created October 14, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumitkharche/fec5790bdf0185793cfe383d95247dd5 to your computer and use it in GitHub Desktop.
Save sumitkharche/fec5790bdf0185793cfe383d95247dd5 to your computer and use it in GitHub Desktop.
---
import BaseHead from '../../components/BaseHead.astro';
import Footer from '../../components/Footer.astro';
import Navigation from '../../components/Navigation.astro';
import { apiURL,bucketSlug,readKey} from '../../lib/config';
export async function getStaticPaths() {
const response = await fetch(`https://api.cosmicjs.com/v2/buckets/${bucketSlug}/objects?pretty=true&query=%7B%22type%22%3A%22posts%22%7D&read_key=${readKey}`);
const objs = await response.json();
const allPosts = objs.objects;
return allPosts.map(( post,i) => {
return {
params: { slug: post.slug },
props: {post}
};
});
}
const { slug } = Astro.request.params;
const {post} = Astro.props;
const url = `${post.metadata.image.url}`;
---
<html lang="en">
<head>
<BaseHead />
</head>
<body>
<!-- Navigation-->
<Navigation />
<!-- Page Header-->
<header class="masthead" style={`background-image: url(${post.metadata.image.imgix_url})`}>
<div class="container position-relative px-4 px-lg-5">
<div class="row gx-4 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
<div class="post-heading">
<h1>{post.title}</h1>
<span class="meta">
Posted on
{new Date(post.published_at).toDateString()}
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content-->
<article class="mb-4">
<div class="container px-4 px-lg-5">
<div class="row gx-4 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
{post.metadata.content}
</div>
</div>
</div>
</article>
<!-- Footer-->
<Footer />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment