ghostcn 1.1.0 → 1.4.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 +225 -3
- package/dist/commands/add.d.ts +6 -1
- package/dist/commands/add.js +121 -83
- package/dist/commands/create.js +8 -1
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +7 -0
- package/dist/commands/init.js +5 -0
- package/dist/commands/pack.d.ts +1 -0
- package/dist/commands/pack.js +8 -0
- package/dist/commands/playground.d.ts +3 -0
- package/dist/commands/playground.js +29 -0
- package/dist/index.js +20 -2
- package/dist/registry/components/alert.json +62 -0
- package/dist/registry/components/archive-header.json +57 -0
- package/dist/registry/components/author-card.json +23 -2
- package/dist/registry/components/author-list.json +55 -0
- package/dist/registry/components/badge.json +51 -0
- package/dist/registry/components/button.json +74 -0
- package/dist/registry/components/card.json +70 -0
- package/dist/registry/components/featured-posts.json +18 -1
- package/dist/registry/components/input.json +94 -0
- package/dist/registry/components/member-cta.json +15 -1
- package/dist/registry/components/newsletter-form.json +23 -2
- package/dist/registry/components/pagination.json +12 -1
- package/dist/registry/components/post-card.json +25 -2
- package/dist/registry/components/post-grid.json +54 -0
- package/dist/registry/components/post-header.json +18 -1
- package/dist/registry/components/post-navigation.json +41 -0
- package/dist/registry/components/pricing-table.json +34 -5
- package/dist/registry/components/related-posts.json +53 -0
- package/dist/registry/components/site-footer.json +15 -1
- package/dist/registry/components/site-header.json +17 -2
- package/dist/registry/components/table-of-contents.json +47 -0
- package/dist/registry/components/tag-grid.json +64 -0
- package/dist/registry/components/tag-list.json +38 -0
- package/dist/registry/index.json +131 -0
- package/dist/templates/playground/index.html +5 -0
- package/dist/templates/playground/playground.css +18 -0
- package/dist/templates/playground/playground.js +71 -0
- package/dist/templates/playground/preview.css +5 -0
- package/dist/templates/playground/preview.js +12 -0
- package/dist/templates/theme-tools.mjs +178 -0
- package/dist/utils/component-diff.d.ts +18 -0
- package/dist/utils/component-diff.js +93 -0
- package/dist/utils/component-files.d.ts +9 -0
- package/dist/utils/component-files.js +48 -0
- package/dist/utils/component-history.d.ts +11 -0
- package/dist/utils/component-history.js +47 -0
- package/dist/utils/component-installer.d.ts +2 -0
- package/dist/utils/component-installer.js +34 -36
- package/dist/utils/component-plan.d.ts +7 -0
- package/dist/utils/component-plan.js +43 -0
- package/dist/utils/playground-server.d.ts +9 -0
- package/dist/utils/playground-server.js +189 -0
- package/dist/utils/preview-renderer.d.ts +143 -0
- package/dist/utils/preview-renderer.js +70 -0
- package/dist/utils/registry.d.ts +7 -0
- package/dist/utils/registry.js +12 -18
- package/dist/utils/styles.d.ts +3 -0
- package/dist/utils/styles.js +20 -0
- package/dist/utils/theme-files.d.ts +2 -0
- package/dist/utils/theme-files.js +46 -4
- package/dist/utils/theme-project.js +9 -4
- package/dist/utils/theme-scaffold.js +61 -24
- package/dist/utils/theme-tooling.d.ts +2 -0
- package/dist/utils/theme-tooling.js +20 -0
- package/dist/utils/theme.js +4 -2
- package/package.json +6 -4
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startPlayground = startPlayground;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const http_1 = __importDefault(require("http"));
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const registry_1 = require("./registry");
|
|
12
|
+
const component_plan_1 = require("./component-plan");
|
|
13
|
+
const component_files_1 = require("./component-files");
|
|
14
|
+
const theme_files_1 = require("./theme-files");
|
|
15
|
+
const preview_renderer_1 = require("./preview-renderer");
|
|
16
|
+
const escape = (value) => value.replace(/[&<>"']/g, character => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[character]));
|
|
17
|
+
const mime = { '.css': 'text/css', '.js': 'text/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.avif': 'image/avif', '.woff': 'font/woff', '.woff2': 'font/woff2', '.ttf': 'font/ttf' };
|
|
18
|
+
const templatesRoot = path_1.default.resolve(__dirname, '../templates/playground');
|
|
19
|
+
function collectThemeFiles(themeRoot, directory, extension) {
|
|
20
|
+
const start = (0, theme_files_1.safeThemePath)(themeRoot, directory);
|
|
21
|
+
const results = [];
|
|
22
|
+
function walk(target) {
|
|
23
|
+
if (!fs_1.default.existsSync(target))
|
|
24
|
+
return;
|
|
25
|
+
const stat = fs_1.default.lstatSync(target);
|
|
26
|
+
if (stat.isSymbolicLink())
|
|
27
|
+
throw new Error('Playground refuses symlinked theme files.');
|
|
28
|
+
if (stat.isDirectory())
|
|
29
|
+
for (const item of fs_1.default.readdirSync(target)) {
|
|
30
|
+
if (results.length > 10000)
|
|
31
|
+
throw new Error('Too many playground theme files.');
|
|
32
|
+
walk((0, theme_files_1.safeThemePath)(themeRoot, path_1.default.relative(themeRoot, path_1.default.join(target, item))));
|
|
33
|
+
}
|
|
34
|
+
else if (stat.isFile() && (!extension || target.endsWith(extension)))
|
|
35
|
+
results.push(target);
|
|
36
|
+
}
|
|
37
|
+
walk(start);
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
function themeStyles(themeRoot, config) {
|
|
41
|
+
const layout = (0, theme_files_1.safeThemePath)(themeRoot, 'default.hbs');
|
|
42
|
+
const source = fs_1.default.existsSync(layout) ? fs_1.default.readFileSync(layout, 'utf8') : '';
|
|
43
|
+
const links = [];
|
|
44
|
+
for (const link of source.match(/<link\b[^>]*>/g) || []) {
|
|
45
|
+
if (!/rel=["']stylesheet["']/.test(link))
|
|
46
|
+
continue;
|
|
47
|
+
const asset = link.match(/\{\{asset\s+["']([^"']+\.css)["']\s*\}\}/)?.[1] || link.match(/href=["']\/assets\/([^"']+\.css)["']/)?.[1];
|
|
48
|
+
if (asset && !links.includes(asset)) {
|
|
49
|
+
(0, theme_files_1.safeThemePath)(themeRoot, `assets/${asset}`);
|
|
50
|
+
links.push(asset);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!links.length) {
|
|
54
|
+
const fallback = [config.cssFile, ...collectThemeFiles(themeRoot, config.aliases.styles, '.css').map(file => path_1.default.relative(themeRoot, file).replace(/\\/g, '/')), 'assets/built/screen.css'];
|
|
55
|
+
for (const relative of fallback)
|
|
56
|
+
if (fs_1.default.existsSync((0, theme_files_1.safeThemePath)(themeRoot, relative)))
|
|
57
|
+
links.push(relative.replace(/^assets\//, ''));
|
|
58
|
+
}
|
|
59
|
+
return links;
|
|
60
|
+
}
|
|
61
|
+
async function startPlayground(options) {
|
|
62
|
+
const themeRoot = fs_1.default.realpathSync(options.themeRoot);
|
|
63
|
+
const config = JSON.parse(fs_1.default.readFileSync((0, theme_files_1.safeThemePath)(themeRoot, 'components.json'), 'utf8').replace(/^\uFEFF/, ''));
|
|
64
|
+
if (!['css', 'tailwind'].includes(config.style) || !config.aliases)
|
|
65
|
+
throw new Error('Invalid components.json. Run ghostcn doctor.');
|
|
66
|
+
(0, component_files_1.componentPartialName)(config, 'button');
|
|
67
|
+
const port = options.port ?? 4190;
|
|
68
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
69
|
+
throw new Error('Port must be an integer between 0 and 65535.');
|
|
70
|
+
const catalog = [];
|
|
71
|
+
for (const item of await (0, registry_1.getRegistryIndex)()) {
|
|
72
|
+
const manifest = await (0, registry_1.getComponent)(item.name);
|
|
73
|
+
if (manifest)
|
|
74
|
+
catalog.push(manifest);
|
|
75
|
+
}
|
|
76
|
+
const plans = new Map();
|
|
77
|
+
for (const manifest of catalog)
|
|
78
|
+
plans.set(manifest.name, await (0, component_plan_1.componentPlan)(themeRoot, config, manifest.name, async (name) => catalog.find(item => item.name === name) || null));
|
|
79
|
+
const installed = () => catalog.filter(manifest => {
|
|
80
|
+
const file = (0, component_files_1.componentFiles)(themeRoot, config, manifest).find(file => file.relative.endsWith('.hbs'));
|
|
81
|
+
return file && fs_1.default.existsSync(file.target);
|
|
82
|
+
});
|
|
83
|
+
const revision = () => {
|
|
84
|
+
const files = [(0, theme_files_1.safeThemePath)(themeRoot, 'default.hbs'), ...collectThemeFiles(themeRoot, 'partials', '.hbs'), ...collectThemeFiles(themeRoot, 'assets')];
|
|
85
|
+
const hash = crypto_1.default.createHash('sha256');
|
|
86
|
+
for (const file of files.sort())
|
|
87
|
+
if (fs_1.default.existsSync(file)) {
|
|
88
|
+
const stat = fs_1.default.statSync(file);
|
|
89
|
+
hash.update(`${file}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`);
|
|
90
|
+
}
|
|
91
|
+
return hash.digest('hex');
|
|
92
|
+
};
|
|
93
|
+
let actualPort = port;
|
|
94
|
+
const server = http_1.default.createServer((request, response) => {
|
|
95
|
+
const send = (status, body, type = 'text/html') => {
|
|
96
|
+
response.writeHead(status, {
|
|
97
|
+
'Content-Type': `${type}${type.startsWith('text/') || type === 'application/json' ? '; charset=utf-8' : ''}`,
|
|
98
|
+
'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'no-referrer',
|
|
99
|
+
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'self'; form-action 'none'; base-uri 'none'; frame-ancestors 'self'"
|
|
100
|
+
});
|
|
101
|
+
response.end(request.method === 'HEAD' ? undefined : body);
|
|
102
|
+
};
|
|
103
|
+
if (!['GET', 'HEAD'].includes(request.method || '')) {
|
|
104
|
+
send(405, 'Read-only playground.', 'text/plain');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (![`127.0.0.1:${actualPort}`, `localhost:${actualPort}`].includes(request.headers.host || '')) {
|
|
108
|
+
send(403, 'Localhost access only.', 'text/plain');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const url = new URL(request.url || '/', `http://127.0.0.1:${actualPort}`);
|
|
113
|
+
if (url.pathname === '/') {
|
|
114
|
+
send(200, fs_1.default.readFileSync(path_1.default.join(templatesRoot, 'index.html')));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (url.pathname === '/catalog') {
|
|
118
|
+
send(200, JSON.stringify({ style: config.style, components: installed().map(manifest => ({ name: manifest.name, description: manifest.description, parameters: manifest.parameters || {}, styleSlots: manifest.styleSlots || {}, partial: manifest.name === 'pagination' ? 'pagination' : (0, component_files_1.componentPartialName)(config, manifest.name), defaults: preview_renderer_1.demoParameters[manifest.name] || {} })) }), 'application/json');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (url.pathname === '/revision') {
|
|
122
|
+
send(200, JSON.stringify({ revision: revision() }), 'application/json');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (url.pathname === '/playground.css' || url.pathname === '/playground.js' || url.pathname === '/preview.js' || url.pathname === '/preview.css') {
|
|
126
|
+
send(200, fs_1.default.readFileSync(path_1.default.join(templatesRoot, path_1.default.basename(url.pathname))), mime[path_1.default.extname(url.pathname)]);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (url.pathname.startsWith('/theme-assets/')) {
|
|
130
|
+
const relative = decodeURIComponent(url.pathname.slice('/theme-assets/'.length));
|
|
131
|
+
if (!mime[path_1.default.extname(relative).toLowerCase()] || /(^|[\\/])\.\.?([\\/]|$)/.test(relative)) {
|
|
132
|
+
send(403, 'Unsupported asset.', 'text/plain');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const asset = (0, theme_files_1.safeThemePath)(themeRoot, `assets/${relative}`);
|
|
136
|
+
if (!fs_1.default.existsSync(asset) || !fs_1.default.statSync(asset).isFile()) {
|
|
137
|
+
send(404, 'Asset not found. Run your theme build.', 'text/plain');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
send(200, fs_1.default.readFileSync(asset), mime[path_1.default.extname(relative).toLowerCase()]);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (url.pathname.startsWith('/preview/')) {
|
|
144
|
+
const name = url.pathname.slice('/preview/'.length);
|
|
145
|
+
const manifest = installed().find(item => item.name === name);
|
|
146
|
+
if (!manifest) {
|
|
147
|
+
send(404, 'Component is not installed. Run ghostcn add first.', 'text/plain');
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const partials = {};
|
|
151
|
+
for (const dependency of plans.get(name) || [])
|
|
152
|
+
for (const file of dependency.files.filter(file => file.relative.endsWith('.hbs'))) {
|
|
153
|
+
// Partial blocks have fallback content, so missing dependencies can otherwise
|
|
154
|
+
// appear to render successfully while silently dropping the card wrapper.
|
|
155
|
+
if (!fs_1.default.existsSync((0, theme_files_1.safeThemePath)(themeRoot, file.relative)))
|
|
156
|
+
throw new Error(`Missing component dependency partial: ${file.relative}. Run ghostcn add ${name}.`);
|
|
157
|
+
}
|
|
158
|
+
for (const file of collectThemeFiles(themeRoot, 'partials', '.hbs'))
|
|
159
|
+
partials[path_1.default.relative(path_1.default.join(themeRoot, 'partials'), file).replace(/\\/g, '/').replace(/\.hbs$/, '')] = fs_1.default.readFileSync(file, 'utf8');
|
|
160
|
+
const parameters = { ...(preview_renderer_1.demoParameters[name] || {}) };
|
|
161
|
+
const keys = new Set([...Object.keys(manifest.parameters || {}), ...Object.keys(manifest.styleSlots || {})]);
|
|
162
|
+
for (const key of keys)
|
|
163
|
+
if (url.searchParams.has(key))
|
|
164
|
+
parameters[key] = ['disabled', 'required', 'invalid', 'urgent'].includes(key) ? url.searchParams.get(key) === 'true' : url.searchParams.get(key);
|
|
165
|
+
const state = preview_renderer_1.previewStates.includes(url.searchParams.get('state') || '') ? url.searchParams.get('state') : 'visitor';
|
|
166
|
+
const scheme = url.searchParams.get('scheme');
|
|
167
|
+
const nameInTheme = name === 'pagination' ? 'pagination' : (0, component_files_1.componentPartialName)(config, name);
|
|
168
|
+
const context = { ...(name === 'author-card' ? preview_renderer_1.demoAuthor : preview_renderer_1.previewDemoContext), ...parameters };
|
|
169
|
+
let source = (0, preview_renderer_1.previewInvocation)(nameInTheme, parameters);
|
|
170
|
+
if (name === 'pagination')
|
|
171
|
+
source = `{{> "pagination" pagination ${Object.keys(parameters).map(key => `${key}=${key}`).join(' ')}}}`;
|
|
172
|
+
let html = (0, preview_renderer_1.renderPreviewTemplate)(partials, source, { state, context });
|
|
173
|
+
if (name === 'table-of-contents')
|
|
174
|
+
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
|
+
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);
|
|
176
|
+
const styles = themeStyles(themeRoot, config).map(asset => `<link rel="stylesheet" href="/theme-assets/${escape(asset)}">`).join('');
|
|
177
|
+
const scriptTags = scripts.map(file => `<script defer src="/theme-assets/${escape(file.relative.replace(/^assets\//, ''))}"></script>`).join('');
|
|
178
|
+
send(200, `<!doctype html><html lang="en" class="${scheme === 'dark' ? 'dark-mode dark' : scheme === 'auto' ? 'auto-color' : ''}" data-theme="${scheme === 'dark' ? 'dark' : 'light'}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escape(name)} preview</title>${styles}<link rel="stylesheet" href="/preview.css"></head><body><main class="playground-preview">${html.trim() || '<p>This component is hidden for the selected settings.</p>'}<p id="preview-feedback" role="status"></p></main>${scriptTags}<script defer src="/preview.js"></script></body></html>`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
send(404, 'Not found.', 'text/plain');
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
send(400, `<!doctype html><html lang="en"><head><title>Preview error</title></head><body><h1>Cannot render preview</h1><p>${escape(error.message)}</p><p>Check missing partials, run your theme build, or use Ghost to test helpers not supported by this synthetic preview.</p></body></html>`);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
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 { server, url: `http://127.0.0.1:${actualPort}`, close: () => new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve())) };
|
|
189
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export declare const demoImage: string;
|
|
2
|
+
export declare const demoAuthor: {
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
bio: string;
|
|
6
|
+
location: string;
|
|
7
|
+
count: {
|
|
8
|
+
posts: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const demoPost: {
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
excerpt: string;
|
|
15
|
+
custom_excerpt: string;
|
|
16
|
+
feature_image: string;
|
|
17
|
+
feature_image_alt: string;
|
|
18
|
+
primary_author: {
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
|
+
bio: string;
|
|
22
|
+
location: string;
|
|
23
|
+
count: {
|
|
24
|
+
posts: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
primary_tag: {
|
|
28
|
+
name: string;
|
|
29
|
+
description: string;
|
|
30
|
+
url: string;
|
|
31
|
+
visibility: string;
|
|
32
|
+
};
|
|
33
|
+
tags: {
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
url: string;
|
|
37
|
+
visibility: string;
|
|
38
|
+
}[];
|
|
39
|
+
access: boolean;
|
|
40
|
+
};
|
|
41
|
+
export declare const demoPosts: {
|
|
42
|
+
title: string;
|
|
43
|
+
url: string;
|
|
44
|
+
excerpt: string;
|
|
45
|
+
custom_excerpt: string;
|
|
46
|
+
feature_image: string;
|
|
47
|
+
feature_image_alt: string;
|
|
48
|
+
primary_author: {
|
|
49
|
+
name: string;
|
|
50
|
+
url: string;
|
|
51
|
+
bio: string;
|
|
52
|
+
location: string;
|
|
53
|
+
count: {
|
|
54
|
+
posts: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
primary_tag: {
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
url: string;
|
|
61
|
+
visibility: string;
|
|
62
|
+
};
|
|
63
|
+
tags: {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
url: string;
|
|
67
|
+
visibility: string;
|
|
68
|
+
}[];
|
|
69
|
+
access: boolean;
|
|
70
|
+
}[];
|
|
71
|
+
export declare const previewStates: string[];
|
|
72
|
+
export declare const previewDemoContext: {
|
|
73
|
+
posts: {
|
|
74
|
+
title: string;
|
|
75
|
+
url: string;
|
|
76
|
+
excerpt: string;
|
|
77
|
+
custom_excerpt: string;
|
|
78
|
+
feature_image: string;
|
|
79
|
+
feature_image_alt: string;
|
|
80
|
+
primary_author: {
|
|
81
|
+
name: string;
|
|
82
|
+
url: string;
|
|
83
|
+
bio: string;
|
|
84
|
+
location: string;
|
|
85
|
+
count: {
|
|
86
|
+
posts: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
primary_tag: {
|
|
90
|
+
name: string;
|
|
91
|
+
description: string;
|
|
92
|
+
url: string;
|
|
93
|
+
visibility: string;
|
|
94
|
+
};
|
|
95
|
+
tags: {
|
|
96
|
+
name: string;
|
|
97
|
+
description: string;
|
|
98
|
+
url: string;
|
|
99
|
+
visibility: string;
|
|
100
|
+
}[];
|
|
101
|
+
access: boolean;
|
|
102
|
+
}[];
|
|
103
|
+
pagination: {
|
|
104
|
+
page: number;
|
|
105
|
+
pages: number;
|
|
106
|
+
prev: number;
|
|
107
|
+
next: number;
|
|
108
|
+
};
|
|
109
|
+
title: string;
|
|
110
|
+
url: string;
|
|
111
|
+
excerpt: string;
|
|
112
|
+
custom_excerpt: string;
|
|
113
|
+
feature_image: string;
|
|
114
|
+
feature_image_alt: string;
|
|
115
|
+
primary_author: {
|
|
116
|
+
name: string;
|
|
117
|
+
url: string;
|
|
118
|
+
bio: string;
|
|
119
|
+
location: string;
|
|
120
|
+
count: {
|
|
121
|
+
posts: number;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
primary_tag: {
|
|
125
|
+
name: string;
|
|
126
|
+
description: string;
|
|
127
|
+
url: string;
|
|
128
|
+
visibility: string;
|
|
129
|
+
};
|
|
130
|
+
tags: {
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
url: string;
|
|
134
|
+
visibility: string;
|
|
135
|
+
}[];
|
|
136
|
+
access: boolean;
|
|
137
|
+
};
|
|
138
|
+
export declare const demoParameters: Record<string, Record<string, string>>;
|
|
139
|
+
export declare function renderPreviewTemplate(partials: Record<string, string>, template: string, options?: {
|
|
140
|
+
state?: string;
|
|
141
|
+
context?: Record<string, unknown>;
|
|
142
|
+
}): string;
|
|
143
|
+
export declare function previewInvocation(partialName: string, parameters: Record<string, unknown>): string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.demoParameters = exports.previewDemoContext = exports.previewStates = exports.demoPosts = exports.demoPost = exports.demoAuthor = exports.demoImage = void 0;
|
|
7
|
+
exports.renderPreviewTemplate = renderPreviewTemplate;
|
|
8
|
+
exports.previewInvocation = previewInvocation;
|
|
9
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
10
|
+
// Synthetic data only. This is shared by static docs and the local playground,
|
|
11
|
+
// never used by production themes, never connected to Ghost/Stripe/email APIs.
|
|
12
|
+
exports.demoImage = 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="675"><rect width="1200" height="675" fill="#172f45"/><path d="M0 470h1200v205H0z" fill="#e46735"/><text x="80" y="180" font-family="sans-serif" font-size="72" fill="white">Ghostcn Journal</text><text x="80" y="270" font-family="sans-serif" font-size="36" fill="#b7cad9">Demo feature image</text></svg>');
|
|
13
|
+
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
|
+
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: 'Demo feature image for Ghostcn Journal', primary_author: exports.demoAuthor, primary_tag: tags[0], tags, access: true };
|
|
16
|
+
exports.demoPosts = [exports.demoPost, { ...exports.demoPost, title: 'Make room for your readers' }, { ...exports.demoPost, title: 'The details that make it yours' }];
|
|
17
|
+
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
|
+
exports.previewStates = ['visitor', 'free', 'paid', 'disabled', 'invite', 'restricted'];
|
|
19
|
+
exports.previewDemoContext = { ...exports.demoPost, posts: exports.demoPosts, pagination: { page: 2, pages: 4, prev: 1, next: 3 } };
|
|
20
|
+
exports.demoParameters = {
|
|
21
|
+
button: { text: 'Read the story' },
|
|
22
|
+
card: { heading: 'Make yourself at home', description: 'A small card, ready for your content.', body: 'Build something for your readers.', footer: 'Your publication. Your style.' },
|
|
23
|
+
badge: { text: 'Featured' },
|
|
24
|
+
input: { label: 'Email address', type: 'email', name: 'email', placeholder: 'you@example.com', hint: 'We will keep your email private.', hintId: 'demo-email-hint' },
|
|
25
|
+
alert: { heading: 'You are all set', description: 'Your theme is ready to customize.' },
|
|
26
|
+
'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' }
|
|
28
|
+
};
|
|
29
|
+
function renderPreviewTemplate(partials, template, options = {}) {
|
|
30
|
+
const state = options.state || 'visitor';
|
|
31
|
+
const hbs = handlebars_1.default.create();
|
|
32
|
+
hbs.registerPartial(partials);
|
|
33
|
+
hbs.registerHelper('foreach', (items, opts) => {
|
|
34
|
+
const visible = (items || []).filter(item => opts.hash.visibility !== 'public' || item.visibility !== 'internal');
|
|
35
|
+
if (!visible.length)
|
|
36
|
+
return opts.inverse ? opts.inverse({}) : '';
|
|
37
|
+
return visible.map((item, index) => opts.fn(item, { data: { ...opts.data, index, first: index === 0, last: index === visible.length - 1 } })).join('');
|
|
38
|
+
});
|
|
39
|
+
hbs.registerHelper('prev_post', opts => opts.fn({ ...exports.demoPost, title: 'The previous story', url: '/previous-story/' }, { data: opts.data }));
|
|
40
|
+
hbs.registerHelper('next_post', opts => opts.fn({ ...exports.demoPost, title: 'The next story', url: '/next-story/' }, { data: opts.data }));
|
|
41
|
+
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
|
+
hbs.registerHelper('match', function (value, expected, opts) { return value === expected ? opts.fn(this) : opts.inverse(this); });
|
|
43
|
+
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(exports.demoPost, { data: opts.data }));
|
|
45
|
+
hbs.registerHelper('primary_author', function (opts) { return opts.fn(this.primary_author, { data: opts.data }); });
|
|
46
|
+
hbs.registerHelper('img_url', value => value);
|
|
47
|
+
hbs.registerHelper('url', function () { return this.url; });
|
|
48
|
+
hbs.registerHelper('excerpt', function () { return this.excerpt; });
|
|
49
|
+
hbs.registerHelper('asset', value => `/theme-assets/${value}`);
|
|
50
|
+
hbs.registerHelper('reading_time', () => '4 min read');
|
|
51
|
+
hbs.registerHelper('date', opts => opts.hash.format === 'YYYY' ? '2026' : opts.hash.format === 'YYYY-MM-DD' ? '2026-10-01' : '1 Oct 2026');
|
|
52
|
+
hbs.registerHelper('plural', (count, opts) => String(count === 0 ? opts.hash.empty : count === 1 ? opts.hash.singular : opts.hash.plural).replace('%', String(count)));
|
|
53
|
+
hbs.registerHelper('social_url', () => 'https://example.com');
|
|
54
|
+
hbs.registerHelper('page_url', page => `/page/${page}/`);
|
|
55
|
+
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
|
+
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
|
+
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) };
|
|
59
|
+
const data = { site, member: ['free', 'paid'].includes(state) ? { paid: state === 'paid' } : undefined };
|
|
60
|
+
return hbs.compile(template)(options.context || exports.previewDemoContext, { data });
|
|
61
|
+
}
|
|
62
|
+
function previewInvocation(partialName, parameters) {
|
|
63
|
+
// Values are bound as data, never interpolated into executable Handlebars source.
|
|
64
|
+
if (!/^[a-zA-Z0-9/_-]+$/.test(partialName))
|
|
65
|
+
throw new Error('Unsafe partial name.');
|
|
66
|
+
const keys = Object.keys(parameters);
|
|
67
|
+
if (keys.some(key => !/^[a-zA-Z][a-zA-Z0-9]*$/.test(key)))
|
|
68
|
+
throw new Error('Unsafe preview parameter.');
|
|
69
|
+
return `{{> "${partialName}" ${keys.map(key => `${key}=${key}`).join(' ')}}}`;
|
|
70
|
+
}
|
package/dist/utils/registry.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export interface ComponentManifest {
|
|
|
13
13
|
dependencies?: string[];
|
|
14
14
|
ghost_version?: string;
|
|
15
15
|
files: ComponentFile[];
|
|
16
|
+
styleSlots?: Record<string, string[]>;
|
|
17
|
+
parameters?: Record<string, {
|
|
18
|
+
description: string;
|
|
19
|
+
options?: string[];
|
|
20
|
+
default?: string;
|
|
21
|
+
}>;
|
|
16
22
|
gscan?: {
|
|
17
23
|
rules_satisfied: string[];
|
|
18
24
|
notes: string;
|
|
@@ -26,6 +32,7 @@ export interface RegistryItem {
|
|
|
26
32
|
files: string[];
|
|
27
33
|
}
|
|
28
34
|
export declare function sanitizeComponentName(name: string): string;
|
|
35
|
+
export declare function fetchRegistryJson<T>(url: string, timeoutMs?: number): Promise<T>;
|
|
29
36
|
export declare function findLocalIndex(): RegistryItem[] | null;
|
|
30
37
|
export declare function findLocalManifest(componentName: string): ComponentManifest | null;
|
|
31
38
|
export declare function getRegistryIndex(): Promise<RegistryItem[]>;
|
package/dist/utils/registry.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DEFAULT_REGISTRY_URL = void 0;
|
|
7
7
|
exports.sanitizeComponentName = sanitizeComponentName;
|
|
8
|
+
exports.fetchRegistryJson = fetchRegistryJson;
|
|
8
9
|
exports.findLocalIndex = findLocalIndex;
|
|
9
10
|
exports.findLocalManifest = findLocalManifest;
|
|
10
11
|
exports.getRegistryIndex = getRegistryIndex;
|
|
@@ -19,14 +20,19 @@ function sanitizeComponentName(name) {
|
|
|
19
20
|
}
|
|
20
21
|
return sanitized;
|
|
21
22
|
}
|
|
22
|
-
async function
|
|
23
|
+
async function fetchRegistryJson(url, timeoutMs = 5000) {
|
|
23
24
|
const controller = new AbortController();
|
|
24
25
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
28
|
+
if (!response.ok)
|
|
29
|
+
throw new Error(`Registry returned HTTP ${response.status}.`);
|
|
30
|
+
// Keep the deadline active through the response body, not just its headers.
|
|
31
|
+
return await response.json();
|
|
27
32
|
}
|
|
28
33
|
finally {
|
|
29
34
|
clearTimeout(timer);
|
|
35
|
+
controller.abort();
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
function findLocalRegistryDir() {
|
|
@@ -86,10 +92,7 @@ async function getRegistryIndex() {
|
|
|
86
92
|
// If custom registry URL explicitly configured, try remote first
|
|
87
93
|
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
88
94
|
try {
|
|
89
|
-
|
|
90
|
-
if (res.ok) {
|
|
91
|
-
return (await res.json());
|
|
92
|
-
}
|
|
95
|
+
return await fetchRegistryJson(`${process.env.GHOST_UI_REGISTRY_URL}/index.json`);
|
|
93
96
|
}
|
|
94
97
|
catch {
|
|
95
98
|
// Fallback to local
|
|
@@ -102,10 +105,7 @@ async function getRegistryIndex() {
|
|
|
102
105
|
}
|
|
103
106
|
// 2. Fallback to default remote registry
|
|
104
107
|
try {
|
|
105
|
-
|
|
106
|
-
if (res.ok) {
|
|
107
|
-
return (await res.json());
|
|
108
|
-
}
|
|
108
|
+
return await fetchRegistryJson(`${exports.DEFAULT_REGISTRY_URL}/index.json`);
|
|
109
109
|
}
|
|
110
110
|
catch {
|
|
111
111
|
// Network or abort error
|
|
@@ -117,10 +117,7 @@ async function getComponent(componentName) {
|
|
|
117
117
|
// If custom registry URL explicitly configured, try remote first
|
|
118
118
|
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
119
119
|
try {
|
|
120
|
-
|
|
121
|
-
if (res.ok) {
|
|
122
|
-
return (await res.json());
|
|
123
|
-
}
|
|
120
|
+
return await fetchRegistryJson(`${process.env.GHOST_UI_REGISTRY_URL}/components/${sanitized}.json`);
|
|
124
121
|
}
|
|
125
122
|
catch {
|
|
126
123
|
// Fallback to local
|
|
@@ -132,10 +129,7 @@ async function getComponent(componentName) {
|
|
|
132
129
|
return local;
|
|
133
130
|
// 2. Fallback to default remote registry
|
|
134
131
|
try {
|
|
135
|
-
|
|
136
|
-
if (res.ok) {
|
|
137
|
-
return (await res.json());
|
|
138
|
-
}
|
|
132
|
+
return await fetchRegistryJson(`${exports.DEFAULT_REGISTRY_URL}/components/${sanitized}.json`);
|
|
139
133
|
}
|
|
140
134
|
catch {
|
|
141
135
|
// Network or abort error
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentCss = componentCss;
|
|
4
|
+
exports.tailwindTheme = tailwindTheme;
|
|
5
|
+
/** Tailwind utilities must outrank portable component defaults, regardless of link order. */
|
|
6
|
+
function componentCss(content, style) {
|
|
7
|
+
return style === 'tailwind' ? `@layer theme, base, components, utilities;\n@layer components {\n${content}\n}\n` : content;
|
|
8
|
+
}
|
|
9
|
+
function tailwindTheme() {
|
|
10
|
+
const colors = ['background', 'foreground', 'card', 'card-foreground', 'popover', 'popover-foreground',
|
|
11
|
+
'primary', 'primary-foreground', 'secondary', 'secondary-foreground', 'muted', 'muted-foreground',
|
|
12
|
+
'accent', 'accent-foreground', 'destructive', 'destructive-foreground', 'border', 'input', 'ring'];
|
|
13
|
+
return `@theme inline {\n${colors.map(color => ` --color-${color}: var(--${color});`).join('\n')}\n --radius-ghostcn: var(--radius);\n}\n
|
|
14
|
+
@custom-variant dark {
|
|
15
|
+
&:where(.dark, .dark *, .dark-mode, .dark-mode *, [data-theme="dark"], [data-theme="dark"] *) { @slot; }
|
|
16
|
+
@media (prefers-color-scheme: dark) {
|
|
17
|
+
&:where(.auto-color, .auto-color *) { @slot; }
|
|
18
|
+
}
|
|
19
|
+
}\n`;
|
|
20
|
+
}
|
|
@@ -9,5 +9,7 @@ export interface StyleSyncResult {
|
|
|
9
9
|
assetPaths: string[];
|
|
10
10
|
}
|
|
11
11
|
export declare function resolveWithinTheme(themeRoot: string, relativePath: string): string;
|
|
12
|
+
export declare function safeThemePath(themeRoot: string, relative: string): string;
|
|
12
13
|
export declare function toGhostAssetPath(themeRelativePath: string): string;
|
|
14
|
+
export declare function syncGhostcnScripts(themeRoot: string, scriptsDir: string): StyleSyncResult;
|
|
13
15
|
export declare function syncGhostcnStyles(options: StyleSyncOptions): StyleSyncResult;
|
|
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveWithinTheme = resolveWithinTheme;
|
|
7
|
+
exports.safeThemePath = safeThemePath;
|
|
7
8
|
exports.toGhostAssetPath = toGhostAssetPath;
|
|
9
|
+
exports.syncGhostcnScripts = syncGhostcnScripts;
|
|
8
10
|
exports.syncGhostcnStyles = syncGhostcnStyles;
|
|
9
11
|
const fs_1 = __importDefault(require("fs"));
|
|
10
12
|
const path_1 = __importDefault(require("path"));
|
|
@@ -25,6 +27,17 @@ function resolveWithinTheme(themeRoot, relativePath) {
|
|
|
25
27
|
}
|
|
26
28
|
return target;
|
|
27
29
|
}
|
|
30
|
+
function safeThemePath(themeRoot, relative) {
|
|
31
|
+
const target = resolveWithinTheme(themeRoot, relative);
|
|
32
|
+
const root = path_1.default.resolve(themeRoot);
|
|
33
|
+
let current = target;
|
|
34
|
+
while (current !== root) {
|
|
35
|
+
if (fs_1.default.lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
36
|
+
throw new Error(`Symlinked theme path is not supported: ${relative}`);
|
|
37
|
+
current = path_1.default.dirname(current);
|
|
38
|
+
}
|
|
39
|
+
return target;
|
|
40
|
+
}
|
|
28
41
|
function toGhostAssetPath(themeRelativePath) {
|
|
29
42
|
const normalized = normalizeRelativePath(themeRelativePath);
|
|
30
43
|
if (!normalized.startsWith('assets/')) {
|
|
@@ -36,6 +49,31 @@ function toGhostAssetPath(themeRelativePath) {
|
|
|
36
49
|
}
|
|
37
50
|
return assetPath;
|
|
38
51
|
}
|
|
52
|
+
function syncGhostcnScripts(themeRoot, scriptsDir) {
|
|
53
|
+
const templatePath = safeThemePath(themeRoot, 'default.hbs');
|
|
54
|
+
const directory = safeThemePath(themeRoot, scriptsDir);
|
|
55
|
+
const assetPaths = fs_1.default.existsSync(directory) ? fs_1.default.readdirSync(directory, { withFileTypes: true })
|
|
56
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.js'))
|
|
57
|
+
.map(entry => toGhostAssetPath(path_1.default.relative(themeRoot, path_1.default.join(directory, entry.name))))
|
|
58
|
+
.sort() : [];
|
|
59
|
+
if (!fs_1.default.existsSync(templatePath))
|
|
60
|
+
return { status: 'missing-template', templatePath, assetPaths };
|
|
61
|
+
if (!assetPaths.length)
|
|
62
|
+
return { status: 'unchanged', templatePath, assetPaths };
|
|
63
|
+
const original = fs_1.default.readFileSync(templatePath, 'utf8');
|
|
64
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
65
|
+
const start = '{{!-- ghostcn:scripts:start --}}', end = '{{!-- ghostcn:scripts:end --}}';
|
|
66
|
+
const block = [start, ...assetPaths.map(asset => `<script defer src="{{asset "${asset}"}}"></script>`), end].join(newline);
|
|
67
|
+
let updated = original.replace(/\{\{!-- ghostcn:scripts:start --\}\}[\s\S]*?\{\{!-- ghostcn:scripts:end --\}\}/g, '');
|
|
68
|
+
// Preserve unrelated host scripts; deduplicate only these owned asset URLs.
|
|
69
|
+
updated = updated.replace(/<script\b[^>]*\bsrc=["'][^"']*\{\{asset\s+["']([^"']+)["']\}\}[^>]*>\s*<\/script>/gi, (tag, asset) => assetPaths.includes(asset) ? '' : tag);
|
|
70
|
+
if (!/<\/body\s*>/i.test(updated))
|
|
71
|
+
return { status: 'missing-template', templatePath, assetPaths };
|
|
72
|
+
updated = updated.replace(/[ \t]*(?:\r?\n)*[ \t]*<\/body\s*>/i, `${newline}${block}${newline}</body>`);
|
|
73
|
+
if (updated !== original)
|
|
74
|
+
fs_1.default.writeFileSync(templatePath, updated, 'utf8');
|
|
75
|
+
return { status: updated === original ? 'unchanged' : 'updated', templatePath, assetPaths };
|
|
76
|
+
}
|
|
39
77
|
function stylesheetBlock(assetPaths, newline) {
|
|
40
78
|
return [
|
|
41
79
|
STYLES_START,
|
|
@@ -59,9 +97,9 @@ function removeOwnedStylesheetLinks(template, assetPaths) {
|
|
|
59
97
|
});
|
|
60
98
|
}
|
|
61
99
|
function syncGhostcnStyles(options) {
|
|
62
|
-
const templatePath =
|
|
63
|
-
const cssPath =
|
|
64
|
-
const stylesDirPath =
|
|
100
|
+
const templatePath = safeThemePath(options.themeRoot, 'default.hbs');
|
|
101
|
+
const cssPath = safeThemePath(options.themeRoot, options.cssFile);
|
|
102
|
+
const stylesDirPath = safeThemePath(options.themeRoot, options.stylesDir);
|
|
65
103
|
const assetPaths = [toGhostAssetPath(options.cssFile)];
|
|
66
104
|
if (fs_1.default.existsSync(stylesDirPath)) {
|
|
67
105
|
const componentStyles = fs_1.default
|
|
@@ -84,8 +122,12 @@ function syncGhostcnStyles(options) {
|
|
|
84
122
|
const withoutManagedBlock = original.replace(managedBlockPattern, '');
|
|
85
123
|
const withoutOwnedLinks = removeOwnedStylesheetLinks(withoutManagedBlock, assetPaths);
|
|
86
124
|
const ghostHeadPattern = /^([ \t]*)\{\{ghost_head\}\}/m;
|
|
125
|
+
const overrideAnchor = /^([ \t]*)\{\{!-- ghostcn:theme-styles --\}\}/m;
|
|
87
126
|
let updated;
|
|
88
|
-
if (
|
|
127
|
+
if (overrideAnchor.test(withoutOwnedLinks)) {
|
|
128
|
+
updated = withoutOwnedLinks.replace(overrideAnchor, (match, indent) => `${indentBlock(block, indent, newline)}${newline}${match}`);
|
|
129
|
+
}
|
|
130
|
+
else if (ghostHeadPattern.test(withoutOwnedLinks)) {
|
|
89
131
|
updated = withoutOwnedLinks.replace(ghostHeadPattern, (_match, indent) => {
|
|
90
132
|
return `${indentBlock(block, indent, newline)}${newline}${indent}{{ghost_head}}`;
|
|
91
133
|
});
|