Skip to content

Auth and content rendering #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 71 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
74ba465
refactor: upgrade to astro 5
keaglin Mar 16, 2025
6dbb8bf
infra: prep for dockerization
keaglin Mar 16, 2025
5b70fb4
add tailwind, react and node
keaglin Mar 16, 2025
bb40a32
update deps; pin node version
keaglin Mar 17, 2025
e940fb1
add tailwind theme (generated; ROUGH)
keaglin Mar 17, 2025
a66b885
add ghost content transformer stuff
keaglin Mar 17, 2025
285bf7b
basic ui
keaglin Mar 17, 2025
21ff0b4
feat: auth (start)
keaglin Mar 17, 2025
44b23c7
use server output
keaglin Mar 17, 2025
a6dbfef
prep for automated deploys
keaglin Mar 17, 2025
09123e1
Create test.html
keaglin Mar 17, 2025
298ae44
bring back trash
keaglin Mar 23, 2025
9aefdec
add favicon
keaglin Mar 23, 2025
b2720b3
fix paragraph and heading colors
keaglin Mar 23, 2025
3146b72
constrain img and center
keaglin Mar 23, 2025
0d3f741
constrain excerpt to 7 lines
keaglin Mar 23, 2025
b6fdca8
fix post list styles and make the fetch lighter
keaglin Mar 23, 2025
fba6192
fix tailwind theme using v4 tokens
keaglin Mar 23, 2025
ecc7789
fix styling
keaglin Mar 23, 2025
ef5dec2
Update README.md
keaglin Mar 23, 2025
e727098
Update railway-deploy.yml
keaglin Mar 23, 2025
11c8b8a
separate check from build
keaglin Mar 23, 2025
3e11512
fix Dockerfile
keaglin Mar 23, 2025
b0110cd
make sure the bg color fills the viewport
keaglin Mar 23, 2025
61d2ac0
make search bar dev-only
keaglin Mar 23, 2025
398e65b
Update docker-compose.yml
keaglin Mar 23, 2025
92dabc7
use process instead of import.meta on server side
keaglin Mar 23, 2025
de8d75f
use whatever env works to define secrets
keaglin Mar 27, 2025
9a4abda
use html identity for copyright
keaglin Mar 27, 2025
5916f49
add default body font (serif)
keaglin Mar 27, 2025
24d8e7f
move author block to the top
keaglin Mar 27, 2025
41ce746
use p for paragraphs
keaglin Mar 27, 2025
237bca8
add partial post object from ghost response
keaglin Mar 27, 2025
d9e1de6
unwrap paragraphs
keaglin Mar 27, 2025
2014cb1
fix post first paragraph styling
keaglin Mar 27, 2025
ba5bd61
add style by length for post title
keaglin Mar 27, 2025
17b7096
remove anchor from post author (for now)
keaglin Mar 27, 2025
3a37cac
use svg as component
keaglin Apr 1, 2025
ecebe26
add header nav start
keaglin Apr 1, 2025
bea6448
update paths from /posts/ to /blog/
keaglin Apr 1, 2025
664191c
add hover/focus effect on nav items
keaglin Apr 1, 2025
4d8e37a
add blog post list page structure
keaglin Apr 1, 2025
224162a
styling fixes
keaglin Apr 1, 2025
d430350
use the same layout for posts as for post list
keaglin Apr 1, 2025
7da0948
fix post link and blog index styling
keaglin Apr 1, 2025
4493da9
move twcss to its own file
keaglin Apr 4, 2025
4413dc3
Update trash.css
keaglin Apr 4, 2025
f20742a
lint
keaglin Apr 4, 2025
e83f4ce
continue styling /blog
keaglin Apr 4, 2025
a50f227
start fixing header
keaglin Apr 4, 2025
de57f46
import the twcss file
keaglin Apr 4, 2025
265abc9
add updated graphics
keaglin Apr 13, 2025
2a4a63a
lint
keaglin Apr 13, 2025
b6bf94e
use the existing logo in header
keaglin Apr 13, 2025
fb30dc9
Update index.astro
keaglin Apr 13, 2025
d5eda11
swap out logo
keaglin Apr 13, 2025
a2352bc
lint
keaglin Apr 13, 2025
2f8293e
styles
keaglin Apr 13, 2025
9a660d8
Update ghost-content.css
keaglin Apr 13, 2025
4206576
lint
keaglin Apr 13, 2025
5db2500
setup eslint
keaglin Apr 13, 2025
ddaa076
Update [slug].astro
keaglin Apr 13, 2025
d487982
only show in dev mode
keaglin Apr 13, 2025
9b2c0da
add nav to home page
keaglin Apr 13, 2025
dd2a41a
add padding to images
keaglin Apr 13, 2025
1720b97
changed my mind
keaglin Apr 13, 2025
3a8a078
Update index.astro
keaglin Apr 13, 2025
9003159
improve mobile styles
keaglin Apr 13, 2025
b07da93
Update trash.css
keaglin Apr 14, 2025
863bd7b
Update trash.css
keaglin Apr 14, 2025
c5c5b6e
make logo into a link
keaglin Apr 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/railway-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy to Railway

on:
push:
branches:
- main
paths:
- src/**
- public/**

workflow_dispatch: # Enables manual triggering

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Railway CLI
run: npm install -g @railway/cli

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: ${{ github.repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Deploy to Railway
run: |
railway link --environment production
railway up --detach
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:lts-alpine AS runtime
WORKDIR /app

COPY . .

RUN npm install
RUN npm run build

ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321
CMD ["node", "./dist/server/entry.mjs"]
123 changes: 92 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,115 @@
# Astro Starter Kit: Basics
# DATCODE.org

```sh
npm create astro@latest -- --template basics
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!

![just-the-basics](https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554)
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

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
│ └── favicon.svg
├── public/ # Static assets (images, favicons)
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
│ ├── 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
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
## 📝 Ghost CMS Integration

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.
This project integrates with Ghost CMS for content management and membership features. The integration works as follows:

Any static assets, like images, can be placed in the `public/` directory.
### Content Fetching

## 🧞 Commands
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

All commands are run from the root of the project, from a terminal:
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 |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?
## ⚙️ 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

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
The site uses Tailwind CSS with a custom theme defined in `src/style/global.css`.
21 changes: 19 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { defineConfig } from 'astro/config';
import node from '@astrojs/node'

import react from '@astrojs/react'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'astro/config'

// https://astro.build/config
export default defineConfig({});
export default defineConfig({
output: 'server',
integrations: [react()],

adapter: node({
mode: 'standalone',
}),
vite: {
plugins: [tailwindcss()],
},
experimental: {
svg: true,
},
})
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
app:
build: .
ports:
- "4321:4321"
# sqlite experiment
# volumes:
# - ./data:/app/data
env_file:
- .env.production
restart: unless-stopped
11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import antfu from '@antfu/eslint-config'
import tailwind from "eslint-plugin-tailwindcss";

export default antfu({
formatters: true,
astro: true,
semi: false,
quotes: 'single',
...tailwind.configs["flat/recommended"],
})

Loading