-
-
Notifications
You must be signed in to change notification settings - Fork 4
Sanity #155
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
Sanity #155
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import groq from 'groq'; | ||
| import { notFound } from 'next/navigation'; | ||
| import { getTranslations } from 'next-intl/server'; | ||
| import { client } from '@/client'; | ||
| import { BlogCategoryGrid } from '@/components/blog/BlogCategoryGrid'; | ||
|
|
||
| export const revalidate = 0; | ||
|
|
||
| type Author = { | ||
| name?: string; | ||
| image?: string; | ||
| }; | ||
|
|
||
| type Post = { | ||
| _id: string; | ||
| title: string; | ||
| slug: { current: string }; | ||
| publishedAt?: string; | ||
| categories?: string[]; | ||
| mainImage?: string; | ||
| body?: any[]; | ||
| author?: Author; | ||
| }; | ||
|
|
||
| type Category = { | ||
| _id: string; | ||
| title: string; | ||
| }; | ||
|
|
||
| const categoriesQuery = groq` | ||
| *[_type == "category"] | order(orderRank asc) { | ||
| _id, | ||
| title | ||
| } | ||
| `; | ||
|
|
||
| export default async function BlogCategoryPage({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ locale: string; category: string }>; | ||
| }) { | ||
| const { locale, category } = await params; | ||
| const t = await getTranslations({ locale, namespace: 'blog' }); | ||
| const categoryKey = String(category || '').toLowerCase(); | ||
| const categories: Category[] = await client | ||
| .withConfig({ useCdn: false }) | ||
| .fetch(categoriesQuery); | ||
| const matchedCategory = categories.find( | ||
| item => slugify(item.title) === categoryKey | ||
| ); | ||
|
|
||
| if (!matchedCategory) return notFound(); | ||
| const categoryTitle = matchedCategory.title; | ||
| const displayTitle = | ||
| categoryTitle === 'Growth' ? 'Career' : categoryTitle; | ||
|
|
||
| const posts: Post[] = await client.withConfig({ useCdn: false }).fetch( | ||
| groq` | ||
| *[_type == "post" && defined(slug.current) && $category in categories[]->title] | ||
| | order(publishedAt desc) { | ||
| _id, | ||
| "title": coalesce(title[$locale], title[lower($locale)], title.uk, title.en, title.pl, title), | ||
| slug, | ||
| publishedAt, | ||
| "categories": categories[]->title, | ||
| "body": coalesce(body[$locale], body[lower($locale)], body.uk, body.en, body.pl, body)[]{ | ||
| ..., | ||
| children[]{ text } | ||
| }, | ||
| "mainImage": mainImage.asset->url, | ||
| "author": author->{ | ||
| "name": coalesce(name[$locale], name[lower($locale)], name.uk, name.en, name.pl, name), | ||
| "image": image.asset->url | ||
| } | ||
| } | ||
| `, | ||
| { locale, category: categoryTitle } | ||
| ); | ||
|
|
||
| return ( | ||
| <main className="max-w-6xl mx-auto px-6 py-12"> | ||
| <h1 className="text-4xl font-bold mb-4 text-center"> | ||
| {displayTitle} | ||
| </h1> | ||
| <div className="mt-12"> | ||
| <BlogCategoryGrid posts={posts} /> | ||
| </div> | ||
| {!posts.length && ( | ||
| <p className="text-center text-gray-500 mt-10">{t('noPosts')}</p> | ||
| )} | ||
| </main> | ||
| ); | ||
| } | ||
|
|
||
| function slugify(value: string) { | ||
| return value | ||
| .toLowerCase() | ||
| .trim() | ||
| .replace(/[^a-z0-9\s-]/g, '') | ||
| .replace(/\s+/g, '-'); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import groq from 'groq'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { client } from '@/client'; | ||
|
|
||
| const searchQuery = groq` | ||
| *[_type == "post" && defined(slug.current)] | order(publishedAt desc) { | ||
| _id, | ||
| "title": coalesce(title.en, title.uk, title.pl, title), | ||
| "body": coalesce(body.en, body.uk, body.pl, body)[]{ | ||
| ..., | ||
| children[]{ text } | ||
| }, | ||
| slug | ||
| } | ||
| `; | ||
|
|
||
| export async function GET() { | ||
| const items = await client.withConfig({ useCdn: false }).fetch(searchQuery); | ||
| return NextResponse.json(items || []); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||
| @import url(https://fonts.googleapis.com/css?family=Lato:100,300,400,700); | ||||||
| @import url(https://raw.github.com/FortAwesome/Font-Awesome/master/docs/assets/css/font-awesome.min.css); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cd /repo && find . -name "globals.css" -o -name "globals.css" | head -5Repository: DevLoversTeam/devlovers.net Length of output: 126 🏁 Script executed: cat -n frontend/app/globals.css | head -20Repository: DevLoversTeam/devlovers.net Length of output: 939 🌐 Web query:
💡 Result: Use jsDelivr (official npm package) for the latest free release — CSS minified (v7.1.0): Sources: Don't load Font Awesome from raw GitHub master. This URL is unversioned and points to the master branch, which can change or break unexpectedly—a supply-chain and stability risk. Use a pinned official CDN URL or install 🔧 Example solutionsOfficial jsDelivr CDN (v7.1.0): -@import url(https://raw.github.com/FortAwesome/Font-Awesome/master/docs/assets/css/font-awesome.min.css);
+@import url(https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@7.1.0/css/all.min.css);Or install locally: -@import url(https://raw.github.com/FortAwesome/Font-Awesome/master/docs/assets/css/font-awesome.min.css);
+@import '@fortawesome/fontawesome-free/css/all.min.css';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| @import 'tailwindcss'; | ||||||
|
|
||||||
| @custom-variant dark (&:is(.dark *)); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||
| 'use client'; | ||||||||||||||||
|
|
||||||||||||||||
| import BlogGrid from '@/components/blog/BlogGrid'; | ||||||||||||||||
| import type { Post } from '@/components/blog/BlogFilters'; | ||||||||||||||||
|
|
||||||||||||||||
| export function BlogCategoryGrid({ posts }: { posts: Post[] }) { | ||||||||||||||||
| if (!posts.length) return null; | ||||||||||||||||
|
|
||||||||||||||||
| return <BlogGrid posts={posts} onAuthorSelect={() => {}} />; | ||||||||||||||||
|
Comment on lines
+6
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent empty-state handling compared to
Consider delegating to 💡 Suggested fix export function BlogCategoryGrid({ posts }: { posts: Post[] }) {
- if (!posts.length) return null;
-
return <BlogGrid posts={posts} onAuthorSelect={() => {}} />;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Category fetch lacks error handling.
If the Sanity client fetch fails, this will throw and crash the layout. Consider wrapping in try-catch with a fallback to an empty array:
This ensures the layout remains functional even if the CMS is temporarily unavailable.
🤖 Prompt for AI Agents