opentwig 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +323 -0
- package/API.md +582 -0
- package/CODE_OF_CONDUCT.md +91 -0
- package/CONTRIBUTING.md +312 -0
- package/README.md +164 -7
- package/SECURITY.md +56 -0
- package/THEME_DEVELOPMENT.md +388 -0
- package/package.json +19 -3
- package/src/constants.js +14 -2
- package/src/index.js +14 -2
- package/src/live-ui/editor.js +173 -0
- package/src/live-ui/preview.js +77 -0
- package/src/live-ui/sidebar.js +523 -0
- package/src/utils/escapeHTML.js +10 -0
- package/src/utils/generateOGImage.js +51 -10
- package/src/utils/parseArgs.js +33 -2
- package/src/utils/readImageAsBase64.js +16 -4
- package/src/utils/setupWatcher.js +69 -0
- package/src/utils/showHelp.js +15 -2
- package/src/utils/startLiveServer.js +218 -0
- package/src/utils/websocketServer.js +53 -0
- package/test-og.js +40 -0
- package/theme/dark/style.css +1 -0
- package/theme/default/index.js +10 -8
- package/validateConfig.js +59 -0
- package/vitest.config.js +11 -0
package/API.md
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
# Utility Functions API Reference
|
|
2
|
+
|
|
3
|
+
This document provides detailed API documentation for all utility functions in OpenTwig.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Build Pipeline](#build-pipeline)
|
|
8
|
+
- [Configuration](#configuration)
|
|
9
|
+
- [Theme Management](#theme-management)
|
|
10
|
+
- [Content Generation](#content-generation)
|
|
11
|
+
- [File Operations](#file-operations)
|
|
12
|
+
- [Utilities](#utilities)
|
|
13
|
+
- [CLI Utilities](#cli-utilities)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Build Pipeline
|
|
18
|
+
|
|
19
|
+
### buildPage()
|
|
20
|
+
|
|
21
|
+
**Location:** `src/utils/buildPage.js`
|
|
22
|
+
|
|
23
|
+
Orchestrates the entire page building process by calling all generation functions.
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
const buildPage = async (config) => { ... }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Parameters:**
|
|
30
|
+
- `config` (Object) - The configuration object
|
|
31
|
+
|
|
32
|
+
**Returns:** `Promise<Object>` - Object containing:
|
|
33
|
+
- `html` (String) - Generated HTML
|
|
34
|
+
- `css` (String) - Processed CSS (or null if not found)
|
|
35
|
+
- `ogImage` (Buffer) - Open Graph image buffer (JPG)
|
|
36
|
+
- `qrImage` (String) - QR code SVG string
|
|
37
|
+
- `theme` (Function) - Theme template function
|
|
38
|
+
|
|
39
|
+
**Throws:** `Error` - If any step in the build process fails
|
|
40
|
+
|
|
41
|
+
**Example:**
|
|
42
|
+
```javascript
|
|
43
|
+
const config = loadConfig();
|
|
44
|
+
const { html, css, ogImage, qrImage, theme } = await buildPage(config);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
### loadConfig()
|
|
52
|
+
|
|
53
|
+
**Location:** `src/utils/loadConfig.js`
|
|
54
|
+
|
|
55
|
+
Loads the configuration file from the current working directory and applies default values.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const loadConfig = () => { ... }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Parameters:** None
|
|
62
|
+
|
|
63
|
+
**Returns:** `Object` - Configuration object with defaults applied
|
|
64
|
+
|
|
65
|
+
**Exits:** Process exits with code 1 if `config.json` is not found
|
|
66
|
+
|
|
67
|
+
**Example:**
|
|
68
|
+
```javascript
|
|
69
|
+
const config = loadConfig();
|
|
70
|
+
console.log(config.theme); // 'default'
|
|
71
|
+
console.log(config.name); // 'Your Name'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### applyDefaults()
|
|
75
|
+
|
|
76
|
+
**Location:** `src/utils/configDefaults.js`
|
|
77
|
+
|
|
78
|
+
Applies default values to a configuration object. Avatar has special handling with no defaults.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const applyDefaults = (config) => { ... }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Parameters:**
|
|
85
|
+
- `config` (Object) - The configuration object to apply defaults to
|
|
86
|
+
|
|
87
|
+
**Returns:** `Object` - Configuration with defaults applied
|
|
88
|
+
|
|
89
|
+
**Example:**
|
|
90
|
+
```javascript
|
|
91
|
+
const partialConfig = { theme: 'dark', name: 'John Doe' };
|
|
92
|
+
const fullConfig = applyDefaults(partialConfig);
|
|
93
|
+
// fullConfig now includes all default values for missing fields
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### DEFAULT_CONFIG
|
|
97
|
+
|
|
98
|
+
**Location:** `src/utils/configDefaults.js`
|
|
99
|
+
|
|
100
|
+
Object containing all default configuration values.
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
const DEFAULT_CONFIG = {
|
|
104
|
+
theme: 'default',
|
|
105
|
+
title: 'OpenTwig 🌿',
|
|
106
|
+
minify: true,
|
|
107
|
+
name: 'Your Name',
|
|
108
|
+
content: 'Hello World! Here is my bio.',
|
|
109
|
+
url: 'https://links.yourwebsite.com',
|
|
110
|
+
links: [],
|
|
111
|
+
footerLinks: [],
|
|
112
|
+
share: {
|
|
113
|
+
title: 'Your Name - opentwig 🌿',
|
|
114
|
+
url: 'https://links.yourwebsite.com',
|
|
115
|
+
text: 'Share'
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### SAMPLE_CONFIG
|
|
121
|
+
|
|
122
|
+
**Location:** `src/utils/configDefaults.js`
|
|
123
|
+
|
|
124
|
+
Complete sample configuration used by the `--init` command.
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
const SAMPLE_CONFIG = {
|
|
128
|
+
theme: 'default',
|
|
129
|
+
url: 'https://links.yourwebsite.com',
|
|
130
|
+
title: 'Your Name - opentwig 🌿',
|
|
131
|
+
name: 'Your Name',
|
|
132
|
+
content: 'Hello World! Here is my bio.',
|
|
133
|
+
minify: true,
|
|
134
|
+
avatar: {
|
|
135
|
+
path: 'avatar.png'
|
|
136
|
+
},
|
|
137
|
+
links: [...],
|
|
138
|
+
footerLinks: [...],
|
|
139
|
+
share: { ... }
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Theme Management
|
|
146
|
+
|
|
147
|
+
### loadTheme()
|
|
148
|
+
|
|
149
|
+
**Location:** `src/utils/loadTheme.js`
|
|
150
|
+
|
|
151
|
+
Loads the theme template function from the theme directory. Handles both NPX package and local development paths.
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
const loadTheme = (config) => { ... }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Parameters:**
|
|
158
|
+
- `config` (Object) - Configuration object containing `theme` property
|
|
159
|
+
|
|
160
|
+
**Returns:** `Function` - Theme template function that accepts `config` and returns HTML string
|
|
161
|
+
|
|
162
|
+
**Exits:** Process exits with code 1 if theme is not found
|
|
163
|
+
|
|
164
|
+
**Example:**
|
|
165
|
+
```javascript
|
|
166
|
+
const theme = loadTheme({ theme: 'dark' });
|
|
167
|
+
const html = theme(config);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Content Generation
|
|
173
|
+
|
|
174
|
+
### generateHTML()
|
|
175
|
+
|
|
176
|
+
**Location:** `src/utils/generateHTML.js`
|
|
177
|
+
|
|
178
|
+
Generates HTML by calling the theme template function and optionally minifies the output.
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
const generateHTML = async (config, theme) => { ... }
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Parameters:**
|
|
185
|
+
- `config` (Object) - Configuration object
|
|
186
|
+
- `theme` (Function) - Theme template function
|
|
187
|
+
|
|
188
|
+
**Returns:** `Promise<String>` - Generated HTML string
|
|
189
|
+
|
|
190
|
+
**Example:**
|
|
191
|
+
```javascript
|
|
192
|
+
const html = await generateHTML(config, theme);
|
|
193
|
+
console.log(html); // '<!DOCTYPE html>...'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### generateOGImage()
|
|
197
|
+
|
|
198
|
+
**Location:** `src/utils/generateOGImage.js`
|
|
199
|
+
|
|
200
|
+
Generates an Open Graph preview image (1200x630 JPG) with avatar and text content.
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
const generateOGImage = async ({ name, content, avatar }) => { ... }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Parameters:**
|
|
207
|
+
- `name` (String) - Display name
|
|
208
|
+
- `content` (String) - Bio/description text
|
|
209
|
+
- `avatar` (Object, optional) - Avatar configuration with `path` property
|
|
210
|
+
|
|
211
|
+
**Returns:** `Promise<Buffer>` - JPG image buffer
|
|
212
|
+
|
|
213
|
+
**Example:**
|
|
214
|
+
```javascript
|
|
215
|
+
const ogImage = await generateOGImage({
|
|
216
|
+
name: 'John Doe',
|
|
217
|
+
content: 'Developer & Creator',
|
|
218
|
+
avatar: { path: './avatar.jpg' }
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Notes:**
|
|
223
|
+
- Supports SVG and raster avatar images (PNG, JPG, JPEG, WebP)
|
|
224
|
+
- Automatically resizes and positions avatar in a circular clip
|
|
225
|
+
- Uses dark gray background (#2d2d2d) with light text
|
|
226
|
+
- Quality set to 90% for JPG compression
|
|
227
|
+
|
|
228
|
+
### generateQR()
|
|
229
|
+
|
|
230
|
+
**Location:** `src/utils/generateQR.js`
|
|
231
|
+
|
|
232
|
+
Generates a QR code SVG for the given URL. Removes white background for transparency.
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
const generateQR = async (url) => { ... }
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Parameters:**
|
|
239
|
+
- `url` (String) - URL to encode in QR code
|
|
240
|
+
|
|
241
|
+
**Returns:** `Promise<String>` - QR code SVG string
|
|
242
|
+
|
|
243
|
+
**Example:**
|
|
244
|
+
```javascript
|
|
245
|
+
const qrCode = await generateQR('https://example.com');
|
|
246
|
+
console.log(qrCode); // '<svg>...</svg>'
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### processCSS()
|
|
250
|
+
|
|
251
|
+
**Location:** `src/utils/processCSS.js`
|
|
252
|
+
|
|
253
|
+
Processes theme CSS with PostCSS, autoprefixer, and optional minification.
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
const processCSS = async (config) => { ... }
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Parameters:**
|
|
260
|
+
- `config` (Object) - Configuration object containing `theme` and `minify` properties
|
|
261
|
+
|
|
262
|
+
**Returns:** `Promise<String|null>` - Processed CSS string, or null if CSS file not found
|
|
263
|
+
|
|
264
|
+
**Example:**
|
|
265
|
+
```javascript
|
|
266
|
+
const css = await processCSS({ theme: 'dark', minify: true });
|
|
267
|
+
console.log(css); // 'body{background:#1a1a1a;color:#fff}...'
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Notes:**
|
|
271
|
+
- Checks both NPX package path and local development path
|
|
272
|
+
- Uses autoprefixer to add vendor prefixes
|
|
273
|
+
- Minifies CSS if `config.minify` is true
|
|
274
|
+
- Returns null silently if CSS file doesn't exist
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## File Operations
|
|
279
|
+
|
|
280
|
+
### saveFiles()
|
|
281
|
+
|
|
282
|
+
**Location:** `src/utils/saveFiles.js`
|
|
283
|
+
|
|
284
|
+
Saves all generated files to the `dist/` directory.
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
const saveFiles = (html, css, avatar, ogImage, qrImage) => { ... }
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Parameters:**
|
|
291
|
+
- `html` (String) - Generated HTML content
|
|
292
|
+
- `css` (String, optional) - Processed CSS content
|
|
293
|
+
- `avatar` (Object, optional) - Avatar configuration with `path` property
|
|
294
|
+
- `ogImage` (Buffer) - Open Graph image buffer
|
|
295
|
+
- `qrImage` (String) - QR code SVG string
|
|
296
|
+
|
|
297
|
+
**Returns:** `undefined`
|
|
298
|
+
|
|
299
|
+
**Creates:**
|
|
300
|
+
- `dist/` directory if it doesn't exist
|
|
301
|
+
- `dist/index.html` - Main HTML page
|
|
302
|
+
- `dist/style.css` - Processed CSS (if provided)
|
|
303
|
+
- `dist/avatar.{ext}` - Avatar image with original extension (if configured and file exists)
|
|
304
|
+
- `dist/og-image.jpg` - Open Graph image
|
|
305
|
+
- `dist/qr.svg` - QR code
|
|
306
|
+
|
|
307
|
+
**Example:**
|
|
308
|
+
```javascript
|
|
309
|
+
saveFiles(
|
|
310
|
+
html, // Generated HTML
|
|
311
|
+
css, // Processed CSS
|
|
312
|
+
config.avatar, // Avatar config
|
|
313
|
+
ogImage, // OG image buffer
|
|
314
|
+
qrImage // QR code SVG
|
|
315
|
+
);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### readImageAsBase64()
|
|
319
|
+
|
|
320
|
+
**Location:** `src/utils/readImageAsBase64.js`
|
|
321
|
+
|
|
322
|
+
Reads an image file and returns it as base64-encoded string (for raster images) or raw SVG markup (for SVG files).
|
|
323
|
+
|
|
324
|
+
```javascript
|
|
325
|
+
const readImageAsBase64 = (imagePath) => { ... }
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**Parameters:**
|
|
329
|
+
- `imagePath` (String) - Path to image file
|
|
330
|
+
|
|
331
|
+
**Returns:** `Object` - Object with properties:
|
|
332
|
+
- `isSvg` (Boolean) - True if file is SVG, false otherwise
|
|
333
|
+
- `content` (String) - Base64 data URI (raster) or raw SVG markup (SVG)
|
|
334
|
+
|
|
335
|
+
**Throws:** `Error` - If file doesn't exist, isn't readable, or has unsupported format
|
|
336
|
+
|
|
337
|
+
**Example:**
|
|
338
|
+
```javascript
|
|
339
|
+
const avatarInfo = readImageAsBase64('./avatar.jpg');
|
|
340
|
+
console.log(avatarInfo.isSvg); // false
|
|
341
|
+
console.log(avatarInfo.content); // 'data:image/jpeg;base64,/9j/4AAQSkZJRg...'
|
|
342
|
+
|
|
343
|
+
const svgInfo = readImageAsBase64('./logo.svg');
|
|
344
|
+
console.log(svgInfo.isSvg); // true
|
|
345
|
+
console.log(svgInfo.content); // '<svg xmlns="http://www.w3.org/2000/svg">...'
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Supported formats:** PNG, JPG, JPEG, GIF, WebP, SVG
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Utilities
|
|
353
|
+
|
|
354
|
+
### escapeHTML()
|
|
355
|
+
|
|
356
|
+
**Location:** `src/utils/escapeHTML.js`
|
|
357
|
+
|
|
358
|
+
Escapes HTML special characters to prevent XSS attacks.
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
const escapeHTML = (str) => { ... }
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**Parameters:**
|
|
365
|
+
- `str` (String) - String to escape
|
|
366
|
+
|
|
367
|
+
**Returns:** `String` - Escaped string
|
|
368
|
+
|
|
369
|
+
**Example:**
|
|
370
|
+
```javascript
|
|
371
|
+
const safe = escapeHTML('<script>alert("xss")</script>');
|
|
372
|
+
console.log(safe); // '<script>alert("xss")</script>'
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Escaped characters:**
|
|
376
|
+
- `&` → `&`
|
|
377
|
+
- `<` → `<`
|
|
378
|
+
- `>` → `>`
|
|
379
|
+
- `"` → `"`
|
|
380
|
+
- `'` → `'`
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## CLI Utilities
|
|
385
|
+
|
|
386
|
+
### parseArgs()
|
|
387
|
+
|
|
388
|
+
**Location:** `src/utils/parseArgs.js`
|
|
389
|
+
|
|
390
|
+
Parses command-line arguments and returns the action to perform.
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
const parseArgs = () => { ... }
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
**Parameters:** None (uses `process.argv`)
|
|
397
|
+
|
|
398
|
+
**Returns:** `Object` - Object with properties:
|
|
399
|
+
- `action` (String) - One of `'help'`, `'init'`, `'validate-config'`, or `'build'`
|
|
400
|
+
|
|
401
|
+
**Example:**
|
|
402
|
+
```javascript
|
|
403
|
+
const args = parseArgs();
|
|
404
|
+
if (args.action === 'help') {
|
|
405
|
+
showHelp();
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Supported arguments:**
|
|
410
|
+
- `--help` or `-h`: Show help
|
|
411
|
+
- `--init` or `-i`: Create sample config
|
|
412
|
+
- `--validate-config` or `-v`: Validate configuration
|
|
413
|
+
- No arguments: Build page
|
|
414
|
+
|
|
415
|
+
### showHelp()
|
|
416
|
+
|
|
417
|
+
**Location:** `src/utils/showHelp.js`
|
|
418
|
+
|
|
419
|
+
Displays help information about OpenTwig usage.
|
|
420
|
+
|
|
421
|
+
```javascript
|
|
422
|
+
const showHelp = () => { ... }
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Parameters:** None
|
|
426
|
+
|
|
427
|
+
**Returns:** `undefined`
|
|
428
|
+
|
|
429
|
+
**Example:**
|
|
430
|
+
```javascript
|
|
431
|
+
showHelp();
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**Output:**
|
|
435
|
+
```
|
|
436
|
+
OpenTwig 🌿 - Open Source Link Page Generator
|
|
437
|
+
|
|
438
|
+
Usage:
|
|
439
|
+
npx opentwig Generate page from config.json
|
|
440
|
+
npx opentwig --init Create sample config.json
|
|
441
|
+
npx opentwig --help Show this help message
|
|
442
|
+
npx opentwig --validate-config Validate config.json
|
|
443
|
+
|
|
444
|
+
For more information, visit: https://github.com/tufantunc/opentwig
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### createSampleConfig()
|
|
448
|
+
|
|
449
|
+
**Location:** `src/utils/createSampleConfig.js`
|
|
450
|
+
|
|
451
|
+
Creates a sample `config.json` file in the current directory.
|
|
452
|
+
|
|
453
|
+
```javascript
|
|
454
|
+
const createSampleConfig = () => { ... }
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
**Parameters:** None
|
|
458
|
+
|
|
459
|
+
**Returns:** `undefined`
|
|
460
|
+
|
|
461
|
+
**Side effects:**
|
|
462
|
+
- Creates `config.json` file in current working directory
|
|
463
|
+
- Logs success message
|
|
464
|
+
- Exits process with code 0
|
|
465
|
+
|
|
466
|
+
**Example:**
|
|
467
|
+
```javascript
|
|
468
|
+
createSampleConfig();
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## Constants
|
|
474
|
+
|
|
475
|
+
**Location:** `src/constants.js`
|
|
476
|
+
|
|
477
|
+
Centralized constants used throughout the application.
|
|
478
|
+
|
|
479
|
+
```javascript
|
|
480
|
+
const CONSTANTS = {
|
|
481
|
+
CONFIG_FILE: 'config.json',
|
|
482
|
+
OUTPUT_DIR: 'dist',
|
|
483
|
+
OUTPUT_FILES: {
|
|
484
|
+
HTML: 'index.html',
|
|
485
|
+
CSS: 'style.css',
|
|
486
|
+
OG_IMAGE: 'og-image.jpg',
|
|
487
|
+
QR_IMAGE: 'qr.svg'
|
|
488
|
+
},
|
|
489
|
+
SUPPORTED_THEMES: ['default', 'dark', 'minimal', 'colorful'],
|
|
490
|
+
MESSAGES: {
|
|
491
|
+
ERROR_PREFIX: 'ERROR: ',
|
|
492
|
+
SUCCESS_PREFIX: '✅ ',
|
|
493
|
+
CONFIG_NOT_FOUND: 'Configuration file not found',
|
|
494
|
+
BUILD_SUCCESS: 'Page built successfully!',
|
|
495
|
+
BUILD_FAILED: 'Failed to build page'
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## Error Handling
|
|
503
|
+
|
|
504
|
+
Most functions follow these error handling patterns:
|
|
505
|
+
|
|
506
|
+
### Async Functions
|
|
507
|
+
```javascript
|
|
508
|
+
try {
|
|
509
|
+
const result = await someAsyncFunction();
|
|
510
|
+
return result;
|
|
511
|
+
} catch (error) {
|
|
512
|
+
throw new Error(`Context: ${error.message}`);
|
|
513
|
+
}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Sync Functions with Exit
|
|
517
|
+
```javascript
|
|
518
|
+
if (!fs.existsSync(path)) {
|
|
519
|
+
console.error(`${CONSTANTS.MESSAGES.ERROR_PREFIX}File not found: ${path}`);
|
|
520
|
+
process.exit(1);
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Errors that Should Be Handled
|
|
525
|
+
- Missing `config.json` file
|
|
526
|
+
- Invalid theme name
|
|
527
|
+
- Avatar file not found
|
|
528
|
+
- Invalid image format
|
|
529
|
+
- CSS file not found (handled silently, returns null)
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## Usage Examples
|
|
534
|
+
|
|
535
|
+
### Complete Build Workflow
|
|
536
|
+
```javascript
|
|
537
|
+
const loadConfig = require('./src/utils/loadConfig');
|
|
538
|
+
const buildPage = require('./src/utils/buildPage');
|
|
539
|
+
const saveFiles = require('./src/utils/saveFiles');
|
|
540
|
+
|
|
541
|
+
async function build() {
|
|
542
|
+
try {
|
|
543
|
+
const config = loadConfig();
|
|
544
|
+
const { html, css, ogImage, qrImage } = await buildPage(config);
|
|
545
|
+
saveFiles(html, css, config.avatar, ogImage, qrImage);
|
|
546
|
+
console.log('✅ Page built successfully!');
|
|
547
|
+
} catch (error) {
|
|
548
|
+
console.error(`❌ Error: ${error.message}`);
|
|
549
|
+
process.exit(1);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
build();
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Custom Build with Specific Components
|
|
557
|
+
```javascript
|
|
558
|
+
const generateHTML = require('./src/utils/generateHTML');
|
|
559
|
+
const generateOGImage = require('./src/utils/generateOGImage');
|
|
560
|
+
const generateQR = require('./src/utils/generateQR');
|
|
561
|
+
|
|
562
|
+
async function customBuild(config, theme) {
|
|
563
|
+
const html = await generateHTML(config, theme);
|
|
564
|
+
const ogImage = await generateOGImage({
|
|
565
|
+
name: config.name,
|
|
566
|
+
content: config.content,
|
|
567
|
+
avatar: config.avatar
|
|
568
|
+
});
|
|
569
|
+
const qrImage = await generateQR(config.url);
|
|
570
|
+
|
|
571
|
+
return { html, ogImage, qrImage };
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
---
|
|
576
|
+
|
|
577
|
+
## See Also
|
|
578
|
+
|
|
579
|
+
- [Theme Development Guide](THEME_DEVELOPMENT.md) - How to create custom themes
|
|
580
|
+
- [Contributing Guide](CONTRIBUTING.md) - Contribution guidelines
|
|
581
|
+
- [README](README.md) - Main project documentation
|
|
582
|
+
- [AGENTS.md](AGENTS.md) - Agent coding guidelines
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body block_size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
|
8
|
+
|
|
9
|
+
## Our Standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
|
12
|
+
|
|
13
|
+
* Using welcoming and inclusive language
|
|
14
|
+
* Being respectful of differing viewpoints and experiences
|
|
15
|
+
* Gracefully accepting constructive criticism
|
|
16
|
+
* Focusing on what is best for the community
|
|
17
|
+
* Showing empathy towards other community members
|
|
18
|
+
|
|
19
|
+
Examples of unacceptable behavior include:
|
|
20
|
+
|
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
22
|
+
advances of any kind
|
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
24
|
+
* Public or private harassment
|
|
25
|
+
* Publishing others' private information, such as a physical or email
|
|
26
|
+
address, without their explicit permission
|
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
28
|
+
professional setting in which this project is developed
|
|
29
|
+
|
|
30
|
+
## Enforcement Responsibilities
|
|
31
|
+
|
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
|
33
|
+
|
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
|
35
|
+
|
|
36
|
+
## Scope
|
|
37
|
+
|
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
|
39
|
+
|
|
40
|
+
## Enforcement
|
|
41
|
+
|
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement by contacting [the maintainer(s)] via e-mail at tufan@tufantunc.com. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
|
+
|
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
|
+
|
|
46
|
+
## Enforcement Guidelines
|
|
47
|
+
|
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
|
49
|
+
|
|
50
|
+
### 1. Correction
|
|
51
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
|
52
|
+
|
|
53
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
|
54
|
+
|
|
55
|
+
### 2. Warning
|
|
56
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
|
57
|
+
|
|
58
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
|
59
|
+
|
|
60
|
+
### 3. Temporary Ban
|
|
61
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
|
62
|
+
|
|
63
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
|
64
|
+
|
|
65
|
+
### 4. Permanent Ban
|
|
66
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
|
67
|
+
|
|
68
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
|
69
|
+
|
|
70
|
+
## Attribution
|
|
71
|
+
|
|
72
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
73
|
+
|
|
74
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
75
|
+
|
|
76
|
+
For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
|
77
|
+
|
|
78
|
+
[homepage]: https://www.contributor-covenant.org
|
|
79
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
80
|
+
|
|
81
|
+
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/deed.en_US).
|
|
82
|
+
|
|
83
|
+
## Contact Information
|
|
84
|
+
|
|
85
|
+
If you have any questions or concerns about this Code of Conduct, please contact the maintainers:
|
|
86
|
+
|
|
87
|
+
- Tufan Tunç - tufan@tufantunc.com
|
|
88
|
+
|
|
89
|
+
You can also reach out through:
|
|
90
|
+
- GitHub Issues
|
|
91
|
+
- GitHub Discussions
|