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.
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
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 π
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
};
Change these values to match your personal information before deploying!
Social Links
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;
}
π Full-Text Search
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
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:
- 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;
}
Use a color picker to find hex values that match your brand!
Fonts
Adding custom fonts:
- Place font files in
public/fonts/ - 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;
}
Navigation
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
The build process:
- Generates static HTML
- Optimizes assets
- Creates search index
- Generates sitemap
Deployment
Vercel (Recommended)
- Push code to GitHub
- Import project in Vercel
- Deploy with default settings
Automatic deployments on every push!
Netlify
- Push code to GitHub
- Import project in Netlify
- Build settings:
- Build command:
npm run build - Publish directory:
dist
- Build command:
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.tswith 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
- Test with PageSpeed Insights
- Optimize images
- Check mobile responsiveness
Troubleshooting
Build Errors
βModule not foundβ
rm -rf node_modules package-lock.json
npm install
TypeScript errors
npm run build -- --verbose
Search Not Working
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
- π Astro Documentation
- π¬ Astro Discord
- π GitHub Issues
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:
- β Create your first post
- β Learn about admonitions
- β Set up Google verification
- β Customize colors and fonts
- β Deploy to production
Congratulations! Your blog is ready to go. Happy blogging! π
Comments
Comments are moderated and will be approved shortly.
Loading comments...
No comments yet. Be the first to comment!
Leave a comment
Insert GIF URL
Paste direct GIF URL from Giphy, Tenor, or any GIF site
Preview: