Personal Portfolio Website Builder with Full Code Examples
Personal Portfolio Website Builder with Full Code Examples
Codes

Personal Portfolio Website Builder with Full Code Examples

Building a personal portfolio website builder can be a rewarding project for both developers and end users. This guide offers a step-by-step breakdown, complete with code snippets, to help you create a portfolio website builder using technologies like React.js, Firebase, and Node.js. Features include customizable templates, drag-and-drop functionality, and live hosting options.

Technologies Used

Key Technologies for the Project

  1. React.js: For building the front-end interface.
  2. Firebase: For hosting and real-time database services.
  3. Node.js: To manage server-side logic.

Project Setup

1. Initialize the Project

Start by setting up a new project environment using Node.js and React.

Run the following commands:

bash

# Create a new directory
mkdir portfolio-builder
cd portfolio-builder

# Initialize a Node.js project
npm init -y

# Install React.js and Firebase dependencies
npx create-react-app client
npm install firebase express body-parser cors

2. Set Up Firebase

Create a Firebase Project

  1. Go to Firebase Console and create a new project.
  2. Enable Hosting and Realtime Database in the Firebase dashboard.
  3. Generate a Firebase configuration file.

Install Firebase CLI

Use the following commands to install Firebase CLI and deploy your application:

bash

npm install -g firebase-tools
firebase login
firebase init

Select Hosting during the Firebase initialization process.

Front-End: Building with React.js

The front-end will include components for templates, drag-and-drop functionality, and live previews.

3. Create Template Components

Sample React Template Component

jsx

import React from 'react';

const PortfolioTemplate = ({ title, description, image }) => {
  return (
    <div style={{ border: '1px solid #ccc', padding: '20px', margin: '10px' }}>
      <h2>{title}</h2>
      <p>{description}</p>
      <img src={image} alt="Template Preview" style={{ width: '100%' }} />
    </div>
  );
};

export default PortfolioTemplate;

Render Templates

Add a collection of pre-designed templates:

import React from 'react';
import PortfolioTemplate from './PortfolioTemplate';

const TemplateList = () => {
  const templates = [
    { title: 'Modern Design', description: 'A sleek and minimalist template.', image: 'template1.jpg' },
    { title: 'Creative Layout', description: 'Perfect for artists and designers.', image: 'template2.jpg' },
  ];

  return (
    <div>
      {templates.map((template, index) => (
        <PortfolioTemplate key={index} {...template} />
      ))}
    </div>
  );
};

export default TemplateList;

4. Add Drag-and-Drop Functionality

Install a drag-and-drop library like React DnD:

bash

npm install react-dnd react-dnd-html5-backend

Implement Drag-and-Drop Logic

import React, { useState } from 'react';
import { useDrag, useDrop } from 'react-dnd';

const DraggableElement = ({ id, text, moveItem }) => {
  const [, dragRef] = useDrag({
    type: 'ITEM',
    item: { id },
  });

  return (
    <div ref={dragRef} style={{ padding: '10px', border: '1px solid #000' }}>
      {text}
    </div>
  );
};

const DropZone = ({ onDrop }) => {
  const [, dropRef] = useDrop({
    accept: 'ITEM',
    drop: (item) => onDrop(item.id),
  });

  return (
    <div ref={dropRef} style={{ border: '2px dashed #000', height: '100px', marginTop: '20px' }}>
      Drop Here
    </div>
  );
};

const DragDropContainer = () => {
  const [items, setItems] = useState([{ id: 1, text: 'Element 1' }, { id: 2, text: 'Element 2' }]);

  const moveItem = (id) => {
    const newItems = items.filter((item) => item.id !== id);
    setItems(newItems);
  };

  return (
    <div>
      {items.map((item) => (
        <DraggableElement key={item.id} {...item} moveItem={moveItem} />
      ))}
      <DropZone onDrop={moveItem} />
    </div>
  );
};

export default DragDropContainer;

Back-End: Adding Node.js Logic

Create a basic Node.js Express server to manage APIs for saving user projects and hosting.

5. Set Up an Express Server

server.js

javascript

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');

const app = express();
app.use(bodyParser.json());
app.use(cors());

let userProjects = [];

app.post('/save-project', (req, res) => {
  const { userId, projectData } = req.body;
  userProjects.push({ userId, projectData });
  res.status(200).send('Project saved successfully');
});

app.get('/get-projects', (req, res) => {
  res.status(200).json(userProjects);
});

app.listen(5000, () => console.log('Server running on port 5000'));

Run the server with:

bash

node server.js

Firebase Integration

6. Enable Firebase Hosting

Deploy the front-end React application to Firebase Hosting.

firebase.json

json

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

Build and deploy the project:

bash

npm run build
firebase deploy

Live Preview Implementation

Enable live preview by rendering changes immediately after updates.

7. React Live Preview

const LivePreview = ({ htmlContent }) => {
  return (
    <iframe
      srcDoc={htmlContent}
      style={{ width: '100%', height: '400px', border: '1px solid #ccc' }}
    />
  );
};

export default LivePreview;

FAQs

How do I set up Firebase hosting for my portfolio builder?
Follow Firebase’s documentation to initialize hosting, upload your files, and deploy the project.

Which drag-and-drop library works best with React?
React DnD is a popular choice due to its flexibility and React-friendly API.

How can I make templates more customizable?
Use React props and state to dynamically modify template styles and content.

By combining modern frameworks like React.js and Firebase, you can build a dynamic personal portfolio website builder. From intuitive templates to drag-and-drop functionality and live hosting, the platform you create will empower users to showcase their skills effortlessly. The provided code snippets serve as a starting point, but feel free to expand and customize the project further. Happy coding!

A big thank you for exploring TechsBucket! Your visit means a lot to us, and we’re grateful for your time on our platform. If you have any feedback or suggestions, we’d love to hear them.

Leave a Response