Skip to content

Latest commit

Β 

History

History
115 lines (89 loc) Β· 4.8 KB

File metadata and controls

115 lines (89 loc) Β· 4.8 KB

DATCODE.org

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.

πŸš€ Project Structure

/
β”œβ”€β”€ 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

πŸ“ Ghost CMS Integration

This project integrates with Ghost CMS for content management and membership features. The integration works as follows:

Content Fetching

  1. 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
  2. Post Retrieval:

    • getPosts() - Gets a list of posts with full HTML content
    • getPostsTextFormat() - Gets posts in text format with only the fields needed for listings, improving performance
    • getPostBySlug() - Gets a specific post by its slug
    • searchPosts() - Searches posts by query string
  3. Post Display:

    • PostList.astro - Renders a grid of post cards
    • PostCard.astro - Displays a post preview with title, excerpt, feature image, etc.
    • Individual post pages ([slug].astro) show the full post content

Content Rendering

  1. Ghost Content Parser:

    • parseGhostContent.ts - Transforms Ghost HTML content into structured blocks
    • Handles all Ghost card types (gallery, bookmark, product, file, etc.)
  2. Rendering Components:

    • GhostContent.tsx - Main component that processes HTML or fetches from URL
    • GhostRenderer.tsx - Renders different block types with appropriate components
    • Card components for specialized content types (galleries, products, etc.)

Authentication & Membership

  1. Member API Client:

    • Server-side only client for authenticating members
    • Handles sign in, sign up, and session management
  2. 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)
  3. API Endpoints:

    • /api/ghost/member.ts - Handles member authentication
    • /api/ghost/access.ts - Checks content access permissions
  4. 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
  5. User Interface:

    • UserMenu.tsx - Displays login/signup buttons or member profile
    • MemberAuth.tsx - Authentication components

🧞 Commands

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

βš™οΈ Environment Configuration

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

πŸŒ“ Styling

The site uses Tailwind CSS with a custom theme defined in src/style/global.css.