Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
How to Create Todo App using Next.js ?
Next article icon

Blogging Platform using Next JS

Last Updated : 13 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this project, we will explore the process of building The Blogging Platform with Next.js. Blogging Platform is a web application that allows users to create and publish blog posts. The platform provides a user-friendly interface for managing blog content and includes functionalities to create new blogs, search for blogs, and read the detailed content of specific blogs.

Output Preview: Let us have a look at how the final output will look like.

gfg-blog

Prerequisites:

  • NPM & NodeJS
  • NextJS
  • NextJS Routing
  • React Hooks

Approach to Create Blogging Platform:

  • Setup the Project by Creating a new NextJS project Install the necessary libraries.
  • Design the layout of blogging platform, including components like Navbar, BlogList, Blogdetail, SearchBar, etc.
  • We will use local storage to store the blog details.
  • We will utilize useState and useEffect hooks to manage state and fetch blog data. we will use useRouter hook to access route parameters such as blog id.
  • Implement a search feature for filtering blog posts based on the search query.
  • We will implement Next.js routing to navigate between different pages (e.g., list of blogs, individual blog posts, create new blogs).
  • We will style the application using bootstrap.

Steps to Create the Blogging Platform:

Step 1: Create a application of NextJS using the following command.

npx create-next-app blog-app

Step 2: Navigate to project directory

cd blog-app

Step 3: Install the necessary package in your project using the following command.

npm install bootstrap

Step 4: Create the folder structure as shown below and create the files in respective folders.

Project Structure:

Screenshot-(18)

The updated dependencies in package.json file will look like:

"dependencies": {
"bootstrap": "^5.3.3",
"next": "14.1.3",
"react": "^18",
"react-dom": "^18"
}

Example: Below are the components which describes the implementation of the Blogging platform.

  • Navbar.js: This component defines a navigation bar for blogging platform. It uses the Link component from Next.js to create links to different pages of the website.
  • Createblog.js: This component allows users to add new blog posts by entering blog details.
  • BlogList.js: This component is responsible to retrieve and display a list of published blog posts.
  • [id].js: This component displays the details of a specific blog post using dynamic routing.
JavaScript
// page.js  import React from 'react' import BlogList from '@/Components/BlogList';  const page = () => {     return (         <>             <BlogList />         </>     ) }  export default page 
JavaScript
// Navbar.js  import React from 'react'; import Link from 'next/link';  const Navbar = () => {     return (         <div>             <nav className="navbar navbar-expand-lg navbar-light                  bg-dark bg-opacity-75 fixed-top text-light">                 <div className="container">                     <Link className="navbar-brand                          text-light font-bold" href="/">                         GFG Blogs                     </Link>                     <button className="navbar-toggler"                         type="button"                          data-toggle="collapse"                         data-target="#navbarNav"                          aria-controls="navbarNav"                         aria-expanded="false"                          aria-label="Toggle navigation">                         <span className="navbar-toggler-icon"></span>                     </button>                     <div className="collapse navbar-collapse"                           id="navbarNav">                         <ul className="navbar-nav mr-auto">                             <li className="nav-item">                                 <Link href="/"                                     className="nav-item nav-link                                                 text-light">                                     Home                                 </Link>                             </li>                             <li className="nav-item">                                 <Link href="/Createblog"                                     className="nav-item nav-link                                                 text-light">                                     Create new Blog                                 </Link>                             </li>                         </ul>                     </div>                 </div>             </nav>         </div>     ); };  export default Navbar; 
JavaScript
// BlogList.js  'use client' import React, {     useState,     useEffect } from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; import Navbar from '@/Components/Navbar'; import Link from 'next/link';  function BlogList() {     const [data, setData] = useState([]);     const [expandedId, setExpandedId] = useState(null);     const [searchQuery, setSearchQuery] = useState('');      useEffect(() => {         const blogs =             JSON.parse(localStorage.getItem('myData') || '[]');         setData(blogs);     }, []);        const toggleExpanded = (id) => {         setExpandedId(expandedId === id ? null : id);     };      let filteredData = data;     if (searchQuery.trim() !== '') {         filteredData = data.filter(item =>             item.title.toLowerCase()                 .includes(searchQuery.toLowerCase())         );     }      return (         <div>             <Navbar />             <div className="container bg-light"                 style={{ marginTop: '5rem' }}>                 <input                     type="text"                     className="form-control mb-2"                     placeholder="Search..."                     value={searchQuery}                     onChange={(e) => setSearchQuery(e.target.value)}                 />                 <div className="row">                     {                         filteredData.map((item) => (                             <div key={item.id} className="col-md-4">                                 <div className="card mb-3">                                     <img src={item.imageUrl}                                          className="card-img-top"                                          alt="Blog" />                                     <div className="card-body">                                         <h5 className="card-title">                                             {item.title}                                         </h5>                                         <p className="card-text">                                             {                                                 expandedId ===                                                     item.id ?                                                     item.description :                                                     `${item.description.substring(0, 50)}...`                                             }                                         </p>                                         <div className="d-flex justify-content-between                                              align-items-center row">                                             <div>                                                 <p className="m-0 small col">                                                     {"posted by "}                                                     {item.author}                                                 </p>                                                 <small className="text-muted">                                                     {item.date}                                                 </small>                                             </div>                                         </div>                                         <Link href={`/blog/${item.id}`}>                                             <button className='btn btn-primary'>                                                 Read more                                             </button>                                         </Link>                                     </div>                                 </div>                             </div>                         ))}                 </div>             </div>         </div>     ); }  export default BlogList; 
JavaScript
// Createblog.js  'use client' import React, { useState, useEffect } from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; import Navbar from '@/Components/Navbar';  const Createblog = () => {     const [author, setAuthor] = useState('');     const [title, setTitle] = useState('');     const [description, setDescription] = useState('');     const [imageUrl, setImageUrl] = useState('');     const initialBlogs =         typeof window !== 'undefined' ?             JSON.parse(localStorage.getItem('myData')) || [] : [];     const [data, setData] = useState(initialBlogs);      useEffect(() => {         // Save habits to localStorage whenever they change         localStorage.setItem('myData', JSON.stringify(data));     }, [data]);      const addData = () => {         const currentDate = new Date().toLocaleDateString();         const newData =         {             id: data.length + 1,             author: author,             date: currentDate,             title: title,             description: description,             imageUrl: imageUrl         };         const updatedData = [...data, newData];         setData(updatedData);         setAuthor('');         setTitle('');         setDescription('');         setImageUrl('');     };      return (         <div>             <Navbar />             <div className="container bg-light"                   style={{ marginTop: '5rem' }}>                 <div className="row">                     <div className="col">                         <input                             type="text"                             className="form-control mb-2"                             placeholder="Author"                             value={author}                             onChange={(e) => setAuthor(e.target.value)}                         />                         <input                             type="text"                             className="form-control mb-2"                             placeholder="Title"                             value={title}                             onChange={(e) => setTitle(e.target.value)}                         />                         <textarea                             className="form-control mb-2"                             placeholder="Description"                             value={description}                             onChange={(e) => setDescription(e.target                                                              .value)}                         />                         <input                             type="text"                             className="form-control mb-2"                             placeholder="Image URL"                             value={imageUrl}                             onChange={(e) =>setImageUrl(e.target.value)}                         />                         <button onClick={addData}                                  className="btn btn-primary mb-2">                             Add Data                         </button>                     </div>                 </div>             </div>         </div>     ); };  export default Createblog; 
JavaScript
// pages/[id].js  import React, {     useEffect,     useState } from 'react'; import { useRouter } from 'next/router'; import Navbar from '@/Components/Navbar'; import 'bootstrap/dist/css/bootstrap.min.css';  const BlogDetails = () => {      const [blogDetail, setBlogDetail] = useState([]);     const router = useRouter();     const { id } = router.query;     useEffect(() => {         const blogs = JSON.parse(localStorage.getItem('myData'));         const selectedBlog=blogs.find(blog => blog.id === parseInt(id));         setBlogDetail(selectedBlog);     }, [id]);       if (!blogDetail) {         return <div>Loading...</div>;     }      return (         <div className="container bg-light"               style={{ marginTop: '5rem' }}>             <Navbar />             <div className="card mt-5">                 <img src={blogDetail.imageUrl}                     style={                         {                             maxWidth: '100%',                             maxHeight: '300px'                         }}                     className="card-img-top" alt="Blog" />                 <div className="card-body">                     <h1 className="card-title">{blogDetail.title}</h1>                     <p className="card-text">                         {blogDetail.description}                     </p>                     <p className="card-text">                         Author: {blogDetail.author}                     </p>                     <p className="card-text">Date: {blogDetail.date}</p>                 </div>             </div>         </div>     ); };  export default BlogDetails; 

Start your application using the following command:

npm run dev

Output: Naviage to the URL http://localhost:3000:

gfg-blog-live


Next Article
How to Create Todo App using Next.js ?
author
yuvrajghule281
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Dev Scripter
  • Next.js
  • Web Development Projects
  • Dev Scripter 2024
  • Next.js - Projects

Similar Reads

  • Blogging Platform using Next JS
    In this project, we will explore the process of building The Blogging Platform with Next.js. Blogging Platform is a web application that allows users to create and publish blog posts. The platform provides a user-friendly interface for managing blog content and includes functionalities to create new
    5 min read
  • How to Create Todo App using Next.js ?
    In this article, we will create a to-do application and understand the basics of Next.js. This to-do list can add new tasks we can also delete the tasks by clicking on them. Next.js is a widely recognized React framework that e­nables server-side­ rendering and enhance­s the developme­nt of interact
    4 min read
  • Document Management System using NextJS
    The Document Management System is a web application developed using Next.js, that allows users to efficiently manage their documents. The system provides features for uploading, organizing, and retrieving documents. Users can upload documents through the web interface, which are then stored in local
    5 min read
  • Create a Quiz App with Next JS
    In this article, we’ll explore the process of building a Quiz App utilizing NextJS. The quiz app provides users with a series of multiple-choice questions with options. Users can select the option and move to the next question. At the end, the user will be able to see the analysis of the quiz. Outpu
    5 min read
  • E-commerce Dashboard with NextJS
    This project is an E-commerce Dashboard built with Next.js, providing features such as a dynamic sidebar, responsive navigation, order analytics, and most sold items of the week. It shows various features such as product analytics, order management, and user interaction. Output Preview: Prerequisite
    11 min read
  • Social Networking Platform using Next.js
    The Social Networking Platform built with NextJS is a web application that provides users the functionality to add a post, like a post, and be able to comment on it. The power of NextJS, a popular React framework for building server-side rendered (SSR) and statically generated web applications, this
    8 min read
  • URL Shortener Service with NextJS
    In this article, we will explore the process of building a URL shortener service using NextJS that takes a long URL and generates a shorter, more condensed version that redirects to the original URL when accessed. This shortened URL is typically much shorter and easier to share, especially in situat
    2 min read
  • Contact Us Form using Next.js
    Creating a Contact Us form in Next.js involves setting up a form component, handling form submissions, and potentially integrating with a backend service or API to send the form data. In this article, we will create a Contact Us Form with NextJS. Output Preview: Let’s have a look at what our final p
    6 min read
  • Blogging Platform using Next JS
    In this project, we will explore the process of building The Blogging Platform with Next.js. Blogging Platform is a web application that allows users to create and publish blog posts. The platform provides a user-friendly interface for managing blog content and includes functionalities to create new
    5 min read
  • Music Player App with Next.js and API
    In this tutorial, we'll create a Music Player App using NextJS, a React framework. Explore frontend development, API integration, and UI design to build a user-friendly app for seamless music enjoyment. Join us in harmonizing code and creativity to craft an engaging Music Player App with NextJS in t
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences