First Lesson: Setting Up Your Development Environment and Creating a Stylish Front Page

Welcome to the first lesson! In this lesson, we'll cover how to set up your development environment, integrate Bootstrap with Sass, and create a stylish front page using Eleventy.

Step 1: Install Node.js and npm

Node.js is a JavaScript runtime that allows you to run JavaScript on your local machine, and npm (Node Package Manager) is a tool that helps you manage libraries and packages for Node.js.

  1. Visit the Node.js Website:

  2. Download the Installer:

  3. Run the Installer:

  4. Verify the Installation:

Step 2: Create the Project Directory and Initialize Eleventy

  1. Create the Project Directory:

    cd path/to/your/projects
    mkdir ssgatwd-main-site
    cd ssgatwd-main-site
    
  2. Initialize a New npm Project:

    npm init -y
    
  3. Install Eleventy:

    npm install @11ty/eleventy --save-dev
    
  4. Create Basic Directory Structure:

    mkdir src
    mkdir src/_includes
    touch src/index.md
    touch .eleventy.js
    touch .gitignore
    

Step 3: Configure Eleventy and Add Initial Content

  1. Configure Eleventy:

    module.exports = function(eleventyConfig) {
      eleventyConfig.addPassthroughCopy("src/assets");
    
      return {
        dir: {
          input: "src",
          output: "_site",
          includes: "_includes",
        },
      };
    };
    
  2. Add Initial Content:

    ---
    title: Home
    layout: default
    ---
    
    # Welcome to My Main Site
    
    This is the main site where we will host tutorials on creating websites using various static site generators.
    
  3. Create a Layout File:

    
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>{{ title }}</title>
      <link rel="stylesheet" href="/assets/css/main.css">
    </head>
    <body>
      <header>
        <h1>{{ title }}</h1>
      </header>
      <main>
        {{ content | safe }}
      </main>
      <footer>
        <p>&copy; 2024 ssgatwd</p>
      </footer>
    </body>
    </html>
    
    

Step 4: Running Eleventy to Build and Serve the Site Locally

  1. Build the Site:

    npx @11ty/eleventy
    
  2. Install and Set Up browser-sync:

    npm install --save-dev browser-sync
    
  3. Add npm Scripts:

    "scripts": {
      "build": "eleventy",
      "serve": "browser-sync start --no-open --server '_site' --files '_site'",
      "start": "npm run build && npm run serve",
      "sass": "sass --load-path=node_modules src/assets/scss/main.scss src/assets/css/main.css --no-source-map --style=compressed"
    }
    
    {
      "scripts": {
        "build": "eleventy",
        "serve": "browser-sync start --no-open --server '_site' --files '_site'",
        "start": "npm run build && npm run serve",
        "sass": "sass --load-path=node_modules src/assets/scss/main.scss src/assets/css/main.css --no-source-map --style=compressed"
      },
      "devDependencies": {
        "@11ty/eleventy": "^2.0.1",
        "browser-sync": "^3.0.2"
      },
      "dependencies": {
        "bootstrap": "^5.3.3",
        "sass": "^1.77.8"
      }
    }
    
  4. Run the Development Server:

    npm start
    

Step 5: Deploying the Site to Cloudflare Pages

  1. Push Your Code to GitHub:

    git init
    git add .
    git commit -m "Initial commit"
    git remote add origin <your-repo-url>
    git push -u origin main
    
  2. Set Up Cloudflare Pages:

Step 6: Styling the Main Site with Bootstrap and Creating a Front Page

  1. Install Bootstrap and Sass:

    npm install bootstrap@5.3.3 sass
    
  2. Create a Sass File:

    mkdir -p src/assets/scss
    touch src/assets/scss/main.scsss
    
  3. Import Bootstrap and Customize:

    // Import Bootstrap functions and variables
    @import "bootstrap/scss/functions";
    @import "bootstrap/scss/variables";
    
    // Customize Bootstrap variables (optional)
    $primary: #007bff;
    $font-family-base: 'Arial, sans-serif';
    
    // Import Bootstrap components
    @import "bootstrap/scss/bootstrap";
    
  4. Compile Sass to CSS:

    npm run sass
    
  5. Include the Compiled CSS in Your Site:

    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title></title>
      <link rel="stylesheet" href="/assets/css/main.css">
    </head>
    
  6. **Update index.md with Bootstrap Classes:

    ---
    title: Home
    layout: default
    ---
    <div class="container mt-5">
      <div class="jumbotron text-center">
        <h1 class="display-4">Welcome to My Main Site</h1>
        <p class="lead">This is the main site where we will host tutorials on creating websites using various static site generators.</p>
        <hr class="my-4">
        <p>Learn how to create this site step-by-step.</p>
        <a class="btn btn-primary btn-lg" href="/first-lesson" role="button">Start Learning</a>
      </div>
    </div>
    
    
  7. Add Additional Components:

  8. Include Components in Layout:

    
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>{{ title }}</title>
      <link rel="stylesheet" href="/assets/css/main.css">
    </head>
    <body>
      {% include "navbar.njk" %}
      <main>
        {{ content | safe }}
      </main>
      {% include "footer.njk" %}
    </body>
    </html>
    
    

And now you have successfully set up your development environment, configured Eleventy, and created a stylish front page with Bootstrap.