Skip to content

cosmic-community/blog-nextjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Modern Blog Platform

App Preview

A beautiful, modern blog platform built with Next.js 16 and powered by Cosmic CMS. Features dynamic content display, category filtering, author profiles, and markdown rendering.

Features

  • πŸ“ Dynamic blog post display with featured images
  • πŸ‘€ Author profiles with bio and social links
  • 🏷️ Category-based filtering and navigation
  • πŸ“± Fully responsive mobile-first design
  • 🎨 Modern UI with Tailwind CSS
  • πŸš€ Built with Next.js 16 App Router
  • πŸ” SEO-optimized with dynamic metadata
  • πŸ“Š Markdown content rendering
  • πŸ–ΌοΈ Automatic image optimization with imgix
  • ⚑ Server-side rendering for optimal performance

Clone this Project

Want to create your own version of this project with all the content and structure? Clone this Cosmic bucket and code repository to get started instantly:

Clone this Project

Prompts

This application was built using the following prompts to generate the content structure and code:

Content Model Prompt

Create a content model for a blog with posts, authors, and categories

Code Generation Prompt

Based on the content model I created for "Create a content model for a blog with posts, authors, and categories", now build a complete web application using Next.js that showcases this content. Include a modern, responsive design with proper navigation, content display, and user-friendly interface.

The app has been tailored to work with your existing Cosmic content structure and includes all the features requested above.

Technologies Used

Getting Started

Prerequisites

  • Node.js 18+ or Bun
  • A Cosmic account and bucket with blog content

Installation

  1. Clone this repository
  2. Install dependencies:
bun install
  1. Create a .env.local file with your Cosmic credentials:
COSMIC_BUCKET_SLUG=your-bucket-slug
COSMIC_READ_KEY=your-read-key
  1. Run the development server:
bun run dev
  1. Open http://localhost:3000 in your browser

Cosmic SDK Examples

Fetching All Posts

import { cosmic } from '@/lib/cosmic'

const { objects: posts } = await cosmic.objects
  .find({ type: 'posts' })
  .props(['id', 'title', 'slug', 'metadata'])
  .depth(1)

Fetching a Single Post by Slug

const { object: post } = await cosmic.objects
  .findOne({
    type: 'posts',
    slug: 'your-post-slug'
  })
  .depth(1)

Filtering Posts by Category

const { objects: posts } = await cosmic.objects
  .find({
    type: 'posts',
    'metadata.categories': categoryId
  })
  .depth(1)

Fetching Author with Posts

const { object: author } = await cosmic.objects
  .findOne({
    type: 'authors',
    slug: 'author-slug'
  })

const { objects: authorPosts } = await cosmic.objects
  .find({
    type: 'posts',
    'metadata.author': author.id
  })
  .depth(1)

Cosmic CMS Integration

This application uses Cosmic's headless CMS to manage all content. The content model includes:

Posts

  • Title and slug
  • Markdown content
  • Featured image
  • Author (object relationship)
  • Categories (objects relationship)
  • Excerpt

Authors

  • Name
  • Bio
  • Avatar image
  • Twitter handle
  • Website URL

Categories

  • Title and slug
  • Description

All relationships are loaded using the depth(1) parameter for efficient data fetching. Images are automatically optimized using Cosmic's imgix integration.

Deployment

Deploy to Vercel

Deploy with Vercel

  1. Click the button above
  2. Connect your Git repository
  3. Add your environment variables:
    • COSMIC_BUCKET_SLUG
    • COSMIC_READ_KEY
  4. Deploy!

Environment Variables

Make sure to set these environment variables in your deployment platform:

COSMIC_BUCKET_SLUG=your-bucket-slug
COSMIC_READ_KEY=your-read-key

Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ layout.tsx          # Root layout with navigation
β”‚   β”œβ”€β”€ page.tsx            # Home page with all posts
β”‚   β”œβ”€β”€ posts/
β”‚   β”‚   └── [slug]/
β”‚   β”‚       └── page.tsx    # Individual post pages
β”‚   β”œβ”€β”€ authors/
β”‚   β”‚   └── [slug]/
β”‚   β”‚       └── page.tsx    # Author profile pages
β”‚   └── categories/
β”‚       └── [slug]/
β”‚           └── page.tsx    # Category filtered posts
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ Header.tsx          # Site header with navigation
β”‚   β”œβ”€β”€ PostCard.tsx        # Post card component
β”‚   β”œβ”€β”€ AuthorInfo.tsx      # Author information display
β”‚   β”œβ”€β”€ CategoryBadge.tsx   # Category badge component
β”‚   └── CosmicBadge.tsx     # "Built with Cosmic" badge
β”œβ”€β”€ lib/
β”‚   └── cosmic.ts           # Cosmic SDK configuration
└── types.ts                # TypeScript type definitions

Learn More

About

Generated by Cosmic AI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published