Skip to content

Commit 289d40c

Browse files
committed
Update readme
1 parent 6426f82 commit 289d40c

2 files changed

Lines changed: 41 additions & 139 deletions

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Community Page Generator
1+
# Community Pages
22

3-
A Python app that generates HTML pages using JSON data and Jinja2 templates, with Flask development server for live preview.
3+
A Python app that generates HTML pages using JSON data and Jinja2 templates. Features a Flask development server for live preview and GitHub Actions for automated static HTML generation. The deployed pages are will be available at `https://codekitchen.community/<page_name>`.
44

5-
## πŸ“ Project Structure
5+
## Project Structure
66

77
```
88
/
@@ -24,94 +24,50 @@ A Python app that generates HTML pages using JSON data and Jinja2 templates, wit
2424
└── requirements.txt # Dependencies
2525
```
2626

27-
## πŸš€ Features
27+
## Usage
2828

29-
- **Flask Development Server**: Live preview without generating files
30-
- **Multi-page Support**: Each page has its own folder with content, styles, and scripts
31-
- **Inline Assets**: CSS and JS are embedded directly in generated HTML
32-
- **Bilingual Support**: English and Chinese content with language switching
33-
- **CLI Commands**: Flask commands for generation and page management
34-
35-
## πŸ“‹ Usage
29+
Clone the repository and install dependencies:
30+
```bash
31+
git clone https://github.com/codekitchen-community/pages.git
32+
cd pages
33+
pip install -r requirements.txt
34+
```
3635

37-
### Development Server (Live Preview)
36+
### Development
3837
```bash
3938
python app.py
4039
# or
4140
FLASK_APP=app.py flask run
4241
```
4342

4443
Access at:
45-
- `http://localhost:5000/` - Redirect to first page
46-
- `http://localhost:5000/pages` - List all pages
47-
- `http://localhost:5000/readme` - View specific page
44+
- `http://localhost:8000/` - Redirect to first page
45+
- `http://localhost:8000/pages` - List all pages
46+
- `http://localhost:8000/readme` - View specific page
4847

4948
### Generate Static HTML
49+
50+
Static HTML generation is handled automatically by GitHub Actions when you push to the main branch.
51+
52+
For manual generation:
53+
5054
```bash
51-
# Generate all pages
52-
FLASK_APP=app.py flask generate
55+
# Generate all pages (standalone script)
56+
python generate.py
5357

5458
# Generate specific page
55-
FLASK_APP=app.py flask generate readme
56-
57-
# Alternative: standalone script
58-
python generate.py [page_name]
59+
python generate.py readme
5960
```
6061

6162
### Page Management
62-
```bash
63-
# List available pages
64-
FLASK_APP=app.py flask list-pages-cli
6563

64+
```bash
6665
# Create new page
6766
FLASK_APP=app.py flask new-page blog
6867
```
6968

70-
### Installation
71-
```bash
72-
pip install -r requirements.txt
73-
```
74-
75-
## πŸ“„ Page Structure
76-
7769
Each page needs:
7870
- `content.json` - Page content and configuration
7971
- `style.css` - Page-specific styles
8072
- `script.js` - Page-specific JavaScript
8173
- Templates in `templates/{page_name}/` folder
82-
83-
## πŸ”§ Development Workflow
84-
85-
### Live Development
86-
1. Start Flask server: `python app.py`
87-
2. Edit `content.json`, `style.css`, or `script.js`
88-
3. Refresh browser to see changes instantly
89-
4. No generation step needed for preview
90-
91-
### Production Build
92-
1. Generate static files: `flask generate`
93-
2. Use generated `body.html.erb` files for deployment
94-
3. Files are self-contained with inline CSS/JS
95-
96-
### Adding New Pages
97-
```bash
98-
# Option 1: Use Flask command (creates template files)
99-
flask new-page blog
100-
101-
# Option 2: Manual creation
102-
mkdir blog
103-
# Add content.json, style.css, script.js
104-
# Create templates/blog/ folder with templates
105-
```
106-
107-
## 🎨 Flask Routes
108-
109-
- `GET /` - Redirect to first available page
110-
- `GET /pages` - List all available pages with links
111-
- `GET/<page_name>` - Serve specific page dynamically
112-
113-
## πŸ”§ Flask Commands
114-
115-
- `flask generate [page]` - Generate static HTML files
116-
- `flask list-pages-cli` - List available page folders
117-
- `flask new-page <name>` - Create new page with template files

β€Žapp.pyβ€Ž

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
"""
33
Flask App for Community Pages
44
5-
This Flask app serves HTML pages dynamically from JSON data and templates,
6-
allowing preview without generating static files. Also includes CLI commands
7-
for HTML generation.
5+
This Flask app serves HTML pages dynamically from JSON data and templates
6+
for live preview. Static HTML generation is handled by GitHub Actions.
87
"""
98

109
import json
11-
import os
12-
import sys
1310
import click
1411
from pathlib import Path
1512
from flask import Flask, render_template, abort, redirect, url_for
1613
from jinja2 import TemplateNotFound
1714

18-
# Import generator functions
15+
# Import helper functions for live preview
1916
from generate import (
2017
load_data, load_css_content, load_js_content,
21-
find_page_folders, generate_page_html, generate_all_pages
18+
find_page_folders
2219
)
2320

2421
app = Flask(__name__)
@@ -133,53 +130,7 @@ def list_pages():
133130

134131
return html
135132

136-
# CLI Commands
137-
@app.cli.command()
138-
@click.argument('page_name', required=False)
139-
def generate(page_name):
140-
"""Generate static HTML files.
141-
142-
Usage:
143-
flask generate # Generate all pages
144-
flask generate readme # Generate specific page
145-
"""
146-
if page_name:
147-
click.echo(f"πŸ”§ Generating {page_name} page...")
148-
success = generate_page_html(page_name, page_name)
149-
if success:
150-
click.echo(f"βœ… Generated {page_name}/body.html")
151-
else:
152-
click.echo("❌ Generation failed")
153-
sys.exit(1)
154-
else:
155-
click.echo("πŸš€ Generating all pages...")
156-
success = generate_all_pages()
157-
if success:
158-
click.echo("✨ All pages generated successfully!")
159-
else:
160-
click.echo("πŸ’₯ Generation failed!")
161-
sys.exit(1)
162-
163-
@app.cli.command()
164-
def list_pages_cli():
165-
"""List all available page folders."""
166-
page_folders = find_page_folders()
167-
168-
if not page_folders:
169-
click.echo("❌ No page folders found.")
170-
click.echo("πŸ’‘ Create a folder with content.json to add a page.")
171-
return
172-
173-
click.echo("πŸ“ Available pages:")
174-
for page_name in page_folders:
175-
page_folder = Path(page_name)
176-
try:
177-
data = load_data(page_folder)
178-
title = data.get('site', {}).get('title', page_name)
179-
click.echo(f" β€’ {page_name} - {title}")
180-
except:
181-
click.echo(f" β€’ {page_name} - (error loading)")
182-
133+
# CLI Command for creating new pages
183134
@app.cli.command()
184135
@click.argument('page_name')
185136
def new_page(page_name):
@@ -276,21 +227,16 @@ def new_page(page_name):
276227
click.echo(f"🌐 Preview at: http://localhost:8000/{page_name}")
277228

278229
if __name__ == '__main__':
279-
# Check if running with Flask CLI commands
280-
if len(sys.argv) > 1 and sys.argv[1] in ['generate', 'list-pages', 'new-page']:
281-
# This is handled by Flask CLI
282-
pass
283-
else:
284-
# Run the Flask dev server
285-
click.echo("πŸš€ Starting Flask development server...")
286-
click.echo("πŸ“„ Available endpoints:")
287-
click.echo(" β€’ http://localhost:8000/ - Redirect to first page")
288-
click.echo(" β€’ http://localhost:8000/pages - List all pages")
289-
click.echo(" β€’ http://localhost:8000/<page_name> - View specific page")
290-
click.echo("")
291-
click.echo("πŸ”§ Available commands:")
292-
click.echo(" β€’ flask generate [page] - Generate static HTML")
293-
click.echo(" β€’ flask list-pages - List available pages")
294-
click.echo(" β€’ flask new-page <name> - Create new page")
295-
click.echo("")
296-
app.run(debug=True, host='127.0.0.1', port=8000)
230+
# Run the Flask dev server for live preview
231+
click.echo("πŸš€ Starting Flask development server for live preview...")
232+
click.echo("πŸ“„ Available endpoints:")
233+
click.echo(" β€’ http://localhost:8000/ - Redirect to first page")
234+
click.echo(" β€’ http://localhost:8000/pages - List all pages")
235+
click.echo(" β€’ http://localhost:8000/<page_name> - View specific page")
236+
click.echo("")
237+
click.echo("πŸ”§ Available command:")
238+
click.echo(" β€’ flask new-page <name> - Create new page")
239+
click.echo("")
240+
click.echo("πŸ’‘ Static HTML generation is handled by GitHub Actions")
241+
click.echo("")
242+
app.run(debug=True, host='127.0.0.1', port=8000)

0 commit comments

Comments
Β (0)