DATCODE.org is built with Astro and leverages Ghost CMS for content management. This application combines the best of both worlds: fast, static site generation with Astro and powerful content management capabilities of Ghost.
/
βββ public/ # Static assets (images, favicons)
βββ src/
β βββ components/ # UI components
β β βββ Card.astro # Basic card component
β β βββ PostCard.astro # Card for displaying post previews
β β βββ PostList.astro # List of post cards
β β βββ ghost/ # Ghost-specific components
β β βββ GhostContent.tsx # Renders Ghost HTML content
β β βββ GhostRenderer.tsx # Handles different content blocks
β β βββ MemberAuth.tsx # Authentication components
β β βββ cards/ # Specialized card components for Ghost content
β βββ layouts/ # Page layouts
β βββ lib/ # Utility functions and API clients
β β βββ api/ # API integration
β β β βββ ghost/ # Ghost API clients and types
β β β βββ session.ts # Session management
β β βββ ghost/ # Ghost content utilities
β βββ pages/ # Page routes
β β βββ api/ # API endpoints
β β βββ posts/ # Post pages
β β βββ index.astro # Homepage
β βββ style/ # Global styles
βββ package.json
This project integrates with Ghost CMS for content management and membership features. The integration works as follows:
-
Content API Client:
- Located in
src/lib/api/ghost/index.ts - Initializes the Ghost Content API client using environment variables
- Provides functions to fetch posts, tags, and site settings
- Located in
-
Post Retrieval:
getPosts()- Gets a list of posts with full HTML contentgetPostsTextFormat()- Gets posts in text format with only the fields needed for listings, improving performancegetPostBySlug()- Gets a specific post by its slugsearchPosts()- Searches posts by query string
-
Post Display:
PostList.astro- Renders a grid of post cardsPostCard.astro- Displays a post preview with title, excerpt, feature image, etc.- Individual post pages (
[slug].astro) show the full post content
-
Ghost Content Parser:
parseGhostContent.ts- Transforms Ghost HTML content into structured blocks- Handles all Ghost card types (gallery, bookmark, product, file, etc.)
-
Rendering Components:
GhostContent.tsx- Main component that processes HTML or fetches from URLGhostRenderer.tsx- Renders different block types with appropriate components- Card components for specialized content types (galleries, products, etc.)
-
Member API Client:
- Server-side only client for authenticating members
- Handles sign in, sign up, and session management
-
Authentication Flow:
useAuth.ts- React hook for client-side authentication state management- Provides functions for sign in, sign up, and sign out
- Tracks authentication state (loading, error, member data)
-
API Endpoints:
/api/ghost/member.ts- Handles member authentication/api/ghost/access.ts- Checks content access permissions
-
Access Control:
checkMemberAccess()- Utility to determine if a member can access content- Posts can be public or restricted to members only
- Protected content shows a sign-in prompt for non-members
-
User Interface:
UserMenu.tsx- Displays login/signup buttons or member profileMemberAuth.tsx- Authentication components
| Command | Action |
|---|---|
npm install |
Installs dependencies |
npm run dev |
Starts local dev server at localhost:4321 |
npm run build |
Build your production site to ./dist/ |
npm run preview |
Preview your build locally, before deploying |
You need the following environment variables for Ghost integration:
# Ghost Content API (public, for fetching content)
GHOST_BASE_URL=https://your-ghost-blog.com
GHOST_CONTENT_API_KEY=your-content-api-key
# Ghost Admin API (private, for authentication - server-side only)
GHOST_ADMIN_API_KEY=your-admin-api-key
The site uses Tailwind CSS with a custom theme defined in src/style/global.css.