gitskins 0.1.0 → 0.2.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/README.md +37 -2
- package/bin/gitskins.js +19 -0
- package/package.json +1 -1
- package/src/commands/template.js +139 -0
- package/src/constants.js +6 -0
- package/src/render.js +32 -6
- package/src/template.js +168 -0
- package/src/util.js +7 -0
- package/templates/examples/founder-log.json +31 -0
- package/templates/examples/green-screen.json +34 -0
- package/templates/examples/hire-me-brief.json +30 -0
- package/templates/examples/maintainers-desk.json +31 -0
- package/templates/examples/quiet-pastel.json +28 -0
- package/templates/examples/study-hall.json +33 -0
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ instead. A first run with no cached copy and no successful render exits non-zero
|
|
|
77
77
|
| `gitskins init` | Scaffold config + Action and render once |
|
|
78
78
|
| `gitskins render` | Re-render the widgets in `.gitskins.json` |
|
|
79
79
|
| `gitskins portrait <image>` | Convert a local photo to an ASCII-art SVG |
|
|
80
|
+
| `gitskins template <action>` | Build, validate and preview a community README template |
|
|
80
81
|
| `gitskins help` | Show help |
|
|
81
82
|
|
|
82
83
|
### `init` options
|
|
@@ -140,6 +141,30 @@ npm install -g sharp @imgly/background-removal-node
|
|
|
140
141
|
`--remove-bg`. (Prefer the always-available hosted version? The web app renders
|
|
141
142
|
one from your GitHub avatar at `/api/section/portrait?username=<you>`.)
|
|
142
143
|
|
|
144
|
+
|
|
145
|
+
### `gitskins template`
|
|
146
|
+
|
|
147
|
+
Make a README template for the [GitSkins gallery](https://www.gitskins.com/readme-generator)
|
|
148
|
+
and get credited in every README built from it. A template is a JSON recipe
|
|
149
|
+
(sections, order, headings, layouts, theme), never code.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx gitskins template init # writes gitskins-template.json
|
|
153
|
+
npx gitskins template validate # checks it offline
|
|
154
|
+
npx gitskins template preview --user torvalds # renders README.preview.md
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
| Action | Description |
|
|
158
|
+
| --- | --- |
|
|
159
|
+
| `init [file]` | Write a starter template (`--example <name>` to start from a ready-made one, `--force` to overwrite) |
|
|
160
|
+
| `examples` | List the ready-made examples |
|
|
161
|
+
| `validate [file]` | Check the template against the GitSkins rules, offline |
|
|
162
|
+
| `preview [file] --user <login>` | Render it with a real GitHub profile; `--pro` for the Pro look, `--out <file>` to choose the output, `--author <login>` for the credit line |
|
|
163
|
+
|
|
164
|
+
When it looks right, submit it at
|
|
165
|
+
[gitskins.com/community-templates](https://www.gitskins.com/community-templates)
|
|
166
|
+
with **Import JSON**. A person reviews every template before it goes live.
|
|
167
|
+
|
|
143
168
|
## Configuration
|
|
144
169
|
|
|
145
170
|
`.gitskins.json`:
|
|
@@ -149,11 +174,21 @@ one from your GitHub avatar at `/api/section/portrait?username=<you>`.)
|
|
|
149
174
|
"username": "torvalds",
|
|
150
175
|
"theme": "satan",
|
|
151
176
|
"outputDir": ".gitskins",
|
|
152
|
-
"widgets": ["card", "languages", "streak", "stats"]
|
|
177
|
+
"widgets": ["card", "languages", "streak", "stats", "projects"],
|
|
178
|
+
"projects": ["torvalds/linux", "git/git", "torvalds/subsurface"]
|
|
153
179
|
}
|
|
154
180
|
```
|
|
155
181
|
|
|
156
|
-
Available widgets: `card`, `languages`, `streak`, `stats
|
|
182
|
+
Available widgets: `card`, `languages`, `streak`, `stats`, `portrait`,
|
|
183
|
+
`wordmark`, `projects`.
|
|
184
|
+
|
|
185
|
+
### Curated projects panel
|
|
186
|
+
|
|
187
|
+
Add the `projects` widget and a `projects` array of `owner/repo` slugs to hand-
|
|
188
|
+
pick and order the repos in your projects panel (instead of relying on GitHub
|
|
189
|
+
pins). GitSkins fills each card with live data — stars, languages (the animated
|
|
190
|
+
donut), topics, and last-push freshness. Edit the list any time; the README
|
|
191
|
+
never changes. Up to 6 repos.
|
|
157
192
|
|
|
158
193
|
## How it compares to hot-linking
|
|
159
194
|
|
package/bin/gitskins.js
CHANGED
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
*
|
|
8
8
|
* npx gitskins init scaffold config + GitHub Action, render once
|
|
9
9
|
* npx gitskins render refresh the committed widget files
|
|
10
|
+
* npx gitskins template build and preview a community README template
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
import { initCommand } from '../src/commands/init.js';
|
|
13
14
|
import { renderCommand } from '../src/commands/render.js';
|
|
14
15
|
import { portraitCommand } from '../src/commands/portrait.js';
|
|
16
|
+
import { templateCommand } from '../src/commands/template.js';
|
|
15
17
|
import { log } from '../src/util.js';
|
|
16
18
|
|
|
17
19
|
const HELP = `
|
|
@@ -24,6 +26,7 @@ ${log.bold('Commands')}
|
|
|
24
26
|
init Scaffold .gitskins.json + a GitHub Action, then render once
|
|
25
27
|
render Re-render the widgets defined in .gitskins.json
|
|
26
28
|
portrait Render a local photo to an ASCII-art SVG (subject on dark)
|
|
29
|
+
template Build, validate and preview a community README template
|
|
27
30
|
help Show this help
|
|
28
31
|
|
|
29
32
|
${log.bold('init options')}
|
|
@@ -49,10 +52,23 @@ ${log.bold('portrait options')}
|
|
|
49
52
|
--title <text> Terminal title line
|
|
50
53
|
Needs the optional deps: npm i -g sharp @imgly/background-removal-node
|
|
51
54
|
|
|
55
|
+
${log.bold('template actions')}
|
|
56
|
+
init [file] Write a starter template (default: gitskins-template.json)
|
|
57
|
+
--example <name> Start from a ready-made example instead
|
|
58
|
+
examples List the ready-made examples
|
|
59
|
+
validate [file] Check it against the GitSkins rules, offline
|
|
60
|
+
preview [file] Render it with a real profile to README.preview.md
|
|
61
|
+
--user <login> GitHub profile to render with (required)
|
|
62
|
+
--pro Render the Pro look (terminal cards, animated activity)
|
|
63
|
+
--out <file> Output path (default: README.preview.md)
|
|
64
|
+
--author <login> Whose credit the footer shows (default: the --user profile)
|
|
65
|
+
Submit a finished template at https://www.gitskins.com/community-templates
|
|
66
|
+
|
|
52
67
|
${log.bold('Examples')}
|
|
53
68
|
npx gitskins init --username torvalds --theme satan
|
|
54
69
|
npx gitskins render --snippet
|
|
55
70
|
npx gitskins portrait me.jpg --remove-bg --out .gitskins/portrait.svg
|
|
71
|
+
npx gitskins template init && npx gitskins template preview --user torvalds
|
|
56
72
|
`;
|
|
57
73
|
|
|
58
74
|
async function main() {
|
|
@@ -70,6 +86,9 @@ async function main() {
|
|
|
70
86
|
case 'portrait':
|
|
71
87
|
await portraitCommand(argv);
|
|
72
88
|
break;
|
|
89
|
+
case 'template':
|
|
90
|
+
await templateCommand(argv);
|
|
91
|
+
break;
|
|
73
92
|
case undefined:
|
|
74
93
|
case 'help':
|
|
75
94
|
case '--help':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitskins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Commit self-updating, themed GitHub profile widgets to your repo — no more hot-linking. Renders GitSkins cards to static SVG/PNG files via a GitHub Action.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `gitskins template <init|validate|preview>`: build a community README
|
|
3
|
+
* template locally, check it against the GitSkins rules, and render it with a
|
|
4
|
+
* real GitHub profile before submitting it at gitskins.com/community-templates.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { readFile, readdir, writeFile, mkdir } from 'node:fs/promises';
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import { resolve, dirname, relative, basename } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { log, parseFlags } from '../util.js';
|
|
12
|
+
import { DEFAULT_BASE_URL } from '../constants.js';
|
|
13
|
+
import { starterTemplate, templateIsFree, validateTemplate } from '../template.js';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_FILE = 'gitskins-template.json';
|
|
16
|
+
/** Ready-made templates to start from: `gitskins template init --example <name>`. */
|
|
17
|
+
const EXAMPLES_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '../../templates/examples');
|
|
18
|
+
const SUBMIT_URL = 'https://www.gitskins.com/community-templates';
|
|
19
|
+
const GITHUB_LOGIN = /^[a-z\d](?:[a-z\d-]{0,37}[a-z\d])?$/i;
|
|
20
|
+
|
|
21
|
+
const USAGE = `Usage:
|
|
22
|
+
gitskins template init [file] [--example <name>] [--force]
|
|
23
|
+
gitskins template examples
|
|
24
|
+
gitskins template validate [file]
|
|
25
|
+
gitskins template preview [file] --user <github-login> [--pro] [--out <file>]`;
|
|
26
|
+
|
|
27
|
+
const positional = (argv) => argv.filter((arg, index) => !arg.startsWith('--') && !(index > 0 && argv[index - 1].startsWith('--') && !argv[index - 1].includes('=')));
|
|
28
|
+
|
|
29
|
+
async function readTemplate(path) {
|
|
30
|
+
if (!existsSync(path)) throw new Error(`Template not found: ${relative(process.cwd(), path) || path}. Create one with \`gitskins template init\`.`);
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(await readFile(path, 'utf8'));
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new Error(`Could not parse ${relative(process.cwd(), path)}: ${err.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Validate, print problems, and return the cleaned template or null. */
|
|
39
|
+
function check(raw, file) {
|
|
40
|
+
const { template, errors, warnings } = validateTemplate(raw);
|
|
41
|
+
for (const warning of warnings) log.warn(warning);
|
|
42
|
+
if (errors.length) {
|
|
43
|
+
log.error(`${file} has ${errors.length} problem${errors.length === 1 ? '' : 's'}:`);
|
|
44
|
+
for (const error of errors) log.info(` - ${error}`);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return template;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The bundled example templates, by name. */
|
|
51
|
+
export async function listExamples() {
|
|
52
|
+
const files = (await readdir(EXAMPLES_DIR)).filter((file) => file.endsWith('.json')).sort();
|
|
53
|
+
return Promise.all(files.map(async (file) => ({
|
|
54
|
+
id: basename(file, '.json'),
|
|
55
|
+
template: JSON.parse(await readFile(resolve(EXAMPLES_DIR, file), 'utf8')),
|
|
56
|
+
})));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function examples() {
|
|
60
|
+
for (const { id, template } of await listExamples()) {
|
|
61
|
+
log.info(`${log.bold(id.padEnd(18))} ${templateIsFree(template.recipe) ? 'Free' : 'Pro '} ${template.description}`);
|
|
62
|
+
}
|
|
63
|
+
log.dim('\n Start from one: gitskins template init --example <name>');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function init(argv, flags) {
|
|
67
|
+
const file = positional(argv)[0] || DEFAULT_FILE;
|
|
68
|
+
const path = resolve(process.cwd(), file);
|
|
69
|
+
if (existsSync(path) && !flags.force) throw new Error(`${file} already exists. Use --force to overwrite it.`);
|
|
70
|
+
let template = starterTemplate();
|
|
71
|
+
if (flags.example) {
|
|
72
|
+
const found = (await listExamples()).find(({ id }) => id === flags.example);
|
|
73
|
+
if (!found) throw new Error(`No example called "${flags.example}". See \`gitskins template examples\`.`);
|
|
74
|
+
template = found.template;
|
|
75
|
+
}
|
|
76
|
+
await mkdir(dirname(path), { recursive: true });
|
|
77
|
+
await writeFile(path, JSON.stringify(template, null, 2) + '\n');
|
|
78
|
+
log.ok(`Wrote ${file}${flags.example ? ` from the "${flags.example}" example` : ''}`);
|
|
79
|
+
log.dim(' Edit it, then: gitskins template validate && gitskins template preview --user <your-login>');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function validate(argv) {
|
|
83
|
+
const file = positional(argv)[0] || DEFAULT_FILE;
|
|
84
|
+
const template = check(await readTemplate(resolve(process.cwd(), file)), file);
|
|
85
|
+
if (!template) process.exit(1);
|
|
86
|
+
log.ok(`${file} is a valid template: "${template.name}", ${template.recipe.sectionOrder.length} sections, ${templateIsFree(template.recipe) ? 'Free' : 'Pro'}.`);
|
|
87
|
+
log.dim(` Submit it at ${SUBMIT_URL} (Import JSON).`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function preview(argv, flags) {
|
|
91
|
+
const file = positional(argv)[0] || DEFAULT_FILE;
|
|
92
|
+
const user = typeof flags.user === 'string' ? flags.user.replace(/^@/, '') : '';
|
|
93
|
+
if (!GITHUB_LOGIN.test(user)) throw new Error('Pass the GitHub profile to render with --user <login>.');
|
|
94
|
+
const template = check(await readTemplate(resolve(process.cwd(), file)), file);
|
|
95
|
+
if (!template) process.exit(1);
|
|
96
|
+
|
|
97
|
+
const baseUrl = (typeof flags['base-url'] === 'string' ? flags['base-url'] : DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
98
|
+
log.step(`Rendering "${template.name}" for @${user}${flags.pro ? ' (Pro look)' : ''}…`);
|
|
99
|
+
const response = await fetch(`${baseUrl}/api/community-templates/preview`, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: { 'Content-Type': 'application/json', 'User-Agent': 'gitskins-cli' },
|
|
102
|
+
body: JSON.stringify({
|
|
103
|
+
username: user,
|
|
104
|
+
name: template.name,
|
|
105
|
+
recipe: template.recipe,
|
|
106
|
+
look: flags.pro ? 'pro' : 'free',
|
|
107
|
+
...(typeof flags.author === 'string' ? { author: flags.author.replace(/^@/, '') } : {}),
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
const data = await response.json().catch(() => ({}));
|
|
111
|
+
if (!response.ok) throw new Error(data.error || `Preview failed (HTTP ${response.status}).`);
|
|
112
|
+
|
|
113
|
+
const out = typeof flags.out === 'string' ? flags.out : 'README.preview.md';
|
|
114
|
+
const outPath = resolve(process.cwd(), out);
|
|
115
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
116
|
+
await writeFile(outPath, data.markdown.endsWith('\n') ? data.markdown : `${data.markdown}\n`);
|
|
117
|
+
log.ok(`Wrote ${relative(process.cwd(), outPath)} (${data.pricing === 'free' ? 'Free' : 'Pro'} template)`);
|
|
118
|
+
log.dim(' Open it in a Markdown preview, or paste it into a GitHub gist to see it as GitHub does.');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function templateCommand(argv) {
|
|
122
|
+
const [action, ...rest] = argv;
|
|
123
|
+
const flags = parseFlags(rest);
|
|
124
|
+
switch (action) {
|
|
125
|
+
case 'init':
|
|
126
|
+
return init(rest, flags);
|
|
127
|
+
case 'examples':
|
|
128
|
+
return examples();
|
|
129
|
+
case 'validate':
|
|
130
|
+
case 'check':
|
|
131
|
+
return validate(rest);
|
|
132
|
+
case 'preview':
|
|
133
|
+
return preview(rest, flags);
|
|
134
|
+
default:
|
|
135
|
+
log.error(action ? `Unknown template action: ${action}` : 'Missing template action.');
|
|
136
|
+
log.info(USAGE);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
}
|
package/src/constants.js
CHANGED
|
@@ -56,6 +56,12 @@ export const WIDGETS = {
|
|
|
56
56
|
alt: "%USER% as a rotating 3D ASCII wordmark",
|
|
57
57
|
defaultExt: 'svg',
|
|
58
58
|
},
|
|
59
|
+
projects: {
|
|
60
|
+
endpoint: 'section/projects',
|
|
61
|
+
label: 'Projects Panel',
|
|
62
|
+
alt: "%USER%'s featured projects",
|
|
63
|
+
defaultExt: 'svg',
|
|
64
|
+
},
|
|
59
65
|
};
|
|
60
66
|
|
|
61
67
|
/** Widgets included by default when a config is scaffolded. */
|
package/src/render.js
CHANGED
|
@@ -32,10 +32,27 @@ function retryConfig() {
|
|
|
32
32
|
|
|
33
33
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const MAX_WIDGET_BYTES = 10 * 1024 * 1024;
|
|
36
|
+
|
|
37
|
+
function validateBaseUrl(value) {
|
|
38
|
+
const url = new URL(value);
|
|
39
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
40
|
+
throw new Error('baseUrl must not contain credentials, query parameters, or a fragment');
|
|
41
|
+
}
|
|
42
|
+
const isLocalHttp = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
43
|
+
if (url.protocol !== 'https:' && !isLocalHttp) {
|
|
44
|
+
throw new Error('baseUrl must use HTTPS, except for localhost development');
|
|
45
|
+
}
|
|
46
|
+
return url;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function widgetUrl(baseUrl, endpoint, username, theme, extraParams = {}) {
|
|
50
|
+
const u = new URL(`/api/${endpoint}`, `${validateBaseUrl(baseUrl).origin}/`);
|
|
37
51
|
u.searchParams.set('username', username);
|
|
38
52
|
u.searchParams.set('theme', theme);
|
|
53
|
+
for (const [key, value] of Object.entries(extraParams)) {
|
|
54
|
+
if (value) u.searchParams.set(key, value);
|
|
55
|
+
}
|
|
39
56
|
return u.toString();
|
|
40
57
|
}
|
|
41
58
|
|
|
@@ -45,11 +62,13 @@ async function fetchOnce(url, timeoutMs) {
|
|
|
45
62
|
try {
|
|
46
63
|
const res = await fetch(url, {
|
|
47
64
|
signal: controller.signal,
|
|
65
|
+
redirect: 'error',
|
|
48
66
|
headers: { 'user-agent': 'gitskins-cli', accept: 'image/*' },
|
|
49
67
|
});
|
|
50
68
|
if (!res.ok) {
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
// Do not echo arbitrary upstream bodies into CLI errors. Widget
|
|
70
|
+
// endpoints can return HTML, stack traces, or reflected request data.
|
|
71
|
+
throw new Error(`HTTP ${res.status}`);
|
|
53
72
|
}
|
|
54
73
|
const contentType = res.headers.get('content-type') || '';
|
|
55
74
|
if (!contentType.startsWith('image/')) {
|
|
@@ -57,6 +76,7 @@ async function fetchOnce(url, timeoutMs) {
|
|
|
57
76
|
}
|
|
58
77
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
59
78
|
if (bytes.length === 0) throw new Error('empty response body');
|
|
79
|
+
if (bytes.length > MAX_WIDGET_BYTES) throw new Error('response body is too large');
|
|
60
80
|
return { bytes, contentType };
|
|
61
81
|
} finally {
|
|
62
82
|
clearTimeout(timer);
|
|
@@ -64,8 +84,8 @@ async function fetchOnce(url, timeoutMs) {
|
|
|
64
84
|
}
|
|
65
85
|
|
|
66
86
|
/** Fetch a single widget with retries. Returns { bytes, ext }. */
|
|
67
|
-
export async function fetchWidget({ baseUrl, endpoint, username, theme }) {
|
|
68
|
-
const url = widgetUrl(baseUrl, endpoint, username, theme);
|
|
87
|
+
export async function fetchWidget({ baseUrl, endpoint, username, theme, extraParams }) {
|
|
88
|
+
const url = widgetUrl(baseUrl, endpoint, username, theme, extraParams);
|
|
69
89
|
const { maxAttempts, retryDelayMs, timeoutMs } = retryConfig();
|
|
70
90
|
let lastErr;
|
|
71
91
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
@@ -100,12 +120,18 @@ export async function renderAll(config, cwd = process.cwd()) {
|
|
|
100
120
|
continue;
|
|
101
121
|
}
|
|
102
122
|
const alt = widget.alt.replace('%USER%', config.username);
|
|
123
|
+
// Curated projects: a `projects` array in the config picks/orders repos.
|
|
124
|
+
const extraParams =
|
|
125
|
+
id === 'projects' && Array.isArray(config.projects) && config.projects.length
|
|
126
|
+
? { repos: config.projects.join(',') }
|
|
127
|
+
: undefined;
|
|
103
128
|
try {
|
|
104
129
|
const { bytes, ext } = await fetchWidget({
|
|
105
130
|
baseUrl: config.baseUrl,
|
|
106
131
|
endpoint: widget.endpoint,
|
|
107
132
|
username: config.username,
|
|
108
133
|
theme: config.theme,
|
|
134
|
+
extraParams,
|
|
109
135
|
});
|
|
110
136
|
const absPath = resolve(outDir, `${id}.${ext}`);
|
|
111
137
|
await writeFile(absPath, bytes);
|
package/src/template.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Community README templates, for the `gitskins template` commands.
|
|
3
|
+
*
|
|
4
|
+
* A template file is JSON: a name, description and category, plus a `recipe`
|
|
5
|
+
* that tells GitSkins' renderer which sections to draw, in which order, under
|
|
6
|
+
* which headings, with which layouts and theme. It is never code or markup.
|
|
7
|
+
*
|
|
8
|
+
* These rules mirror the server's (src/lib/community-templates.ts) without any
|
|
9
|
+
* dependency, so `validate` works offline. A parity test in the GitSkins repo
|
|
10
|
+
* runs both validators on the same cases, so they cannot drift apart.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const TEMPLATE_SECTIONS = ['header', 'about', 'skills', 'stats', 'projects', 'highlights', 'heatmap', 'connect'];
|
|
14
|
+
export const TEMPLATE_CATEGORIES = ['recruiter', 'open-source', 'creative', 'technical'];
|
|
15
|
+
export const TEMPLATE_THEMES = [
|
|
16
|
+
'matrix', 'github-dark', 'neon', 'dracula',
|
|
17
|
+
'midnight', 'winter', 'aurora', 'ocean', 'forest',
|
|
18
|
+
'satan', 'halloween', 'summer', 'sunset', 'autumn', 'retro', 'christmas',
|
|
19
|
+
'minimal', 'pastel', 'zen', 'spring',
|
|
20
|
+
];
|
|
21
|
+
export const FREE_TEMPLATE_THEMES = ['satan', 'neon', 'zen', 'github-dark'];
|
|
22
|
+
export const TEMPLATE_VARIANTS = {
|
|
23
|
+
hero: ['profile', 'statement', 'terminal', 'portfolio'],
|
|
24
|
+
about: ['brief', 'manifest', 'story', 'learning', 'systems', 'community'],
|
|
25
|
+
skills: ['badges', 'stack', 'language-list', 'toolbox'],
|
|
26
|
+
stats: ['signal', 'metrics', 'activity', 'progress'],
|
|
27
|
+
projects: ['cards', 'impact', 'details', 'case-studies', 'repos'],
|
|
28
|
+
};
|
|
29
|
+
export const TEMPLATE_PRO_LOOK = {
|
|
30
|
+
cardStyle: ['aura', 'terminal'],
|
|
31
|
+
heatmap: ['aura', 'jet', 'erased', 'snake'],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const SAFE_TEXT = /^[\p{L}\p{N}\p{M}\p{Extended_Pictographic}️ .,:;'’"“”&+/?!()@–—·-]+$/u;
|
|
35
|
+
const RECIPE_KEYS = new Set(['version', 'theme', 'sectionOrder', 'headings', ...Object.keys(TEMPLATE_VARIANTS), ...Object.keys(TEMPLATE_PRO_LOOK)]);
|
|
36
|
+
const FILE_KEYS = new Set(['$schema', 'name', 'description', 'category', 'recipe']);
|
|
37
|
+
|
|
38
|
+
const isObject = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
const list = (values) => values.map((value) => `"${value}"`).join(', ');
|
|
40
|
+
|
|
41
|
+
/** Collapse whitespace, then check length, characters and links. Returns [value, error]. */
|
|
42
|
+
function safeText(label, value, min, max) {
|
|
43
|
+
if (typeof value !== 'string') return [null, `${label} must be text.`];
|
|
44
|
+
const clean = value.replace(/\s+/g, ' ').trim();
|
|
45
|
+
if (clean.length < min) return [null, `${label} needs at least ${min} characters.`];
|
|
46
|
+
if (clean.length > max) return [null, `${label} can be at most ${max} characters.`];
|
|
47
|
+
if (!SAFE_TEXT.test(clean)) return [null, `${label} can use letters, numbers, emoji and simple punctuation only.`];
|
|
48
|
+
if (/:\/\/|www\./i.test(clean)) return [null, `${label} cannot contain links.`];
|
|
49
|
+
return [clean, null];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Validate a recipe. Returns `{ recipe, errors, warnings }`; `recipe` is the
|
|
54
|
+
* cleaned value the server would store, or null when there are errors.
|
|
55
|
+
*/
|
|
56
|
+
export function validateRecipe(input) {
|
|
57
|
+
const errors = [];
|
|
58
|
+
const warnings = [];
|
|
59
|
+
if (!isObject(input)) return { recipe: null, errors: ['"recipe" must be an object.'], warnings };
|
|
60
|
+
|
|
61
|
+
for (const key of Object.keys(input)) {
|
|
62
|
+
if (!RECIPE_KEYS.has(key)) warnings.push(`recipe.${key} is not a recipe field and will be ignored.`);
|
|
63
|
+
}
|
|
64
|
+
if (input.version !== undefined && input.version !== 1) errors.push('recipe.version must be 1.');
|
|
65
|
+
if (!TEMPLATE_THEMES.includes(input.theme)) errors.push(`recipe.theme must be one of ${list(TEMPLATE_THEMES)}.`);
|
|
66
|
+
|
|
67
|
+
const order = input.sectionOrder;
|
|
68
|
+
if (!Array.isArray(order)) {
|
|
69
|
+
errors.push('recipe.sectionOrder must be a list of sections.');
|
|
70
|
+
} else {
|
|
71
|
+
const unknown = order.filter((section) => !TEMPLATE_SECTIONS.includes(section));
|
|
72
|
+
if (unknown.length) errors.push(`recipe.sectionOrder has unknown sections (${list(unknown)}). Use ${list(TEMPLATE_SECTIONS)}.`);
|
|
73
|
+
if (order.length < 3) errors.push('Pick at least 3 sections.');
|
|
74
|
+
if (order.length > TEMPLATE_SECTIONS.length) errors.push(`Pick at most ${TEMPLATE_SECTIONS.length} sections.`);
|
|
75
|
+
if (new Set(order).size !== order.length) errors.push('Each section can appear once.');
|
|
76
|
+
if (!order.includes('header')) errors.push('Include the header section.');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const headings = {};
|
|
80
|
+
if (input.headings !== undefined) {
|
|
81
|
+
if (!isObject(input.headings)) {
|
|
82
|
+
errors.push('recipe.headings must be an object of section: heading.');
|
|
83
|
+
} else {
|
|
84
|
+
for (const [section, value] of Object.entries(input.headings)) {
|
|
85
|
+
if (!TEMPLATE_SECTIONS.includes(section)) {
|
|
86
|
+
errors.push(`recipe.headings.${section} is not a section.`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const [clean, error] = safeText('A heading', value, 1, 48);
|
|
90
|
+
if (error) errors.push(`recipe.headings.${section}: ${error}`);
|
|
91
|
+
else headings[section] = clean;
|
|
92
|
+
if (Array.isArray(order) && !order.includes(section)) warnings.push(`recipe.headings.${section} is set but "${section}" is not in sectionOrder.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const [key, options] of Object.entries(TEMPLATE_VARIANTS)) {
|
|
98
|
+
if (!options.includes(input[key])) errors.push(`recipe.${key} must be one of ${list(options)}.`);
|
|
99
|
+
}
|
|
100
|
+
for (const [key, options] of Object.entries(TEMPLATE_PRO_LOOK)) {
|
|
101
|
+
if (input[key] !== undefined && !options.includes(input[key])) errors.push(`recipe.${key} must be one of ${list(options)}, or left out.`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (errors.length) return { recipe: null, errors, warnings };
|
|
105
|
+
const recipe = {
|
|
106
|
+
version: 1,
|
|
107
|
+
theme: input.theme,
|
|
108
|
+
sectionOrder: [...order],
|
|
109
|
+
headings,
|
|
110
|
+
hero: input.hero,
|
|
111
|
+
about: input.about,
|
|
112
|
+
skills: input.skills,
|
|
113
|
+
stats: input.stats,
|
|
114
|
+
projects: input.projects,
|
|
115
|
+
};
|
|
116
|
+
if (input.cardStyle !== undefined) recipe.cardStyle = input.cardStyle;
|
|
117
|
+
if (input.heatmap !== undefined) recipe.heatmap = input.heatmap;
|
|
118
|
+
return { recipe, errors, warnings };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Validate a whole template file: name, description, category and recipe. */
|
|
122
|
+
export function validateTemplate(input) {
|
|
123
|
+
if (!isObject(input)) return { template: null, errors: ['The template file must be a JSON object.'], warnings: [] };
|
|
124
|
+
const errors = [];
|
|
125
|
+
const warnings = [];
|
|
126
|
+
for (const key of Object.keys(input)) {
|
|
127
|
+
if (!FILE_KEYS.has(key)) warnings.push(`"${key}" is not a template field and will be ignored.`);
|
|
128
|
+
}
|
|
129
|
+
const [name, nameError] = safeText('The name', input.name, 3, 40);
|
|
130
|
+
if (nameError) errors.push(nameError);
|
|
131
|
+
const [description, descriptionError] = safeText('The description', input.description, 10, 160);
|
|
132
|
+
if (descriptionError) errors.push(descriptionError);
|
|
133
|
+
if (!TEMPLATE_CATEGORIES.includes(input.category)) errors.push(`"category" must be one of ${list(TEMPLATE_CATEGORIES)}.`);
|
|
134
|
+
const result = validateRecipe(input.recipe);
|
|
135
|
+
errors.push(...result.errors);
|
|
136
|
+
warnings.push(...result.warnings);
|
|
137
|
+
if (errors.length) return { template: null, errors, warnings };
|
|
138
|
+
return { template: { name, description, category: input.category, recipe: result.recipe }, errors, warnings };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Free when it uses a free theme and no terminal header, as the server prices it. */
|
|
142
|
+
export function templateIsFree(recipe) {
|
|
143
|
+
return FREE_TEMPLATE_THEMES.includes(recipe.theme) && recipe.hero !== 'terminal';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A valid starting point for `gitskins template init`. */
|
|
147
|
+
export function starterTemplate() {
|
|
148
|
+
return {
|
|
149
|
+
name: 'My Template',
|
|
150
|
+
description: 'A short line on who this template is for and what it shows.',
|
|
151
|
+
category: 'creative',
|
|
152
|
+
recipe: {
|
|
153
|
+
version: 1,
|
|
154
|
+
theme: 'neon',
|
|
155
|
+
sectionOrder: ['header', 'about', 'projects', 'skills', 'stats', 'connect'],
|
|
156
|
+
headings: {
|
|
157
|
+
header: 'Hello, I build things',
|
|
158
|
+
projects: 'Selected work',
|
|
159
|
+
connect: 'Say hello',
|
|
160
|
+
},
|
|
161
|
+
hero: 'statement',
|
|
162
|
+
about: 'story',
|
|
163
|
+
skills: 'badges',
|
|
164
|
+
stats: 'metrics',
|
|
165
|
+
projects: 'cards',
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
package/src/util.js
CHANGED
|
@@ -62,6 +62,10 @@ export async function loadConfig(cwd = process.cwd()) {
|
|
|
62
62
|
outputDir: (raw.outputDir || DEFAULT_OUTPUT_DIR).trim(),
|
|
63
63
|
baseUrl: (raw.baseUrl || DEFAULT_BASE_URL).trim().replace(/\/+$/, ''),
|
|
64
64
|
widgets: Array.isArray(raw.widgets) && raw.widgets.length ? raw.widgets : DEFAULT_WIDGETS,
|
|
65
|
+
// Curated `owner/repo` list for the `projects` widget (arifhaxn model).
|
|
66
|
+
projects: Array.isArray(raw.projects)
|
|
67
|
+
? raw.projects.filter((p) => typeof p === 'string' && p.trim()).map((p) => p.trim())
|
|
68
|
+
: [],
|
|
65
69
|
};
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -76,6 +80,9 @@ export async function writeConfig(config, cwd = process.cwd()) {
|
|
|
76
80
|
if (config.baseUrl && config.baseUrl !== DEFAULT_BASE_URL) {
|
|
77
81
|
body.baseUrl = config.baseUrl;
|
|
78
82
|
}
|
|
83
|
+
if (Array.isArray(config.projects) && config.projects.length) {
|
|
84
|
+
body.projects = config.projects;
|
|
85
|
+
}
|
|
79
86
|
await writeFile(path, JSON.stringify(body, null, 2) + '\n');
|
|
80
87
|
return path;
|
|
81
88
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Founder Log",
|
|
3
|
+
"category": "creative",
|
|
4
|
+
"description": "Build in public: the why, what you are shipping, traction and how to reach you.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "satan",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"projects",
|
|
12
|
+
"stats",
|
|
13
|
+
"skills",
|
|
14
|
+
"connect"
|
|
15
|
+
],
|
|
16
|
+
"headings": {
|
|
17
|
+
"header": "Building in the open",
|
|
18
|
+
"about": "The why",
|
|
19
|
+
"projects": "What I'm shipping",
|
|
20
|
+
"stats": "Traction",
|
|
21
|
+
"skills": "The stack",
|
|
22
|
+
"connect": "Talk to me"
|
|
23
|
+
},
|
|
24
|
+
"hero": "statement",
|
|
25
|
+
"about": "story",
|
|
26
|
+
"skills": "toolbox",
|
|
27
|
+
"stats": "metrics",
|
|
28
|
+
"projects": "case-studies",
|
|
29
|
+
"cardStyle": "terminal"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Green Screen",
|
|
3
|
+
"category": "technical",
|
|
4
|
+
"description": "A terminal session for systems and backend engineers, from whoami to ssh.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "matrix",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"projects",
|
|
12
|
+
"stats",
|
|
13
|
+
"skills",
|
|
14
|
+
"heatmap",
|
|
15
|
+
"connect"
|
|
16
|
+
],
|
|
17
|
+
"headings": {
|
|
18
|
+
"header": "whoami",
|
|
19
|
+
"about": "cat about.txt",
|
|
20
|
+
"projects": "ls projects",
|
|
21
|
+
"stats": "top",
|
|
22
|
+
"skills": "which tools",
|
|
23
|
+
"heatmap": "git log --graph",
|
|
24
|
+
"connect": "ssh me"
|
|
25
|
+
},
|
|
26
|
+
"hero": "terminal",
|
|
27
|
+
"about": "systems",
|
|
28
|
+
"skills": "stack",
|
|
29
|
+
"stats": "metrics",
|
|
30
|
+
"projects": "details",
|
|
31
|
+
"cardStyle": "terminal",
|
|
32
|
+
"heatmap": "jet"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Hire Me Brief",
|
|
3
|
+
"category": "recruiter",
|
|
4
|
+
"description": "A one-screen profile for job hunting: what you do, the numbers, then proof of work.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "github-dark",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"stats",
|
|
12
|
+
"projects",
|
|
13
|
+
"skills",
|
|
14
|
+
"connect"
|
|
15
|
+
],
|
|
16
|
+
"headings": {
|
|
17
|
+
"header": "At a glance",
|
|
18
|
+
"about": "What I do",
|
|
19
|
+
"stats": "By the numbers",
|
|
20
|
+
"projects": "Proof of work",
|
|
21
|
+
"skills": "Toolkit",
|
|
22
|
+
"connect": "Get in touch"
|
|
23
|
+
},
|
|
24
|
+
"hero": "profile",
|
|
25
|
+
"about": "brief",
|
|
26
|
+
"skills": "badges",
|
|
27
|
+
"stats": "metrics",
|
|
28
|
+
"projects": "impact"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Maintainer's Desk",
|
|
3
|
+
"category": "open-source",
|
|
4
|
+
"description": "For open-source maintainers: the repositories you look after, your contribution log and how to help.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "neon",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"projects",
|
|
12
|
+
"heatmap",
|
|
13
|
+
"skills",
|
|
14
|
+
"connect"
|
|
15
|
+
],
|
|
16
|
+
"headings": {
|
|
17
|
+
"header": "Maintainer on duty",
|
|
18
|
+
"about": "Why I maintain",
|
|
19
|
+
"projects": "Repositories I look after",
|
|
20
|
+
"heatmap": "Contribution log",
|
|
21
|
+
"skills": "Tools of the trade",
|
|
22
|
+
"connect": "Come contribute"
|
|
23
|
+
},
|
|
24
|
+
"hero": "profile",
|
|
25
|
+
"about": "community",
|
|
26
|
+
"skills": "toolbox",
|
|
27
|
+
"stats": "activity",
|
|
28
|
+
"projects": "repos",
|
|
29
|
+
"heatmap": "erased"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Quiet Pastel",
|
|
3
|
+
"category": "creative",
|
|
4
|
+
"description": "Soft, light and short: a hello, a few things you made and where to find you.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "pastel",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"projects",
|
|
12
|
+
"skills",
|
|
13
|
+
"connect"
|
|
14
|
+
],
|
|
15
|
+
"headings": {
|
|
16
|
+
"header": "Hello there",
|
|
17
|
+
"about": "Lately",
|
|
18
|
+
"projects": "Things I've made",
|
|
19
|
+
"skills": "What I use",
|
|
20
|
+
"connect": "Find me"
|
|
21
|
+
},
|
|
22
|
+
"hero": "portfolio",
|
|
23
|
+
"about": "brief",
|
|
24
|
+
"skills": "language-list",
|
|
25
|
+
"stats": "signal",
|
|
26
|
+
"projects": "cards"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Study Hall",
|
|
3
|
+
"category": "technical",
|
|
4
|
+
"description": "For students and career changers: what you are learning, projects in progress and your streak.",
|
|
5
|
+
"recipe": {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"theme": "zen",
|
|
8
|
+
"sectionOrder": [
|
|
9
|
+
"header",
|
|
10
|
+
"about",
|
|
11
|
+
"skills",
|
|
12
|
+
"projects",
|
|
13
|
+
"stats",
|
|
14
|
+
"heatmap",
|
|
15
|
+
"connect"
|
|
16
|
+
],
|
|
17
|
+
"headings": {
|
|
18
|
+
"header": "Learning out loud",
|
|
19
|
+
"about": "Currently studying",
|
|
20
|
+
"skills": "Languages I'm practicing",
|
|
21
|
+
"projects": "Projects in progress",
|
|
22
|
+
"stats": "Progress so far",
|
|
23
|
+
"heatmap": "Study streak",
|
|
24
|
+
"connect": "Say hi"
|
|
25
|
+
},
|
|
26
|
+
"hero": "profile",
|
|
27
|
+
"about": "learning",
|
|
28
|
+
"skills": "language-list",
|
|
29
|
+
"stats": "progress",
|
|
30
|
+
"projects": "details",
|
|
31
|
+
"heatmap": "snake"
|
|
32
|
+
}
|
|
33
|
+
}
|