ghostcn 1.4.1 → 1.6.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/dist/commands/create.js +16 -9
- package/dist/commands/diff.js +47 -5
- package/dist/commands/init.js +22 -10
- package/dist/commands/list.js +22 -4
- package/dist/registry/components/accordion.json +66 -0
- package/dist/registry/components/alert.json +1 -1
- package/dist/registry/components/announcement-bar.json +79 -0
- package/dist/registry/components/archive-header.json +2 -2
- package/dist/registry/components/author-card.json +2 -2
- package/dist/registry/components/author-list.json +2 -2
- package/dist/registry/components/avatar.json +62 -0
- package/dist/registry/components/badge.json +1 -1
- package/dist/registry/components/breadcrumbs.json +59 -0
- package/dist/registry/components/button.json +1 -1
- package/dist/registry/components/card.json +1 -1
- package/dist/registry/components/featured-posts.json +2 -2
- package/dist/registry/components/input.json +8 -2
- package/dist/registry/components/member-cta.json +1 -1
- package/dist/registry/components/newsletter-form.json +12 -3
- package/dist/registry/components/pagination.json +2 -2
- package/dist/registry/components/post-card.json +2 -2
- package/dist/registry/components/post-grid.json +2 -2
- package/dist/registry/components/post-header.json +2 -2
- package/dist/registry/components/post-navigation.json +1 -1
- package/dist/registry/components/pricing-table.json +24 -4
- package/dist/registry/components/reading-progress.json +73 -0
- package/dist/registry/components/related-posts.json +7 -1
- package/dist/registry/components/share-buttons.json +76 -0
- package/dist/registry/components/site-footer.json +2 -2
- package/dist/registry/components/site-header.json +1 -1
- package/dist/registry/components/table-of-contents.json +13 -3
- package/dist/registry/components/tag-grid.json +2 -2
- package/dist/registry/components/tag-list.json +1 -1
- package/dist/registry/components/theme-toggle.json +65 -0
- package/dist/registry/components/visibility-badge.json +71 -0
- package/dist/registry/index.json +89 -4
- package/dist/templates/playground/index.html +2 -2
- package/dist/templates/playground/playground.css +8 -1
- package/dist/templates/playground/playground.js +39 -5
- package/dist/templates/playground/preview.css +1 -0
- package/dist/templates/theme-tools.mjs +62 -24
- package/dist/utils/component-diff.d.ts +1 -1
- package/dist/utils/component-diff.js +46 -17
- package/dist/utils/component-files.js +3 -2
- package/dist/utils/component-history.js +1 -1
- package/dist/utils/design-defaults.json +17 -0
- package/dist/utils/playground-server.js +34 -12
- package/dist/utils/preview-renderer.d.ts +5 -0
- package/dist/utils/preview-renderer.js +30 -8
- package/dist/utils/registry.js +15 -5
- package/dist/utils/theme-files.js +14 -7
- package/dist/utils/theme-project.js +6 -4
- package/dist/utils/theme-scaffold.js +27 -14
- package/dist/utils/theme.d.ts +3 -3
- package/dist/utils/theme.js +108 -49
- package/package.json +1 -1
|
@@ -40,9 +40,10 @@ function componentFiles(themeRoot, config, manifest) {
|
|
|
40
40
|
throw new Error('Component target must be a file, not a directory.');
|
|
41
41
|
if (file.type === 'style' || file.type === 'js')
|
|
42
42
|
(0, theme_files_1.toGhostAssetPath)(relative);
|
|
43
|
-
|
|
43
|
+
const key = process.platform === 'win32' ? target.toLowerCase() : target;
|
|
44
|
+
if (targets.has(key))
|
|
44
45
|
throw new Error('Duplicate component target.');
|
|
45
|
-
targets.add(
|
|
46
|
+
targets.add(key);
|
|
46
47
|
return { relative: path_1.default.relative(path_1.default.resolve(themeRoot), target).replace(/\\/g, '/'), target, content: file.type === 'style' ? (0, styles_1.componentCss)(file.content, config.style) : file.type === 'partial' ? aliasedPartial(file.content, config) : file.content };
|
|
47
48
|
});
|
|
48
49
|
}
|
|
@@ -18,7 +18,7 @@ function readHistory(themeRoot) {
|
|
|
18
18
|
const target = (0, component_files_1.safeThemePath)(themeRoot, '.ghostcn/installed.json');
|
|
19
19
|
if (!fs_1.default.existsSync(target))
|
|
20
20
|
return { schema: 1, components: {} };
|
|
21
|
-
const state = JSON.parse(fs_1.default.readFileSync(target, 'utf8'));
|
|
21
|
+
const state = JSON.parse(fs_1.default.readFileSync(target, 'utf8').replace(/^\uFEFF/, ''));
|
|
22
22
|
if (state.schema !== 1 || !state.components || Array.isArray(state.components) || typeof state.components !== 'object')
|
|
23
23
|
throw new Error('Invalid .ghostcn/installed.json; preserve it and repair before continuing.');
|
|
24
24
|
for (const [name, entry] of Object.entries(state.components)) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"section-space": "clamp(24px, 4vw, 48px)",
|
|
3
|
+
"section-gap": "20px",
|
|
4
|
+
"grid-gap": "16px",
|
|
5
|
+
"panel-padding": "clamp(16px, 3vw, 24px)",
|
|
6
|
+
"panel-radius": "min(var(--radius, 8px), 24px)",
|
|
7
|
+
"title-display": "clamp(32px, 5vw, 56px)",
|
|
8
|
+
"title-section": "clamp(24px, 3vw, 32px)",
|
|
9
|
+
"title-card": "20px",
|
|
10
|
+
"text-body": "16px",
|
|
11
|
+
"text-small": "14px",
|
|
12
|
+
"text-meta": "13px",
|
|
13
|
+
"control-height": "40px",
|
|
14
|
+
"control-padding": "8px 14px",
|
|
15
|
+
"control-gap": "8px",
|
|
16
|
+
"control-radius": "var(--radius, 8px)"
|
|
17
|
+
}
|
|
@@ -39,19 +39,22 @@ function collectThemeFiles(themeRoot, directory, extension) {
|
|
|
39
39
|
}
|
|
40
40
|
function themeStyles(themeRoot, config) {
|
|
41
41
|
const layout = (0, theme_files_1.safeThemePath)(themeRoot, 'default.hbs');
|
|
42
|
-
const
|
|
42
|
+
const raw = fs_1.default.existsSync(layout) ? fs_1.default.readFileSync(layout, 'utf8') : '';
|
|
43
|
+
const source = raw.replace(/\{\{!--[\s\S]*?--\}\}/g, '').replace(/\{\{![\s\S]*?\}\}/g, '');
|
|
43
44
|
const links = [];
|
|
44
|
-
for (const link of source.match(/<link\b[^>]*>/
|
|
45
|
-
if (
|
|
45
|
+
for (const link of source.match(/<link\b[^>]*>/gi) || []) {
|
|
46
|
+
if (!/\brel\s*=\s*["']stylesheet["']/i.test(link))
|
|
46
47
|
continue;
|
|
47
48
|
const asset = link.match(/\{\{asset\s+["']([^"']+\.css)["']\s*\}\}/)?.[1] || link.match(/href=["']\/assets\/([^"']+\.css)["']/)?.[1];
|
|
48
49
|
if (asset && !links.includes(asset)) {
|
|
49
|
-
(0, theme_files_1.safeThemePath)(themeRoot, `assets/${asset}`);
|
|
50
|
-
|
|
50
|
+
const target = (0, theme_files_1.safeThemePath)(themeRoot, `assets/${asset}`);
|
|
51
|
+
if (fs_1.default.existsSync(target) && fs_1.default.statSync(target).isFile())
|
|
52
|
+
links.push(asset);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
if (!links.length) {
|
|
54
|
-
const
|
|
56
|
+
const styleFiles = config.aliases?.styles ? collectThemeFiles(themeRoot, config.aliases.styles, '.css').map(file => path_1.default.relative(themeRoot, file).replace(/\\/g, '/')) : [];
|
|
57
|
+
const fallback = [config.cssFile, ...styleFiles, 'assets/built/screen.css'].filter(Boolean);
|
|
55
58
|
for (const relative of fallback)
|
|
56
59
|
if (fs_1.default.existsSync((0, theme_files_1.safeThemePath)(themeRoot, relative)))
|
|
57
60
|
links.push(relative.replace(/^assets\//, ''));
|
|
@@ -60,7 +63,10 @@ function themeStyles(themeRoot, config) {
|
|
|
60
63
|
}
|
|
61
64
|
async function startPlayground(options) {
|
|
62
65
|
const themeRoot = fs_1.default.realpathSync(options.themeRoot);
|
|
63
|
-
const
|
|
66
|
+
const configPath = (0, theme_files_1.safeThemePath)(themeRoot, 'components.json');
|
|
67
|
+
if (!fs_1.default.existsSync(configPath))
|
|
68
|
+
throw new Error('components.json was not found. Run "npx ghostcn init" from your Ghost theme root first.');
|
|
69
|
+
const config = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
|
|
64
70
|
if (!['css', 'tailwind'].includes(config.style) || !config.aliases)
|
|
65
71
|
throw new Error('Invalid components.json. Run ghostcn doctor.');
|
|
66
72
|
(0, component_files_1.componentPartialName)(config, 'button');
|
|
@@ -159,17 +165,25 @@ async function startPlayground(options) {
|
|
|
159
165
|
partials[path_1.default.relative(path_1.default.join(themeRoot, 'partials'), file).replace(/\\/g, '/').replace(/\.hbs$/, '')] = fs_1.default.readFileSync(file, 'utf8');
|
|
160
166
|
const parameters = { ...(preview_renderer_1.demoParameters[name] || {}) };
|
|
161
167
|
const keys = new Set([...Object.keys(manifest.parameters || {}), ...Object.keys(manifest.styleSlots || {})]);
|
|
168
|
+
const boolKeys = new Set(['disabled', 'required', 'invalid', 'urgent', 'decorative', 'open', 'hideDismiss', 'showPublic']);
|
|
162
169
|
for (const key of keys)
|
|
163
170
|
if (url.searchParams.has(key))
|
|
164
|
-
parameters[key] =
|
|
165
|
-
const
|
|
171
|
+
parameters[key] = boolKeys.has(key) ? url.searchParams.get(key) === 'true' : url.searchParams.get(key);
|
|
172
|
+
const allowedStates = [...preview_renderer_1.previewStates, 'free-only'];
|
|
173
|
+
const state = allowedStates.includes(url.searchParams.get('state') || '') ? url.searchParams.get('state') : 'visitor';
|
|
174
|
+
const access = url.searchParams.get('access') === 'false' ? false : true;
|
|
166
175
|
const scheme = url.searchParams.get('scheme');
|
|
167
176
|
const nameInTheme = name === 'pagination' ? 'pagination' : (0, component_files_1.componentPartialName)(config, name);
|
|
168
|
-
const
|
|
177
|
+
const baseContext = ['pricing-table', 'newsletter-form'].includes(name)
|
|
178
|
+
? {}
|
|
179
|
+
: name === 'author-card'
|
|
180
|
+
? preview_renderer_1.demoAuthor
|
|
181
|
+
: { ...preview_renderer_1.previewDemoContext, access };
|
|
182
|
+
const context = { ...baseContext, ...parameters };
|
|
169
183
|
let source = (0, preview_renderer_1.previewInvocation)(nameInTheme, parameters);
|
|
170
184
|
if (name === 'pagination')
|
|
171
185
|
source = `{{> "pagination" pagination ${Object.keys(parameters).map(key => `${key}=${key}`).join(' ')}}}`;
|
|
172
|
-
let html = (0, preview_renderer_1.renderPreviewTemplate)(partials, source, { state, context });
|
|
186
|
+
let html = (0, preview_renderer_1.renderPreviewTemplate)(partials, source, { state, context, access });
|
|
173
187
|
if (name === 'table-of-contents')
|
|
174
188
|
html += '<article class="ghcn-article-content"><h2>Start with your story</h2><p>Demo article.</p><h3>Make room for readers</h3><p>A subsection.</p><h2>Keep it yours</h2><p>Your theme, your style.</p></article>';
|
|
175
189
|
const scripts = manifest.files.filter(file => file.type === 'js').map(file => (0, component_files_1.componentFiles)(themeRoot, config, manifest).find(target => target.relative.endsWith(`/${file.name}`))).filter(Boolean);
|
|
@@ -185,5 +199,13 @@ async function startPlayground(options) {
|
|
|
185
199
|
}
|
|
186
200
|
});
|
|
187
201
|
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(port, '127.0.0.1', () => { server.removeListener('error', reject); actualPort = server.address().port; resolve(); }); });
|
|
188
|
-
return {
|
|
202
|
+
return {
|
|
203
|
+
server,
|
|
204
|
+
url: `http://127.0.0.1:${actualPort}`,
|
|
205
|
+
close: () => new Promise((resolve, reject) => {
|
|
206
|
+
server.close(error => error ? reject(error) : resolve());
|
|
207
|
+
if (typeof server.closeAllConnections === 'function')
|
|
208
|
+
server.closeAllConnections();
|
|
209
|
+
})
|
|
210
|
+
};
|
|
189
211
|
}
|
|
@@ -37,6 +37,7 @@ export declare const demoPost: {
|
|
|
37
37
|
visibility: string;
|
|
38
38
|
}[];
|
|
39
39
|
access: boolean;
|
|
40
|
+
visibility: string;
|
|
40
41
|
};
|
|
41
42
|
export declare const demoPosts: {
|
|
42
43
|
title: string;
|
|
@@ -67,6 +68,7 @@ export declare const demoPosts: {
|
|
|
67
68
|
visibility: string;
|
|
68
69
|
}[];
|
|
69
70
|
access: boolean;
|
|
71
|
+
visibility: string;
|
|
70
72
|
}[];
|
|
71
73
|
export declare const previewStates: string[];
|
|
72
74
|
export declare const previewDemoContext: {
|
|
@@ -99,6 +101,7 @@ export declare const previewDemoContext: {
|
|
|
99
101
|
visibility: string;
|
|
100
102
|
}[];
|
|
101
103
|
access: boolean;
|
|
104
|
+
visibility: string;
|
|
102
105
|
}[];
|
|
103
106
|
pagination: {
|
|
104
107
|
page: number;
|
|
@@ -134,10 +137,12 @@ export declare const previewDemoContext: {
|
|
|
134
137
|
visibility: string;
|
|
135
138
|
}[];
|
|
136
139
|
access: boolean;
|
|
140
|
+
visibility: string;
|
|
137
141
|
};
|
|
138
142
|
export declare const demoParameters: Record<string, Record<string, string>>;
|
|
139
143
|
export declare function renderPreviewTemplate(partials: Record<string, string>, template: string, options?: {
|
|
140
144
|
state?: string;
|
|
141
145
|
context?: Record<string, unknown>;
|
|
146
|
+
access?: boolean;
|
|
142
147
|
}): string;
|
|
143
148
|
export declare function previewInvocation(partialName: string, parameters: Record<string, unknown>): string;
|
|
@@ -9,11 +9,19 @@ exports.previewInvocation = previewInvocation;
|
|
|
9
9
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
10
10
|
// Synthetic data only. This is shared by static docs and the local playground,
|
|
11
11
|
// never used by production themes, never connected to Ghost/Stripe/email APIs.
|
|
12
|
-
|
|
12
|
+
// Text-free artwork survives the lead, thumbnail and article crops.
|
|
13
|
+
const editorialImage = (background, ink, motif) => 'data:image/svg+xml,' + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="675" viewBox="0 0 1200 675"><rect width="1200" height="675" fill="${background}"/><g fill="${ink}">${motif}</g></svg>`);
|
|
14
|
+
exports.demoImage = editorialImage('#ded4c3', '#38362f', '<path d="M315 475V220L560 120l205 100v255L560 575z"/><path d="M560 170v348l160-71V250z" fill="#b68f74"/><path d="M359 249l157-66v324l-157-55z" fill="#f4ece1"/><path d="M817 232v245l76-34V272z" fill="#9a8c74"/>');
|
|
15
|
+
const secondImage = editorialImage('#cbd1c5', '#374738', '<circle cx="600" cy="337" r="210"/><path d="M380 336h440v35H380z" fill="#f0ede1"/><circle cx="600" cy="337" r="116" fill="#aab4a1"/><path d="M573 121h54v431h-54z" fill="#677c65" opacity=".8"/>');
|
|
16
|
+
const thirdImage = editorialImage('#dbc7bb', '#6a483e', '<path d="M334 454l140-235 127 208 126-208 140 235z"/><path d="M312 485h576v40H312z" fill="#9c6956"/><circle cx="603" cy="166" r="44" fill="#f5e4cd"/>');
|
|
13
17
|
exports.demoAuthor = { name: 'Alex Reader', url: '/author/alex/', bio: 'Writing about independent publishing, thoughtful design, and building a home for your readers.', location: 'Everywhere', count: { posts: 12 } };
|
|
14
18
|
const tags = [{ name: 'Publishing', description: 'Stories about independent publishing.', url: '/tag/publishing/', visibility: 'public' }, { name: 'Design', description: 'The details that make it yours.', url: '/tag/design/', visibility: 'public' }];
|
|
15
|
-
exports.demoPost = { title: 'A home for independent ideas', url: '/a-home-for-independent-ideas/', excerpt: 'Good stories deserve a place of their own. Build a publication around your ideas, your community, and your voice.', custom_excerpt: 'Good stories deserve a place of their own.', feature_image: exports.demoImage, feature_image_alt: '
|
|
16
|
-
exports.demoPosts = [
|
|
19
|
+
exports.demoPost = { title: 'A home for independent ideas', url: '/a-home-for-independent-ideas/', excerpt: 'Good stories deserve a place of their own. Build a publication around your ideas, your community, and your voice.', custom_excerpt: 'Good stories deserve a place of their own.', feature_image: exports.demoImage, feature_image_alt: 'An abstract illustration of folded paper', primary_author: exports.demoAuthor, primary_tag: tags[0], tags, access: true, visibility: 'members' };
|
|
20
|
+
exports.demoPosts = [
|
|
21
|
+
exports.demoPost,
|
|
22
|
+
{ ...exports.demoPost, title: 'Make room for your readers', url: '/make-room-for-your-readers/', feature_image: secondImage, feature_image_alt: 'An abstract illustration of intersecting circles', excerpt: 'A thoughtful reading experience starts with space for the story and a clear path to what comes next.' },
|
|
23
|
+
{ ...exports.demoPost, title: 'The details that make it yours', url: '/the-details-that-make-it-yours/', feature_image: thirdImage, feature_image_alt: 'An abstract illustration of two hills and the sun', excerpt: 'The small choices that make your publication feel unmistakably yours.' },
|
|
24
|
+
];
|
|
17
25
|
const tiers = [{ id: 'demo-free', type: 'free', name: 'Reader', description: 'Follow the publication.', benefits: ['New posts in your inbox'] }, { id: 'demo-paid', type: 'paid', name: 'Supporter', description: 'Support independent writing.', currency: 'USD', monthly_price: 500, yearly_price: 5000, benefits: ['Everything in Reader', 'Members-only stories'] }];
|
|
18
26
|
exports.previewStates = ['visitor', 'free', 'paid', 'disabled', 'invite', 'restricted'];
|
|
19
27
|
exports.previewDemoContext = { ...exports.demoPost, posts: exports.demoPosts, pagination: { page: 2, pages: 4, prev: 1, next: 3 } };
|
|
@@ -24,10 +32,19 @@ exports.demoParameters = {
|
|
|
24
32
|
input: { label: 'Email address', type: 'email', name: 'email', placeholder: 'you@example.com', hint: 'We will keep your email private.', hintId: 'demo-email-hint' },
|
|
25
33
|
alert: { heading: 'You are all set', description: 'Your theme is ready to customize.' },
|
|
26
34
|
'post-grid': { heading: 'Latest stories' }, 'author-list': { heading: 'Meet the authors' }, 'tag-grid': { heading: 'Explore topics' },
|
|
27
|
-
'archive-header': { heading: 'Publishing', description: 'Ideas for a publication of your own.', eyebrow: 'Topic', archiveImage: exports.demoImage, imageAlt: 'Demo archive image' }
|
|
35
|
+
'archive-header': { heading: 'Publishing', description: 'Ideas for a publication of your own.', eyebrow: 'Topic', archiveImage: exports.demoImage, imageAlt: 'Demo archive image' },
|
|
36
|
+
avatar: { name: 'Alex Reader' },
|
|
37
|
+
accordion: { heading: 'How does membership work?', body: 'Choose a free or paid tier in Ghost Portal to unlock member-only essays and newsletters.' },
|
|
38
|
+
'theme-toggle': { ariaLabel: 'Color theme' },
|
|
39
|
+
'announcement-bar': { text: 'Issue 14 is live — read our spring editorial report.', linkText: 'Read issue', href: '/archive/' },
|
|
40
|
+
'reading-progress': { initialValue: '42' },
|
|
41
|
+
'share-buttons': { heading: 'Share' },
|
|
42
|
+
breadcrumbs: { homeLabel: 'Home' },
|
|
43
|
+
'visibility-badge': { membersLabel: 'Members only' }
|
|
28
44
|
};
|
|
29
45
|
function renderPreviewTemplate(partials, template, options = {}) {
|
|
30
46
|
const state = options.state || 'visitor';
|
|
47
|
+
const postContext = options.access === undefined ? exports.demoPost : { ...exports.demoPost, access: options.access };
|
|
31
48
|
const hbs = handlebars_1.default.create();
|
|
32
49
|
hbs.registerPartial(partials);
|
|
33
50
|
hbs.registerHelper('foreach', (items, opts) => {
|
|
@@ -41,10 +58,14 @@ function renderPreviewTemplate(partials, template, options = {}) {
|
|
|
41
58
|
hbs.registerHelper('get', (resource, opts) => opts.fn(resource === 'tiers' ? { tiers } : resource === 'authors' ? { authors: [exports.demoAuthor] } : resource === 'tags' ? { tags } : { posts: exports.demoPosts }, { data: opts.data }));
|
|
42
59
|
hbs.registerHelper('match', function (value, expected, opts) { return value === expected ? opts.fn(this) : opts.inverse(this); });
|
|
43
60
|
hbs.registerHelper('has', function (opts) { return String(opts.data?.index) === opts.hash.index ? opts.fn(this) : opts.inverse(this); });
|
|
44
|
-
hbs.registerHelper('post', opts => opts.fn(
|
|
61
|
+
hbs.registerHelper('post', opts => opts.fn(postContext, { data: opts.data }));
|
|
45
62
|
hbs.registerHelper('primary_author', function (opts) { return opts.fn(this.primary_author, { data: opts.data }); });
|
|
46
63
|
hbs.registerHelper('img_url', value => value);
|
|
47
|
-
hbs.registerHelper('url', function () {
|
|
64
|
+
hbs.registerHelper('url', function (opts) {
|
|
65
|
+
const pathUrl = this.url || '/a-home-for-independent-ideas/';
|
|
66
|
+
return opts?.hash?.absolute ? `https://example.com${pathUrl}` : pathUrl;
|
|
67
|
+
});
|
|
68
|
+
hbs.registerHelper('encode', value => encodeURIComponent(String(value ?? '')));
|
|
48
69
|
hbs.registerHelper('excerpt', function () { return this.excerpt; });
|
|
49
70
|
hbs.registerHelper('asset', value => `/theme-assets/${value}`);
|
|
50
71
|
hbs.registerHelper('reading_time', () => '4 min read');
|
|
@@ -55,9 +76,10 @@ function renderPreviewTemplate(partials, template, options = {}) {
|
|
|
55
76
|
hbs.registerHelper('navigation', () => new hbs.SafeString('<ul class="nav"><li class="nav-current"><a href="/">Home</a></li><li><a href="/about/">About</a></li><li><a href="/archive/">Archive</a></li></ul>'));
|
|
56
77
|
hbs.registerHelper('search', () => new hbs.SafeString('<button type="button" class="ghcn-icon-button ghcn-button--ghost" aria-label="Search"><svg width="20" height="20" viewBox="0 0 24 24" aria-hidden="true"><circle cx="10" cy="10" r="6" fill="none" stroke="currentColor" stroke-width="2"/><path d="m15 15 6 6" stroke="currentColor" stroke-width="2"/></svg></button>'));
|
|
57
78
|
hbs.registerHelper('price', (amount, opts) => new Intl.NumberFormat('en', { style: 'currency', currency: opts.hash.currency }).format(amount / 100));
|
|
58
|
-
const site = { title: 'Ghostcn Journal', url: '/', description: 'Independent ideas, shared with your readers.', locale: 'en', members_enabled: state !== 'disabled', paid_members_enabled: state !== 'disabled', members_invite_only: state === 'invite', allow_self_signup: !['disabled', 'invite', 'restricted'].includes(state) };
|
|
79
|
+
const site = { title: 'Ghostcn Journal', url: '/', description: 'Independent ideas, shared with your readers.', locale: 'en', members_enabled: state !== 'disabled', paid_members_enabled: state !== 'disabled' && state !== 'free-only', members_invite_only: state === 'invite', allow_self_signup: !['disabled', 'invite', 'restricted'].includes(state) };
|
|
59
80
|
const data = { site, member: ['free', 'paid'].includes(state) ? { paid: state === 'paid' } : undefined };
|
|
60
|
-
|
|
81
|
+
const context = options.context || (options.access === undefined ? exports.previewDemoContext : { ...exports.previewDemoContext, access: options.access });
|
|
82
|
+
return hbs.compile(template)(context, { data });
|
|
61
83
|
}
|
|
62
84
|
function previewInvocation(partialName, parameters) {
|
|
63
85
|
// Values are bound as data, never interpolated into executable Handlebars source.
|
package/dist/utils/registry.js
CHANGED
|
@@ -35,22 +35,32 @@ async function fetchRegistryJson(url, timeoutMs = 5000) {
|
|
|
35
35
|
controller.abort();
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
function safeRegistryBase(raw) {
|
|
39
|
+
const url = new URL(raw.trim().replace(/\/+$/, ''));
|
|
40
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
|
|
41
|
+
throw new Error('Invalid GHOST_UI_REGISTRY_URL.');
|
|
42
|
+
}
|
|
43
|
+
return url.href.replace(/\/+$/, '');
|
|
44
|
+
}
|
|
45
|
+
function isValidRegistryDir(dir) {
|
|
46
|
+
return fs_1.default.existsSync(path_1.default.join(dir, 'index.json')) && fs_1.default.statSync(path_1.default.join(dir, 'index.json')).isFile();
|
|
47
|
+
}
|
|
38
48
|
function findLocalRegistryDir() {
|
|
39
49
|
const bundledCandidates = [
|
|
40
50
|
path_1.default.join(__dirname, 'registry'),
|
|
41
51
|
path_1.default.join(__dirname, '..', 'registry')
|
|
42
52
|
];
|
|
43
53
|
for (const cand of bundledCandidates) {
|
|
44
|
-
if (
|
|
54
|
+
if (isValidRegistryDir(cand)) {
|
|
45
55
|
return cand;
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
|
-
const searchStarts = [process.cwd()
|
|
58
|
+
const searchStarts = [__dirname, process.cwd()];
|
|
49
59
|
for (const start of searchStarts) {
|
|
50
60
|
let currentDir = start;
|
|
51
61
|
while (currentDir !== path_1.default.parse(currentDir).root) {
|
|
52
62
|
const potentialPath = path_1.default.join(currentDir, 'registry');
|
|
53
|
-
if (
|
|
63
|
+
if (isValidRegistryDir(potentialPath)) {
|
|
54
64
|
return potentialPath;
|
|
55
65
|
}
|
|
56
66
|
currentDir = path_1.default.dirname(currentDir);
|
|
@@ -92,7 +102,7 @@ async function getRegistryIndex() {
|
|
|
92
102
|
// If custom registry URL explicitly configured, try remote first
|
|
93
103
|
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
94
104
|
try {
|
|
95
|
-
return await fetchRegistryJson(`${process.env.GHOST_UI_REGISTRY_URL}/index.json`);
|
|
105
|
+
return await fetchRegistryJson(`${safeRegistryBase(process.env.GHOST_UI_REGISTRY_URL)}/index.json`);
|
|
96
106
|
}
|
|
97
107
|
catch {
|
|
98
108
|
// Fallback to local
|
|
@@ -117,7 +127,7 @@ async function getComponent(componentName) {
|
|
|
117
127
|
// If custom registry URL explicitly configured, try remote first
|
|
118
128
|
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
119
129
|
try {
|
|
120
|
-
return await fetchRegistryJson(`${process.env.GHOST_UI_REGISTRY_URL}/components/${sanitized}.json`);
|
|
130
|
+
return await fetchRegistryJson(`${safeRegistryBase(process.env.GHOST_UI_REGISTRY_URL)}/components/${sanitized}.json`);
|
|
121
131
|
}
|
|
122
132
|
catch {
|
|
123
133
|
// Fallback to local
|
|
@@ -53,9 +53,9 @@ function syncGhostcnScripts(themeRoot, scriptsDir) {
|
|
|
53
53
|
const templatePath = safeThemePath(themeRoot, 'default.hbs');
|
|
54
54
|
const directory = safeThemePath(themeRoot, scriptsDir);
|
|
55
55
|
const assetPaths = fs_1.default.existsSync(directory) ? fs_1.default.readdirSync(directory, { withFileTypes: true })
|
|
56
|
-
.filter(entry => entry.isFile() && entry.name.endsWith('.js'))
|
|
56
|
+
.filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.js'))
|
|
57
57
|
.map(entry => toGhostAssetPath(path_1.default.relative(themeRoot, path_1.default.join(directory, entry.name))))
|
|
58
|
-
.sort() : [];
|
|
58
|
+
.sort((a, b) => a.localeCompare(b)) : [];
|
|
59
59
|
if (!fs_1.default.existsSync(templatePath))
|
|
60
60
|
return { status: 'missing-template', templatePath, assetPaths };
|
|
61
61
|
if (!assetPaths.length)
|
|
@@ -64,12 +64,17 @@ function syncGhostcnScripts(themeRoot, scriptsDir) {
|
|
|
64
64
|
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
65
65
|
const start = '{{!-- ghostcn:scripts:start --}}', end = '{{!-- ghostcn:scripts:end --}}';
|
|
66
66
|
const block = [start, ...assetPaths.map(asset => `<script defer src="{{asset "${asset}"}}"></script>`), end].join(newline);
|
|
67
|
-
let updated = original.replace(
|
|
67
|
+
let updated = original.replace(/^[ \t]*\{\{!-- ghostcn:scripts:start --\}\}[\s\S]*?\{\{!-- ghostcn:scripts:end --\}\}[ \t]*(?:\r?\n)?/gm, '');
|
|
68
68
|
// Preserve unrelated host scripts; deduplicate only these owned asset URLs.
|
|
69
|
-
updated = updated.replace(
|
|
69
|
+
updated = updated.replace(/^[ \t]*<script\b[^>]*\bsrc=["'][^"']*\{\{asset\s+["']([^"']+)["']\}\}[^>]*>\s*<\/script>[ \t]*(?:\r?\n)?/gim, (tag, asset) => assetPaths.includes(asset) ? '' : tag);
|
|
70
70
|
if (!/<\/body\s*>/i.test(updated))
|
|
71
71
|
return { status: 'missing-template', templatePath, assetPaths };
|
|
72
|
-
|
|
72
|
+
if (/^[ \t]*<\/body\s*>/im.test(updated)) {
|
|
73
|
+
updated = updated.replace(/^([ \t]*)<\/body\s*>/im, (_match, indent) => `${indentBlock(block, indent, newline)}${newline}${indent}</body>`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
updated = updated.replace(/<\/body\s*>/i, `${newline}${block}${newline}</body>`);
|
|
77
|
+
}
|
|
73
78
|
if (updated !== original)
|
|
74
79
|
fs_1.default.writeFileSync(templatePath, updated, 'utf8');
|
|
75
80
|
return { status: updated === original ? 'unchanged' : 'updated', templatePath, assetPaths };
|
|
@@ -100,12 +105,14 @@ function syncGhostcnStyles(options) {
|
|
|
100
105
|
const templatePath = safeThemePath(options.themeRoot, 'default.hbs');
|
|
101
106
|
const cssPath = safeThemePath(options.themeRoot, options.cssFile);
|
|
102
107
|
const stylesDirPath = safeThemePath(options.themeRoot, options.stylesDir);
|
|
103
|
-
const
|
|
108
|
+
const rootAsset = toGhostAssetPath(options.cssFile);
|
|
109
|
+
const assetPaths = [rootAsset];
|
|
104
110
|
if (fs_1.default.existsSync(stylesDirPath)) {
|
|
105
111
|
const componentStyles = fs_1.default
|
|
106
112
|
.readdirSync(stylesDirPath, { withFileTypes: true })
|
|
107
113
|
.filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.css'))
|
|
108
114
|
.map(entry => toGhostAssetPath(path_1.default.relative(options.themeRoot, path_1.default.join(stylesDirPath, entry.name))))
|
|
115
|
+
.filter(assetPath => assetPath !== rootAsset)
|
|
109
116
|
.sort((a, b) => a.localeCompare(b));
|
|
110
117
|
assetPaths.push(...componentStyles);
|
|
111
118
|
}
|
|
@@ -118,7 +125,7 @@ function syncGhostcnStyles(options) {
|
|
|
118
125
|
const original = fs_1.default.readFileSync(templatePath, 'utf8');
|
|
119
126
|
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
120
127
|
const block = stylesheetBlock(assetPaths, newline);
|
|
121
|
-
const managedBlockPattern = new RegExp(`^[ \\t]*${STYLES_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${STYLES_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[ \\t]*(?:\\r?\\n)?`, '
|
|
128
|
+
const managedBlockPattern = new RegExp(`^[ \\t]*${STYLES_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${STYLES_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[ \\t]*(?:\\r?\\n)?`, 'gm');
|
|
122
129
|
const withoutManagedBlock = original.replace(managedBlockPattern, '');
|
|
123
130
|
const withoutOwnedLinks = removeOwnedStylesheetLinks(withoutManagedBlock, assetPaths);
|
|
124
131
|
const ghostHeadPattern = /^([ \t]*)\{\{ghost_head\}\}/m;
|
|
@@ -13,7 +13,7 @@ const styles_1 = require("./styles");
|
|
|
13
13
|
function buildGhostcnConfig(theme, paths = {}) {
|
|
14
14
|
const normalized = (value, fallback) => value?.trim().replace(/\\/g, '/') || fallback;
|
|
15
15
|
return {
|
|
16
|
-
$schema: 'https://ghostcn.
|
|
16
|
+
$schema: 'https://ghostcn.geekbits.dev/schema.json',
|
|
17
17
|
style: theme.style,
|
|
18
18
|
theme: {
|
|
19
19
|
baseColor: theme.baseColor,
|
|
@@ -29,13 +29,15 @@ function buildGhostcnConfig(theme, paths = {}) {
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
function initializeThemeProject(options) {
|
|
32
|
-
const configPath = (0, theme_files_1.
|
|
33
|
-
const cssPath = (0, theme_files_1.
|
|
32
|
+
const configPath = (0, theme_files_1.safeThemePath)(options.themeRoot, 'components.json');
|
|
33
|
+
const cssPath = (0, theme_files_1.safeThemePath)(options.themeRoot, options.config.cssFile);
|
|
34
34
|
fs_1.default.mkdirSync(path_1.default.dirname(cssPath), { recursive: true });
|
|
35
35
|
fs_1.default.writeFileSync(configPath, JSON.stringify(options.config, null, 2) + '\n', 'utf8');
|
|
36
36
|
fs_1.default.writeFileSync(cssPath, (0, theme_1.generateThemeCss)({ style: options.config.style, ...options.config.theme }), 'utf8');
|
|
37
37
|
if (options.config.style === 'tailwind') {
|
|
38
|
-
|
|
38
|
+
const tailwindRelative = path_1.default.posix.join(path_1.default.posix.dirname(options.config.cssFile.replace(/\\/g, '/')), 'ghostcn-tailwind.css');
|
|
39
|
+
const tailwindPath = (0, theme_files_1.safeThemePath)(options.themeRoot, tailwindRelative);
|
|
40
|
+
fs_1.default.writeFileSync(tailwindPath, (0, styles_1.tailwindTheme)(), 'utf8');
|
|
39
41
|
}
|
|
40
42
|
const styleSync = (0, theme_files_1.syncGhostcnStyles)({
|
|
41
43
|
themeRoot: options.themeRoot,
|
|
@@ -47,11 +47,11 @@ img { max-width: 100%; }
|
|
|
47
47
|
Match the embedded document's native scheme so dark mode does not force a white canvas. */
|
|
48
48
|
iframe[title="comments-frame"] { color-scheme: normal; }
|
|
49
49
|
h1, h2, h3, h4, h5, h6 { font-family: var(--gh-font-heading, inherit); }
|
|
50
|
-
.ghcn-main { min-height: 65vh; }
|
|
51
|
-
.ghcn-page-heading { width: min(100% -
|
|
52
|
-
.ghcn-page-heading h1 { margin: 0; font-size:
|
|
50
|
+
.ghcn-main { min-height: 65vh; overflow-x: clip; }
|
|
51
|
+
.ghcn-page-heading { width: min(100% - 32px, 1152px); margin: var(--ghcn-section-space) auto var(--ghcn-section-gap); }
|
|
52
|
+
.ghcn-page-heading h1 { margin: 0; font-size: var(--ghcn-title-display); line-height: 1.08; letter-spacing: -.045em; overflow-wrap: anywhere; text-wrap: balance; }
|
|
53
53
|
.ghcn-page-heading p { max-width: 42rem; margin: 1rem 0 0; color: var(--muted-foreground); font-size: 1.125rem; }
|
|
54
|
-
.ghcn-
|
|
54
|
+
.ghcn-starter-posts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: var(--ghcn-grid-gap); width: min(100% - 32px, 1152px); margin: var(--ghcn-section-space) auto; }
|
|
55
55
|
.ghcn-article { width: min(100% - 2rem, 46rem); margin: 0 auto 4rem; }
|
|
56
56
|
.ghcn-article-content { color: var(--foreground); font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: clamp(1.0625rem, 2vw, 1.1875rem); }
|
|
57
57
|
.ghcn-article-content > * { margin-block: 0 1.5em; }
|
|
@@ -61,11 +61,13 @@ h1, h2, h3, h4, h5, h6 { font-family: var(--gh-font-heading, inherit); }
|
|
|
61
61
|
.ghcn-article-content .kg-width-wide { width: min(72rem, 100vw - 2rem); max-width: none; margin-left: 50%; transform: translateX(-50%); }
|
|
62
62
|
.ghcn-article-content .kg-width-full { width: 100vw; max-width: none; margin-left: 50%; transform: translateX(-50%); }
|
|
63
63
|
.ghcn-empty { width: min(100% - 2rem, 42rem); margin: 4rem auto; padding: 3rem; border: 1px dashed var(--border); border-radius: min(var(--radius), 1rem); color: var(--muted-foreground); text-align: center; }
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
.ghcn-error { width: min(100% - 2rem, 38rem); margin: 5rem auto; text-align: center; }
|
|
65
|
+
.ghcn-error__code { margin: 0; color: var(--muted-foreground); font-size: 0.875rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
66
|
+
.ghcn-error__title { margin: 0.75rem 0 0; font-size: var(--ghcn-title-display); line-height: 1.1; letter-spacing: -0.04em; }
|
|
67
|
+
.ghcn-error__message { margin: 1rem auto 1.75rem; color: var(--muted-foreground); max-width: 30rem; }
|
|
66
68
|
`;
|
|
67
69
|
}
|
|
68
|
-
function defaultTemplate(
|
|
70
|
+
function defaultTemplate() {
|
|
69
71
|
return `<!DOCTYPE html>
|
|
70
72
|
<html lang="{{@site.locale}}"{{#match @custom.color_scheme "Dark"}} class="dark-mode"{{else match @custom.color_scheme "Auto"}} class="auto-color"{{/match}}>
|
|
71
73
|
<head>
|
|
@@ -100,7 +102,7 @@ function indexTemplate(options) {
|
|
|
100
102
|
</header>
|
|
101
103
|
|
|
102
104
|
{{#if posts}}
|
|
103
|
-
<section class="ghcn-
|
|
105
|
+
<section class="ghcn-starter-posts" aria-label="Latest posts">
|
|
104
106
|
{{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
|
|
105
107
|
</section>
|
|
106
108
|
{{else}}
|
|
@@ -146,12 +148,23 @@ function archiveTemplate(kind) {
|
|
|
146
148
|
return `{{!< default}}
|
|
147
149
|
|
|
148
150
|
${header}
|
|
149
|
-
<section class="ghcn-
|
|
151
|
+
<section class="ghcn-starter-posts" aria-label="Posts">
|
|
150
152
|
{{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
|
|
151
153
|
</section>
|
|
152
154
|
{{pagination}}
|
|
153
155
|
`;
|
|
154
156
|
}
|
|
157
|
+
function errorTemplate() {
|
|
158
|
+
return `{{!< default}}
|
|
159
|
+
|
|
160
|
+
<section class="ghcn-error">
|
|
161
|
+
<p class="ghcn-error__code">{{statusCode}}</p>
|
|
162
|
+
<h1 class="ghcn-error__title">{{message}}</h1>
|
|
163
|
+
<p class="ghcn-error__message">The page you are looking for may have moved or no longer exists.</p>
|
|
164
|
+
<a class="ghcn-button" href="{{@site.url}}">Back to {{@site.title}}</a>
|
|
165
|
+
</section>
|
|
166
|
+
`;
|
|
167
|
+
}
|
|
155
168
|
function packageJson(options) {
|
|
156
169
|
const gscanCommand = {
|
|
157
170
|
npm: 'npx --yes gscan@6.4.2 .',
|
|
@@ -159,24 +172,23 @@ function packageJson(options) {
|
|
|
159
172
|
yarn: 'yarn dlx gscan@6.4.2 .',
|
|
160
173
|
bun: 'bunx gscan@6.4.2 .'
|
|
161
174
|
};
|
|
175
|
+
const zipScript = `${options.packageManager} run build && node ./scripts/zip.mjs`;
|
|
162
176
|
const scripts = options.style === 'tailwind'
|
|
163
177
|
? {
|
|
164
178
|
dev: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --watch',
|
|
165
179
|
build: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --minify',
|
|
166
180
|
test: 'node ./scripts/check.mjs',
|
|
167
|
-
zip:
|
|
181
|
+
zip: zipScript,
|
|
168
182
|
validate: gscanCommand[options.packageManager]
|
|
169
183
|
}
|
|
170
184
|
: {
|
|
171
185
|
dev: 'node ./scripts/dev.mjs',
|
|
172
186
|
build: 'node ./scripts/build.mjs',
|
|
173
187
|
test: 'node ./scripts/check.mjs',
|
|
174
|
-
zip:
|
|
188
|
+
zip: zipScript,
|
|
175
189
|
validate: gscanCommand[options.packageManager]
|
|
176
190
|
};
|
|
177
191
|
const devDependencies = {};
|
|
178
|
-
// Use the selected package manager for the build preceding archive creation.
|
|
179
|
-
scripts.zip = `${options.packageManager} run build && node ./scripts/zip.mjs`;
|
|
180
192
|
if (options.style === 'tailwind') {
|
|
181
193
|
devDependencies.tailwindcss = '^4.1.0';
|
|
182
194
|
devDependencies['@tailwindcss/cli'] = '^4.1.0';
|
|
@@ -296,13 +308,14 @@ function scaffoldTheme(options) {
|
|
|
296
308
|
: css;
|
|
297
309
|
const files = {
|
|
298
310
|
'package.json': packageJson({ ...options, themeName }),
|
|
299
|
-
'default.hbs': defaultTemplate(
|
|
311
|
+
'default.hbs': defaultTemplate(),
|
|
300
312
|
'index.hbs': indexTemplate(options),
|
|
301
313
|
'post.hbs': postTemplate(options),
|
|
302
314
|
'partials/content-cta.hbs': '{{{html}}}\n{{> "components/member-cta"}}\n',
|
|
303
315
|
'page.hbs': pageTemplate(),
|
|
304
316
|
'tag.hbs': archiveTemplate('tag'),
|
|
305
317
|
'author.hbs': archiveTemplate('author'),
|
|
318
|
+
'error.hbs': errorTemplate(),
|
|
306
319
|
'assets/css/source.css': sourceCss,
|
|
307
320
|
'assets/built/screen.css': css,
|
|
308
321
|
'scripts/check.mjs': "import { fileURLToPath } from 'node:url';\nimport { reportTheme } from './theme-tools.mjs';\nif (!reportTheme(fileURLToPath(new URL('../', import.meta.url)))) process.exitCode = 1;\n",
|
package/dist/utils/theme.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type BaseColor = 'zinc' | 'slate' | 'stone' | 'gray' | 'neutral';
|
|
2
|
-
export type AccentColor = 'ghost' | 'zinc' | 'indigo' | 'violet' | 'blue' | 'emerald' | 'rose' | 'orange';
|
|
3
|
-
export type Radius = '0' | '0.25rem' | '0.5rem' | '0.75rem' | '1rem' | '9999px';
|
|
1
|
+
export type BaseColor = 'doks' | 'zinc' | 'slate' | 'stone' | 'gray' | 'neutral';
|
|
2
|
+
export type AccentColor = 'doks' | 'ghost' | 'zinc' | 'indigo' | 'violet' | 'blue' | 'emerald' | 'rose' | 'orange';
|
|
3
|
+
export type Radius = '0' | '0.25rem' | '0.5rem' | '0.625rem' | '0.75rem' | '1rem' | '9999px';
|
|
4
4
|
export interface ThemeConfig {
|
|
5
5
|
style: 'tailwind' | 'css';
|
|
6
6
|
baseColor: BaseColor;
|