summaryrefslogtreecommitdiff
path: root/README.md
blob: cd6dc621ebe31d07480d9137edbaea78bc35b6d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# Jelly CMS

A fast, lightweight static site generator written in C that supports multilingual content, template partials, and asset management.

## Features

- [x] Multilingual Support**: Automatic locale detection and site generation
- [x] Template Partials**: Reusable HTML components with includes
- [x] Zero Dependencies**: Single executable with no external requirements
- [ ] Markdown support for content
- [ ] CGI support for auth, captcha, comments features
- [ ] Watch mode
- [ ] Serve mode
- [ ] Help command that shows readme

## Quick Start

### Installation

1. Clone or download the project files (`main.c` and `Makefile`)
2. Build the executable:
   ```bash
   make
   ```

### Project Structure

```
your-project/
├── assets/                 # Static assets (images, fonts, etc.)
│   └── images/
│       └── logo.png
├── locale/                 # Locale files (optional)
│   ├── en.json
│   ├── ru.json
│   └── kk.json
├── public/                 # Public files copied as-is
│   ├── robots.txt
│   ├── sitemap.xml
│   └── main.css
├── src/
│   ├── pages/              # Your HTML pages
│   │   ├── index.html
│   │   └── about/
│   │       └── contacts.html
│   └── partials/           # Reusable components
│       ├── header.html
│       └── footer.html
├── vendor/                 # Third-party libraries
│   └── alpinejs.min.js
└── jelly-cms              # The built executable
```

### Build Your Site

```bash
./jelly-cms build
```

This creates a `build/` directory with your generated site.

## Templating

### Including Partials

Use the include syntax to embed reusable components:

```html
<!DOCTYPE html>
<html>
<head>
    <title>My Site</title>
</head>
<body>
    <!-- %include.header% -->
    
    <main>
        <h1>Welcome to my site</h1>
    </main>
    
    <!-- %include.footer% -->
</body>
</html>
```

### Locale Variables

Reference locale-specific content using the locale syntax:

```html
<h1>%locale.welcome_title%</h1>
<p>Contact us: %locale.phone%</p>
<address>%locale.address%</address>
```

## Localization

### Setting Up Locales

1. Create a `locale/` directory
2. Add JSON files for each language (e.g., `en.json`, `ru.json`, `kk.json`)

**Example `locale/en.json`:**
```json
{
  "welcome_title": "Welcome to Our Website",
  "phone": "+1 555 123 4567",
  "address": "123 Main St, City, Country",
  "nav_home": "Home",
  "nav_about": "About",
  "footer_copyright": "© 2024 My Company"
}
```

**Example `locale/ru.json`:**
```json
{
  "welcome_title": "Добро пожаловать на наш сайт",
  "phone": "+7 123 456 7890",
  "address": "ул. Главная 123, Город, Страна",
  "nav_home": "Главная",
  "nav_about": "О нас",
  "footer_copyright": "© 2024 Моя Компания"
}
```

### Build Output

With locales, Jelly CMS generates:
```
build/
├── en/
│   ├── index.html
│   └── about/
│       └── contacts.html
├── ru/
│   ├── index.html
│   └── about/
│       └── contacts.html
├── assets/
│   └── images/
│       └── logo.png
├── vendor/
│   └── alpinejs.min.js
├── robots.txt
├── sitemap.xml
└── main.css
```

Without locales:
```
build/
├── index.html
├── about/
│   └── contacts.html
├── assets/
├── vendor/
├── robots.txt
├── sitemap.xml
└── main.css
```

## Directory Behavior

| Source Directory | Build Behavior |
|-----------------|----------------|
| `assets/` | Copied to `build/assets/` |
| `public/` | Contents copied directly to `build/` root |
| `vendor/` | Copied to `build/vendor/` |
| `src/pages/` | Processed as templates, structure preserved |
| `src/partials/` | Used for includes, not copied to build |
| `locale/` | Used for templating, not copied to build |

## Example Templates

### Main Page (`src/pages/index.html`)
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>%locale.site_title%</title>
    <link rel="stylesheet" href="/main.css">
</head>
<body>
    <!-- %include.header% -->
    
    <main>
        <h1>%locale.welcome_title%</h1>
        <p>%locale.welcome_message%</p>
    </main>
    
    <!-- %include.footer% -->
    <script src="/vendor/alpinejs.min.js"></script>
</body>
</html>
```

### Header Partial (`src/partials/header.html`)
```html
<header>
    <nav>
        <img src="/assets/images/logo.png" alt="Logo">
        <ul>
            <li><a href="/">%locale.nav_home%</a></li>
            <li><a href="/about/">%locale.nav_about%</a></li>
        </ul>
    </nav>
</header>
```

### Footer Partial (`src/partials/footer.html`)
```html
<footer>
    <p>%locale.footer_copyright%</p>
    <p>%locale.contact_info%</p>
</footer>
```

## Build Commands

### Basic Commands
```bash
# Build the site
./jelly-cms build

# Clean build artifacts
make clean

# Rebuild everything
make clean && make && ./jelly-cms build
```

### Make Targets
```bash
make              # Build jelly-cms executable
make clean        # Remove build artifacts
make install      # Install to /usr/local/bin (requires sudo)
make uninstall    # Remove from /usr/local/bin (requires sudo)
make test         # Build and run test
make help         # Show available targets
```

## Advanced Usage

### Nested Partials
Partials can include other partials:

**`src/partials/layout.html`:**
```html
<!DOCTYPE html>
<html>
<head>
    <!-- %include.meta% -->
</head>
<body>
    <!-- %include.header% -->
    <main>
        <!-- Content will be here -->
    </main>
    <!-- %include.footer% -->
</body>
</html>
```

### Complex Directory Structures
```
src/pages/
├── index.html
├── blog/
│   ├── index.html
│   └── posts/
│       ├── first-post.html
│       └── second-post.html
└── products/
    ├── index.html
    └── category/
        └── item.html
```

This structure is preserved in the build output for each locale.

## Troubleshooting

### Common Issues

**Segmentation Fault:**
- Check that all referenced partials exist in `src/partials/`
- Ensure locale JSON files are valid JSON
- Verify file permissions for all source directories

**Missing Files in Build:**
- Ensure source directories exist (`src/pages/`, etc.)
- Check file paths are correct (case-sensitive)
- Verify JSON syntax in locale files

**Locale Variables Not Replaced:**
- Check JSON syntax in locale files
- Ensure locale keys match exactly (case-sensitive)
- Verify locale files are in `locale/` directory

### Debug Mode
Run with verbose output to see detailed processing:
```bash
./jelly-cms build 2>&1 | tee build.log
```

### File Size Limits
- Maximum file size: 64KB per template
- Maximum locale entries: 100 per language
- Maximum locales: 10

## Performance

- **Build Speed**: Processes hundreds of pages in milliseconds
- **Memory Usage**: Minimal RAM footprint (~1-2MB)
- **File Size**: Single ~50KB executable
- **Dependencies**: None (statically linked)

## License

This project is provided as-is. Feel free to modify and distribute according to your needs.

## Contributing

Since this is a simple C program, contributions are welcome:
1. Fork the project
2. Make your changes to `main.c`
3. Test thoroughly
4. Submit a pull request

For bug reports or feature requests, please provide:
- Your project structure
- Locale files (if using multilingual features)
- Error messages or unexpected behavior
- Operating system and compiler version