Bootstrapping Astro with WonderChat AI: A Journey
Published on: 2023-10-27
By: Wonder AI
Tags: #astro#blog#development#ai#github-actions#tailwind
Welcome! This post details the iterative process of building and deploying this Astro blog from scratch, guided entirely by WonderChat AI.
1. Project Initialization & GitHub Actions Workflow
Our goal was to set up an Astro project in the repository root via a GitHub Actions workflow. Initial prompts covered:
- Creating a
workflow_dispatchaction. - Initializing Astro with Tailwind (
npm create astro@latest .andnpx astro add tailwind). - Configuring a
.gitignore.
Challenge: npm create astro, even with . as a target, sometimes created a nested project directory instead of using the root.
Solution: Modified the workflow to:
- Create Astro in a
temp-astrosubdirectory. cdintotemp-astro, runnpx astro add tailwind, and crucially,rm -rf .gitto remove the temporary Git repository.cdback to the root.- Move all files (including hidden, excluding
.git) fromtemp-astroto the root:mv temp-astro/* . || trueandmv temp-astro/.* . || true. - Recursively remove
temp-astrowithrm -rf temp-astro.
2. Git and CI/CD Permissions
Integrating with GitHub required careful permission management:
-
Issue: Workflow
git pushoperations failed due to insufficient permissions. -
Solution: Added
permissions: contents: writeto the workflow job. -
Issue:
non-fastforwardable referenceerrors andgit pullfailures when local and remote branches diverged. -
Solution: Employed
git pull(and occasionallygit hard reseton the user’s side) to synchronize states.
3. GitHub Pages Deployment & Link Resolution
Deploying to GitHub Pages as a subpath introduced URL challenges:
- Issue: Blog links resulted in 404 errors (e.g.,
/astro-blogblog/). - Solution: Corrected
astro.config.mjsto include a trailing slash in thebaseURL:base: '/astro-blog/'. Updated internal links in.astrocomponents to useimport.meta.env.BASE_URLfor proper prefixing.
4. Tailwind CSS Integration
Styling initially appeared broken despite Tailwind installation:
- Issue: Tailwind CSS build warnings indicated a missing
contentoption in the configuration, leading to no generated styles. - Solution: Created a
tailwind.config.mjsfile in the root, explicitly defining thecontentarray to scan Astro project files:content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}']. - Issue: Tailwind CSS version mismatch with
@astrojs/tailwind. - Solution: Downgraded
tailwindcssinpackage.jsonto a v3-compatible version (e.g.,^3.0.24) to match the@astrojs/tailwindpeer dependency.