Skip to content

A Ghost CMS frontend built with Astro and React. Features responsive design, content type support, and interactive UI components.

License

Notifications You must be signed in to change notification settings

SolitudeRA/Solitude-Interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

78 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Solitude Interface

A modern personal blog interface built with Astro and powered by Ghost CMS API. This project is currently under active development.

๐Ÿš€ Project Features

  • High-performance static site built with Astro
  • Ghost CMS integration (Headless)
  • Multi-language support (zh/ja/en) with automatic fallback
  • Responsive design
  • Dark/light theme toggle
  • Multiple post type displays (articles, gallery, video, music)
  • SEO optimized (hreflang, canonical, html lang)
  • Comprehensive testing suite (unit + integration tests)

๐Ÿšง Development Status

This project is currently in active development. Features and documentation will be expanded as the project matures.

๐Ÿ“‚ Project Structure

The project follows a modular structure with separate directories for API integration, components, layouts, and pages.

๐Ÿ”ง Tech Stack

๐Ÿงž Commands

Command Action
npm install Install dependencies
npm run dev Start local dev server at localhost:4321
npm run build Build production site to ./dist/
npm run preview Preview build locally before deploying
npm run format Format code with Prettier
npm test Run tests in watch mode
npm run test:unit Run unit tests only (fast, with mocks)
npm run test:integration Run integration tests (real API calls)
npm run test:coverage Run tests with coverage report
npm run test:ui Open Vitest UI for interactive testing

โš™๏ธ Environment Setup

1. Create Environment File

Create a .env file in the root directory. You can use .env.example as a template:

cp .env.example .env

2. Configure Environment Variables

Edit the .env file with your Ghost instance information:

# Ghost Content API Configuration
GHOST_URL=https://your-ghost-instance.com
GHOST_CONTENT_KEY=your-content-api-key-here
GHOST_VERSION=v5.0

# Your Site URL
SITE_URL=https://your-site.example.com

3. Get Your Ghost Content API Key

  1. Log in to your Ghost Admin panel
  2. Navigate to Settings โ†’ Integrations
  3. Click Add custom integration
  4. Create an integration and copy the Content API Key
  5. Paste the API key into your .env file

Alternative: Use the Ghost Demo API for testing:

GHOST_URL=https://demo.ghost.io
GHOST_CONTENT_KEY=22444f78447824223cefc48062

Note: The demo API is read-only and may have rate limits.

๐Ÿ“‹ Testing

This project includes two types of tests:

  • Unit Tests: Fast tests using mock data, no external dependencies
  • Integration Tests: Tests using real Ghost API to verify actual behavior

Quick Start

# Run all tests
npm test

# Run only unit tests (fast, no API needed)
npm run test:unit

# Run only integration tests (requires .env configuration)
npm run test:integration

๐Ÿงช Running Tests

Unit Tests vs Integration Tests

Feature Unit Tests Integration Tests
Speed โšก Fast (< 1s) ๐ŸŒ Slower (10-30s)
Dependencies โœ… None โš ๏ธ Requires .env + Network
API Calls โŒ Mocked โœ… Real Ghost API
Use Case Daily development Pre-commit verification
Command npm run test:unit npm run test:integration

Available Test Commands

# Watch mode - runs tests on file changes
npm test

# Run all tests once
npm run test:all

# Run unit tests only
npm run test:unit

# Run integration tests only
npm run test:integration

# Generate coverage report
npm run test:coverage

# Open interactive UI
npm run test:ui

What's Tested

Unit Tests (with mocks)

  • Ghost adapter logic (URL transformations, tag extraction)
  • Cloudflare Zero Trust adapter
  • Cache utilities
  • Error handlers
  • API client structure

Integration Tests (with real API)

  • Real Ghost API connection
  • Fetching posts and site information
  • Data structure validation
  • URL adaptation and transformation
  • Tag extraction and categorization
  • Cache performance (first call = API, second call = cache)
  • Error handling with actual endpoints

๐Ÿ—‚๏ธ Test Structure

src/api/__tests__/
โ”œโ”€โ”€ setup.ts                          # Unit test setup (mocks env vars)
โ”œโ”€โ”€ setup.integration.ts              # Integration test setup (uses real env vars)
โ”œโ”€โ”€ adapters/
โ”‚   โ”œโ”€โ”€ ghost.test.ts                 # Unit: Ghost adapter
โ”‚   โ””โ”€โ”€ cloudflare.test.ts            # Unit: Cloudflare adapter
โ”œโ”€โ”€ clients/
โ”‚   โ”œโ”€โ”€ ghost.test.ts                 # Unit: Ghost API client
โ”‚   โ””โ”€โ”€ ghost.integration.test.ts     # Integration: Real API calls
โ”œโ”€โ”€ ghost/
โ”‚   โ”œโ”€โ”€ posts.test.ts                 # Unit: Posts API
โ”‚   โ”œโ”€โ”€ posts.integration.test.ts     # Integration: Real post data
โ”‚   โ”œโ”€โ”€ settings.test.ts              # Unit: Settings API
โ”‚   โ””โ”€โ”€ settings.integration.test.ts  # Integration: Real site info
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ cache.test.ts                 # Unit: Cache utilities
    โ””โ”€โ”€ errorHandlers.test.ts         # Unit: Error handlers

Naming Convention:

  • Unit tests: *.test.ts
  • Integration tests: *.integration.test.ts

๐ŸŒ Multi-language (i18n) Support

This project supports three languages: Chinese (zh), Japanese (ja), and English (en).

URL Structure

Route Description
/ Auto-redirects to user's preferred language
/zh/ Chinese posts listing
/ja/ Japanese posts listing
/en/ English posts listing
/zh/p/{key}/ Chinese version of article
/ja/p/{key}/ Japanese version of article
/en/p/{key}/ English version of article

Ghost Content Tagging (Required)

For multi-language to work, posts in Ghost must have specific internal tags:

  1. Language Tag (required, one of):

    • #lang-zh - Chinese content
    • #lang-ja - Japanese content
    • #lang-en - English content
  2. Translation Group Tag (required):

    • #i18n-{key} - Links translations together
    • Example: #i18n-intro-to-solitude

Example: Creating Multi-language Posts

To create the same article in 3 languages:

Post Title Tags
"Solitude ็ฎ€ไป‹" (Chinese) #lang-zh, #i18n-intro-to-solitude
"Solitude ็ดนไป‹" (Japanese) #lang-ja, #i18n-intro-to-solitude
"Intro to Solitude" (English) #lang-en, #i18n-intro-to-solitude

Fallback Behavior

  • If a language version doesn't exist, the default language (Chinese) is shown
  • A notice banner appears indicating the fallback
  • Language switcher shows available/unavailable versions

Configuration

Default language is set in src/lib/i18n.ts:

export const DEFAULT_LOCALE: Locale = 'zh';

To change the default, modify this value and update astro.config.mjs:

i18n: {
    locales: ['zh', 'en', 'ja'],
    defaultLocale: 'zh',  // Change this
}

๐Ÿ“š Additional Resources

๐Ÿ“„ License

This project is open source and available under the MIT License.

About

A Ghost CMS frontend built with Astro and React. Features responsive design, content type support, and interactive UI components.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •