Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add snippets to home page #102

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions components/SnippetsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import React from 'react'
import Link from 'next/link'
import Image from 'next/image'
import { Snippets } from '../typings'
import { urlFor } from '../sanity'

function SnippetsCard() {

interface Props {
snippet: Snippets
}

function SnippetsCard({snippet}: Props) {
return (
<div className="mb-5 cursor-pointer ">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4 lg:gap-8">
<div className="border border-grey-200 dark:border-gray-800 rounded p-4 w-full bg-gray-50 dark:bg-gray-900 hover:scale-105 transition-transform duration-200 ease-in-out">
<img src='./avatar.jpg' alt='logo' className=' w-10 h-10 rounded-full ' />
<h3 className="text-lg font-bold text-left mt-2 text-gray-900 dark:text-gray-100">
Serverless Code
</h3>
<p className="mt-1 text-gray-700 dark:text-gray-400">Lorem ipsum dolor</p>
</div>
{/* <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 gap-4 lg:gap-8"> */}
<div className="border border-grey-200 dark:border-gray-800 rounded p-4 w-full bg-gray-50 dark:bg-gray-900 hover:scale-105 transition-transform duration-200 ease-in-out">
<img src='./avatar.jpg' alt='logo' className=' w-10 h-10 rounded-full ' />
<img src={urlFor(snippet.mainImage).url()!} alt='logo' className=' w-10 h-10 rounded-full ' />
<h3 className="text-lg font-bold text-left mt-2 text-gray-900 dark:text-gray-100">
Serverless Code
{snippet.title}
</h3>
<p className="mt-1 text-gray-700 dark:text-gray-400">Lorem ipsum dolor</p>
<p className="mt-1 text-gray-700 dark:text-gray-400">{snippet.description}</p>
</div>
</div>
{/* </div> */}
</div>
)
}
Expand Down
121 changes: 72 additions & 49 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,54 @@ import Link from 'next/link'
import SnippetsCard from '../components/SnippetsCard'
import NewsLetter from '../components/NewsLetter'
import Footer from '../components/Footer'
import {sanityClient, urlFor} from '../sanity'
import { sanityClient, urlFor } from '../sanity'

import {Post} from '../typings.d'
import { Post, Snippets } from '../typings.d'
import snippets from './snippets';

interface Props {
posts: [Post]
posts: [Post],
snippets: [Snippets]
}

export default function Home({ posts }: Props) {
export default function Home({ posts, snippets }: Props) {

console.log(snippets)

return (
<Layout title='CloudyS.K.Y - Home'>
{/* <Header /> */}
{/* Header and profile bio */}
<Profile />
{/* Featured posts */}
<div className='pt-5 pl-5 pr-5'>
<h3 className=" font-bold text-2xl md:text-3xl tracking-tight mb-6 text-black dark:text-white">
Featured Blogs
</h3>
{posts.map((post) => (
<FeaturedPosts post={post} key={post._id} />
<FeaturedPosts post={post} key={post._id} />
))}
{/* <FeaturedPosts />
<FeaturedPosts /> */}
<Link
href="/blogs"
className="flex items-center mb-6 text-gray-600 dark:text-gray-400 leading-7 rounded-lg hover:text-gray-800 dark:hover:text-gray-200 transition-all h-6"
>
<>
{'See all blogs'}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
className="h-6 w-6 ml-1"
>
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17.5 12h-15m11.667-4l3.333 4-3.333-4zm3.333 4l-3.333 4 3.333-4z"
/>
</svg>
</>
href="/blogs"
className="flex items-center mb-6 text-gray-600 dark:text-gray-400 leading-7 rounded-lg hover:text-gray-800 dark:hover:text-gray-200 transition-all h-6"
>
<>
{'See all blogs'}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
className="h-6 w-6 ml-1"
>
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17.5 12h-15m11.667-4l3.333 4-3.333-4zm3.333 4l-3.333 4 3.333-4z"
/>
</svg>
</>
</Link>
<h3 className="font-bold text-2xl md:text-3xl tracking-tight mb-6 text-black dark:text-white">
Snippets
Expand All @@ -65,32 +67,40 @@ export default function Home({ posts }: Props) {
instructions. Others are anything from web apps to aws and devsecops
related.
</p>
<SnippetsCard />
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 gap-3 md:gap-6'>
{snippets.map((snippet) => (
<SnippetsCard snippet={snippet} key={snippet._id} />
))}


</div>


<Link
href="/snippets"
className="flex items-center mb-6 text-gray-600 dark:text-gray-400 leading-7 rounded-lg hover:text-gray-800 dark:hover:text-gray-200 transition-all h-6"
>
<>
{'See all snippets'}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
className="h-6 w-6 ml-1"
>
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17.5 12h-15m11.667-4l3.333 4-3.333-4zm3.333 4l-3.333 4 3.333-4z"
/>
</svg>
</>
href="/snippets"
className="flex items-center mb-6 text-gray-600 dark:text-gray-400 leading-7 rounded-lg hover:text-gray-800 dark:hover:text-gray-200 transition-all h-6"
>
<>
{'See all snippets'}
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
className="h-6 w-6 ml-1"
>
<path
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17.5 12h-15m11.667-4l3.333 4-3.333-4zm3.333 4l-3.333 4 3.333-4z"
/>
</svg>
</>
</Link>
<NewsLetter />
<Footer />

</div>
</Layout>

Expand All @@ -116,10 +126,23 @@ export const getServerSideProps = async () => {
slug,
}`;

const snippetsQuery = `*[_type == 'snippets' && Featured == true]{
_id,
_createdAt,
title,
description,
body,
Featured,
mainImage,
slug,
}`

const posts = await sanityClient.fetch(query);
const snippets = await sanityClient.fetch(snippetsQuery);
return {
props: {
posts,
snippets
}
}

Expand Down
17 changes: 17 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ export interface Post {
body: [object];
}

export interface Snippets {
_id: string;
_createdAt: string;
title: string;
// comments: Comment[];
description: string;
mainImage: {
asset: {
url: string;
};
};
slug: {
current: string;
};
body: [object];
}

export interface DetailedPost {
_id: string;
_createdAt: string;
Expand Down