Getting Started
Welcome to BlogFastAI documentation. Follow these steps to get up and running quickly.
Prerequisites
Before you begin, ensure you have the following installed:
- Node.js v20 or later
- pnpm (Package manager)
API Keys Setup
To use BlogFastAI with full functionality, you need to set up API keys for various services. Follow these steps:
- Locate the
.env.example
file in your project root. - Create a new file named
.env
in the same directory. - Copy the contents from
.env.example
to.env
. - Fill in your API keys for the following services:
- OpenAI
- Anthropic
- Replicate
- Exa
- Gemini
- Perplexity
Note: Keep your API keys confidential and never share them publicly.
Installation
Navigate to your project directory:
cd your-project-name
Install the dependencies:
pnpm install
This command will install all the dependencies for the monorepo.
Building the Project
After installation, build the project:
pnpm run build
Running the Servers
Once the build is complete, start the servers:
pnpm start
This command will launch three servers:
- Admin Server: The main dashboard for managing projects and creating/editing articles.
- Blog Server: The main blog server where you can preview and build the blog application.
- Preview Server: Used for previewing individual articles.
Running with Docker
You can also run the application using Docker. Follow these steps to get started:
# Build the Docker image: docker build -t blogfastai .
# Run the container: docker docker run -p 3000:3000 -p 3001:3001 -p 3002:3002 blogfastai
The application will be available at http://localhost:3000
Project Structure
BlogFastAI is organized as a pnpm monorepo project, using SQLite as its database. Understanding the project structure will help you navigate and contribute to the codebase effectively.
The project includes four main directories:
1. apps
This directory contains the Next.js servers for different parts of the application:
- Dashboard server: For managing projects and articles
- Blog server: The main blog application
- Preview server: For previewing individual articles
2. data
This directory contains the SQLite database file:
sqlite.db
: Stores all data for your project
Note: It's recommended to keep a backup of this file after significant work, although this is optional.
3. packages/content-generator
This package contains core functions for generating articles and projects, including:
- API calls
- Prompts
- Database operations
4. packages/shared
This directory includes shared functions that are used across different packages and apps in the monorepo.
Understanding this structure will help you:
- Locate specific functionality within the project
- Understand the separation of concerns between different parts of the application
- Contribute to the project more effectively
Deployment
Once you've created and customized your blog, you'll want to deploy it for the world to see. Follow these simple steps to deploy your BlogFastAI project.
Generate a Production Build
- In the BlogFastAI dashboard, locate and click the "Download Build" button.
- This action will create a production-ready build of your blog in a zip folder.
Prepare the Build
- Extract the contents of the zip folder to your local machine.
- Rename the extracted folder to "blog".
Deploy the Build
- Place the "blog" folder in any location capable of serving static folders.
Deploy to Next.js
To deploy your blog to a Next.js project, add the following rewrites to your
next.config.js
file:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
async rewrites() { return [ { source: "/blog", destination: "/blog/index.html", }, { source: "/blog/page/:pagenumber", destination: "/blog/page/:pagenumber.html", }, { source: "/blog/posts/:slug", destination: "/blog/posts/:slug.html", }, ]; },
These rewrites will ensure that your static blog pages are correctly served by the Next.js server.
Deploy to Nuxt.js
To deploy your blog to a Nuxt.js project, add the following file
rewrite.ts
under theserver/middleware
folder with the following content:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
export default defineEventHandler((event) => { const url = getRequestURL(event).pathname; if (!url) return; // Handle blog/page/number const pageMatch = url.match(/^\/blog\/page\/(\d+)$/); if (pageMatch) { return sendRedirect(event, `/blog/page/${pageMatch[1]}.html`); } // Handle blog/posts/slug const postMatch = url.match(/^\/blog\/posts\/([^/]+)$/); if (postMatch) { return sendRedirect(event, `/blog/posts/${postMatch[1]}.html`); } // Handle basic blog path if (url === '/blog') { return sendRedirect(event, '/blog/index.html'); } });
This middleware will ensure that your static blog pages are correctly served by the Nuxt.js server.
Deploy to Vite
To deploy your blog to a Vite project, copy build output add the following plugin to your
vite.config.js plugins array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
plugins: [ { name: "rewrite-middleware", configureServer(server) { server.middlewares.use((req, res, next) => { // Extract URL without query parameters const url = req.url?.split("?")[0]; if (!url) { return next(); } // Basic blog index if (url === "/blog") { req.url = "/blog/index.html"; return next(); } // Blog page number const pageMatch = url.match(/^\/blog\/page\/(\d+)$/); if (pageMatch) { req.url = `/blog/page/${pageMatch[1]}.html`; return next(); } // Blog posts const postMatch = url.match(/^\/blog\/posts\/([^/]+)$/); if (postMatch) { req.url = `/blog/posts/${postMatch[1]}.html`; return next(); } next(); }); }, }, ],
This plugin will ensure that your static blog pages are correctly served by the Vite server.
Deploy to Astro
To deploy your blog to an Astro project, copy and paste the following configuration to your
astro.config.mjs
file:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
import { defineConfig } from "astro/config"; export default defineConfig({ vite: { plugins: [ { name: "rewrite-middleware", configureServer(server) { server.middlewares.use((req, res, next) => { // Extract URL without query parameters const url = req.url?.split("?")[0]; if (!url) { return next(); } // Basic blog index if (url === "/blog") { req.url = "/blog/index.html"; return next(); } // Blog page number const pageMatch = url.match(/^\/blog\/page\/(\d+)$/); if (pageMatch) { req.url = `/blog/page/${pageMatch[1]}.html`; return next(); } // Blog posts const postMatch = url.match(/^\/blog\/posts\/([^/]+)$/); if (postMatch) { req.url = `/blog/posts/${postMatch[1]}.html`; return next(); } next(); }); }, }, ], }, });
This configuration will ensure that your static blog pages are correctly served by the Astro server.
Congratulations!
Your blog is now ready to be served. The static files in the "blog" folder contain your entire blog, which can be easily hosted on various platforms that support static site hosting.
Deployment Options
Here are some popular options for hosting your static blog:
- GitHub Pages: Free and easy to set up for GitHub repositories.
- Netlify: Offers continuous deployment from Git and global CDN.
- Vercel: Excellent for Next.js projects with easy deployment and previews.
- Amazon S3: Scalable and cost-effective for larger sites.
Image Upload
BlogFastAI supports image uploads to either Amazon S3 or Cloudflare, depending on the value of the STORAGE_TYPE
environment variable.
Amazon S3
If STORAGE_TYPE="S3"
, the following environment variables must be set:
AWS_ACCESS_KEY="your-aws-access-key"
AWS_SECRET_KEY="your-aws-secret-key"
AWS_BUCKET_NAME="your-aws-bucket-name"
AWS_BUCKET_PUBLIC_URL="your-aws-bucket-url"
AWS_REGION="your-aws-region"
Cloudflare
If STORAGE_TYPE
is not set to "S3", the following environment variables must be set for Cloudflare:
CF_ACCOUNT_ID="your-cloudflare-account-id"
CF_ACCESS_KEY="your-cloudflare-access-key"
CF_SECRET="your-cloudflare-secret"
CF_BUCKET_NAME="your-cloudflare-bucket-name"
CF_BUCKET_PUBLIC_URL="your-cloudflare-bucket-url"