← All posts

Complete Installation & Setup Guide

Comprehensive guide to install, configure, and deploy this Astro blog with all features enabled

Introduction

Welcome to the complete installation guide! This tutorial will walk you through setting up this modern Astro blog from scratch. By the end, you’ll have a fully functional blog with dark mode, search, pagination, and more.

Info

Prerequisites: Node.js 18+, Git, and a code editor (VS Code recommended)

Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/your-blog.git
cd your-blog

2. Install Dependencies

npm install

This will install all required packages including:

  • Astro core framework
  • Tailwind CSS for styling
  • Pagefind for search
  • Reading time plugin
  • Remark/Rehype plugins
Tip

Using pnpm? Run pnpm install instead for faster installation!

3. Start Development Server

npm run dev

Your blog is now running at http://localhost:4321 πŸŽ‰

Success

Quick Test: Open your browser and navigate to http://localhost:4321. You should see the homepage!

Project Structure

Understanding the project structure helps you navigate and customize effectively:

your-blog/
β”œβ”€β”€ public/              # Static assets
β”‚   β”œβ”€β”€ fonts/          # Custom fonts
β”‚   β”œβ”€β”€ images/         # Images
β”‚   └── robots.txt      # SEO crawler rules
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/     # Reusable components
β”‚   β”‚   β”œβ”€β”€ Header.astro
β”‚   β”‚   β”œβ”€β”€ Footer.astro
β”‚   β”‚   β”œβ”€β”€ TableOfContents.astro
β”‚   β”‚   β”œβ”€β”€ LinkButton.astro
β”‚   β”‚   └── SocialIcon.astro
β”‚   β”œβ”€β”€ content/        # Content collections
β”‚   β”‚   β”œβ”€β”€ config.ts   # Content schema
β”‚   β”‚   └── posts/      # Blog posts (Markdown)
β”‚   β”œβ”€β”€ layouts/        # Page layouts
β”‚   β”‚   β”œβ”€β”€ BaseLayout.astro
β”‚   β”‚   └── PostLayout.astro
β”‚   β”œβ”€β”€ pages/          # Routes
β”‚   β”‚   β”œβ”€β”€ index.astro         # Homepage
β”‚   β”‚   β”œβ”€β”€ about.astro         # About page
β”‚   β”‚   β”œβ”€β”€ search.astro        # Search page
β”‚   β”‚   β”œβ”€β”€ posts/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.astro     # All posts
β”‚   β”‚   β”‚   β”œβ”€β”€ [slug].astro    # Individual post
β”‚   β”‚   β”‚   └── page/[page].astro  # Pagination
β”‚   β”‚   └── tags/
β”‚   β”‚       β”œβ”€β”€ index.astro     # All tags
β”‚   β”‚       └── [tag].astro     # Posts by tag
β”‚   β”œβ”€β”€ styles/         # Global styles
β”‚   β”‚   └── global.css
β”‚   β”œβ”€β”€ utils/          # Utility functions
β”‚   β”‚   └── reading-time.mjs
β”‚   β”œβ”€β”€ config.ts       # Site configuration
β”‚   └── constants.ts    # Constants (social links)
β”œβ”€β”€ plugins/            # Markdown plugins
β”‚   └── remark-admonitions.mjs
β”œβ”€β”€ astro.config.mjs    # Astro configuration
β”œβ”€β”€ package.json        # Dependencies
β”œβ”€β”€ tailwind.config.mjs # Tailwind configuration
└── tsconfig.json       # TypeScript configuration

Configuration

Site Configuration

Edit src/config.ts to customize your site:

export const SITE = {
  title: "Your Blog Name",
  description: "Your blog description",
  url: "https://yoursite.com",
  author: "Your Name",
  showBackButton: true
};
Note

Change these values to match your personal information before deploying!

Update social media links in src/constants.ts:

export const SOCIALS = [
  {
    name: "Github",
    href: "https://github.com/yourusername",
    linkTitle: "Follow me on Github",
    icon: "github"
  },
  {
    name: "Twitter",
    href: "https://twitter.com/yourusername",
    linkTitle: "Follow me on Twitter",
    icon: "twitter"
  },
  {
    name: "LinkedIn",
    href: "https://linkedin.com/in/yourusername",
    linkTitle: "Connect with me on LinkedIn",
    icon: "linkedin"
  }
];

Share Buttons

Configure which social platforms appear on share buttons:

export const SHARE_LINKS = [
  {
    name: "Twitter",
    href: "https://twitter.com/intent/tweet?url=",
    linkTitle: "Share on Twitter",
    icon: "twitter"
  },
  {
    name: "Facebook",
    href: "https://www.facebook.com/sharer/sharer.php?u=",
    linkTitle: "Share on Facebook",
    icon: "facebook"
  },
  // Add or remove platforms as needed
];

Features Overview

✨ Dark Mode

Automatic theme switching with user preference persistence.

How it works:

  • Detects system preference
  • Remembers user choice via localStorage
  • Toggle available in header
  • Prevents flash of unstyled content

Customization: Edit colors in src/styles/global.css

:root {
  --color-accent: #ef4444;  /* Change accent color */
  --bg-primary: #ffffff;
  --text-primary: #1a1a1a;
}

:root.dark {
  --bg-primary: #0a0a0a;
  --text-primary: #e5e5e5;
}

Powered by Pagefind for instant client-side search.

Features:

  • Instant search results
  • Highlights matching text
  • Works entirely offline after first load
  • No backend required

Usage: Navigate to /search or use the search icon in header

Warning

Search index is generated during build. Run npm run build at least once to enable search in development.

πŸ“– Table of Contents

Automatically generated sticky TOC for posts with 2+ headings.

How it works:

  • Extracts H2 and H3 headings
  • Generates anchor links
  • Highlights current section
  • Smooth scroll on click

Customization: Edit src/components/TableOfContents.astro

⏱️ Reading Time

Automatic estimation based on word count.

Formula: ~200 words per minute

Display: Shown in post header alongside date

🏷️ Tag System

Organize and filter posts by topics.

Features:

  • Tag index page showing all tags
  • Individual tag pages with filtered posts
  • Tag counts
  • Hover effects

Usage: Add tags to post frontmatter:

***
tags: ["javascript", "tutorial", "webdev"]
***

πŸ“„ Pagination

Clean pagination for post listings.

Configuration: 15 posts per page (customizable)

Routes:

  • /posts - Page 1
  • /posts/page/2 - Page 2
  • /posts/page/3 - Page 3

Customization: Edit POSTS_PER_PAGE in src/pages/posts/index.astro

🎨 Admonitions

6 types of callout boxes for emphasis.

Types:

  • :::note - General information (Blue)
  • :::tip - Helpful suggestions (Green)
  • :::info - Factual information (Cyan)
  • :::warning - Cautions (Orange)
  • :::danger - Critical warnings (Red)
  • :::success - Positive outcomes (Green)

Usage: See Admonitions Guide

πŸ”— Social Share

Share buttons for major platforms.

Platforms:

  • Twitter
  • Facebook
  • LinkedIn
  • WhatsApp
  • Telegram
  • Copy link

Location: Below post content, above footer navigation

β¬…οΈβž‘οΈ Post Navigation

Previous/Next post links for easy browsing.

Features:

  • Chronological order
  • Shows post titles
  • Hover animations
  • Mobile responsive

Customization

Colors & Themes

Edit src/styles/global.css:

:root {
  /* Accent color */
  --color-accent: #ef4444;
  
  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-surface: #f5f5f5;
  --bg-header: rgba(255, 255, 255, 0.8);
  
  /* Text */
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  
  /* Borders */
  --border-color: #e5e5e5;
}
Tip

Use a color picker to find hex values that match your brand!

Fonts

Adding custom fonts:

  1. Place font files in public/fonts/
  2. Update src/styles/global.css:
@font-face {
  font-family: 'YourFont';
  src: url('/fonts/YourFont.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: 'YourFont', system-ui, sans-serif;
}

Edit src/components/Header.astro:

const navItems = [
  { name: 'about', href: '/about' },
  { name: 'posts', href: '/posts' },
  { name: 'tags', href: '/tags' },
  { name: 'contact', href: '/contact' }, // Add new item
];

Building for Production

Local Build

Test your production build locally:

npm run build
npm run preview

Visit http://localhost:4321 to preview

Info

The build process:

  1. Generates static HTML
  2. Optimizes assets
  3. Creates search index
  4. Generates sitemap

Deployment

  1. Push code to GitHub
  2. Import project in Vercel
  3. Deploy with default settings

Automatic deployments on every push!

Netlify

  1. Push code to GitHub
  2. Import project in Netlify
  3. Build settings:
    • Build command: npm run build
    • Publish directory: dist

GitHub Pages

# Build
npm run build

# Deploy dist folder

Post-Deployment Checklist

After deploying, complete these tasks:

1. Google Search Console

  • Verify ownership (Guide)
  • Submit sitemap
  • Request indexing

2. SEO Setup

  • Update src/config.ts with production URL
  • Create public/favicon.svg
  • Add Open Graph image
  • Test with Google Rich Results

3. Analytics (Optional)

  • Set up Google Analytics
  • Configure Vercel Analytics
  • Add privacy policy

4. Performance

Troubleshooting

Build Errors

β€œModule not found”

rm -rf node_modules package-lock.json
npm install

TypeScript errors

npm run build -- --verbose

Search Not Working

Warning

Search requires a production build to generate the index.

Fix:

npm run build
npm run preview

Reading Time Not Showing

Ensure plugin is enabled in astro.config.mjs:

import { remarkReadingTime } from './src/utils/reading-time.mjs';

export default defineConfig({
  markdown: {
    remarkPlugins: [
      remarkReadingTime  // ← Must be here
    ]
  }
});

Then rebuild:

npm run build

Dark Mode Not Persisting

Check localStorage:

// In browser console
localStorage.getItem('theme')

Should return 'dark' or 'light'

Advanced Features

Custom Pages

Create new pages in src/pages/:

***
import BaseLayout from '../layouts/BaseLayout.astro';
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
***

<BaseLayout title="New Page">
  <Header />
  <main>
    <h1>Your Content</h1>
  </main>
  <Footer />
</BaseLayout>

Content Collections

Add new collections in src/content/config.ts:

const projectsCollection = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    link: z.string().url(),
  })
});

export const collections = {
  posts: postsCollection,
  projects: projectsCollection,  // New collection
};

API Routes

Create API endpoints in src/pages/api/:

// src/pages/api/hello.ts
export async function GET() {
  return new Response(JSON.stringify({
    message: 'Hello World'
  }), {
    headers: { 'Content-Type': 'application/json' }
  });
}

Performance Tips

Image Optimization

Use Astro’s Image component:

***
import { Image } from 'astro:assets';
import myImage from '../assets/image.jpg';
***

<Image src={myImage} alt="Description" />

Code Splitting

Astro automatically splits code. No configuration needed!

Lazy Loading

Images are lazy-loaded by default.

Getting Help

Resources

Common Issues

Check the Troubleshooting section above or search existing issues.

Community Support

Join the Astro Discord for real-time help from the community!

Next Steps

Now that your blog is installed:

  1. βœ… Create your first post
  2. βœ… Learn about admonitions
  3. βœ… Set up Google verification
  4. βœ… Customize colors and fonts
  5. βœ… Deploy to production
Success

Congratulations! Your blog is ready to go. Happy blogging! πŸš€

Comments

Comments are moderated and will be approved shortly.

Loading comments...

Leave a comment