This guide explains how to deploy your Obsidian Blogger site to different platforms while ensuring correct URL handling.
The site uses environment variables to handle URLs correctly across different deployment environments:
SITE_URL
: The full URL of your siteBASE_URL
: The base path where your site is served from
SITE_URL=http://localhost:4321
BASE_URL=/
Run the development server:
npm run dev
If your repository is at github.com/username/repo-name
:
SITE_URL=https://username.github.io
BASE_URL=/repo-name/
- Create
.github/workflows/deploy.yml
:
name: Deploy to GitHub Pages
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Build website
run: npm run build
env:
SITE_URL: https://<username>.github.io
BASE_URL: /<repo-name>/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
- Enable GitHub Pages in your repository settings:
- Source: GitHub Actions
If your site is at yourdomain.com
:
SITE_URL=https://yourdomain.com
BASE_URL=/
-
Add environment variables in Netlify dashboard:
- Key:
SITE_URL
, Value:https://yourdomain.com
- Key:
BASE_URL
, Value:/
- Key:
-
Configure build settings:
- Build command:
npm run build
- Publish directory:
dist
- Build command:
-
Add environment variables in Vercel dashboard:
- Key:
SITE_URL
, Value:https://yourdomain.com
- Key:
BASE_URL
, Value:/
- Key:
-
The build settings should be auto-detected
The site automatically handles URLs using the utility functions in src/utils/url.ts
:
// Get correct URL for any path
import { getUrl } from '../utils/url';
// Usage in components
<a href={getUrl('/blog')}>Blog</a>
- Always ensure
SITE_URL
does not end with a slash - Always ensure
BASE_URL
starts and ends with a slash - For GitHub Pages,
BASE_URL
must match your repository name - For custom domains, use
/
asBASE_URL
- Update your sitemap configuration in
astro.config.mjs
if needed
-
404 errors on subpages:
- Check if
BASE_URL
is correctly set - Ensure all internal links use the
getUrl()
function
- Check if
-
Assets not loading:
- Ensure all asset URLs use the
getUrl()
function - Check if public assets are in the correct directory
- Ensure all asset URLs use the
-
GitHub Pages not updating:
- Check GitHub Actions workflow status
- Ensure GitHub Pages is enabled in repository settings
If you encounter any issues:
- Check the Astro deployment docs
- Open an issue in the GitHub repository
- Check existing issues for similar problems