ghostcn 1.2.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 +182 -1
- package/dist/commands/add.d.ts +6 -1
- package/dist/commands/add.js +121 -83
- package/dist/commands/diff.d.ts +5 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/playground.d.ts +3 -0
- package/dist/commands/playground.js +29 -0
- package/dist/index.js +16 -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 +31 -2
- 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 +16 -1
- 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 +1 -1
- 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 -37
- 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/theme-files.d.ts +2 -0
- package/dist/utils/theme-files.js +41 -3
- package/dist/utils/theme-scaffold.js +12 -0
- package/package.json +2 -2
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
|
|
@@ -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
|
|
@@ -238,6 +238,18 @@ You own the files in \`partials/components\` and \`assets/css/components\`. ${op
|
|
|
238
238
|
? 'Add normal Tailwind classes to the markup, for example `ghcn-button bg-purple-600 hover:bg-purple-700 text-white`. No important modifier is needed for ghostcn defaults. Semantic utilities such as `bg-primary` and `border-border` are configured in `assets/css/ghostcn-tailwind.css`. Put additional CSS in `assets/css/source.css`.'
|
|
239
239
|
: 'Edit the component CSS directly, or put token and selector overrides in `assets/css/source.css`. The built stylesheet loads after ghostcn, so equal-specificity overrides win.'}
|
|
240
240
|
|
|
241
|
+
Prefer per-instance styling parameters over modifying the shared partial:
|
|
242
|
+
|
|
243
|
+
\`\`\`handlebars
|
|
244
|
+
{{> "components/pricing-table"
|
|
245
|
+
class="${options.style === 'tailwind' ? 'mx-auto my-12 w-full max-w-md' : 'membership'}"
|
|
246
|
+
cardClass="${options.style === 'tailwind' ? 'rounded-2xl bg-card p-8 shadow-lg' : 'membership-card'}"
|
|
247
|
+
buttonClass="${options.style === 'tailwind' ? 'bg-purple-600 hover:bg-purple-700 text-white' : 'membership-button'}"
|
|
248
|
+
}}
|
|
249
|
+
\`\`\`
|
|
250
|
+
|
|
251
|
+
Every component accepts \`class\` for its root; named slots (such as \`buttonClass\`, \`titleClass\` and \`inputClass\`) apply to the corresponding internal elements when present. Available slots are listed in the installed partial's opening comment and in the ghostcn documentation. Pricing also accepts \`titleClass\` and \`gridClass\`. ${options.style === 'tailwind' ? 'Keep classes as complete literal strings in scanned .hbs files and keep the dev watcher running.' : 'Define your custom class selectors in assets/css/source.css, matching default specificity where needed.'} Re-adding a component can overwrite its partial/CSS but does not overwrite styling kept in calling templates or source.css. These parameters do not style Ghost-owned Portal, search or comments UI.
|
|
252
|
+
|
|
241
253
|
Membership UI follows Ghost's enabled/invite-only/paid settings. Pricing comes from public tiers configured in Ghost Admin; payments must be configured before paid plans appear. The custom \`partials/content-cta.hbs\` renders one paywall for protected posts without exposing restricted content.
|
|
242
254
|
|
|
243
255
|
## Package for upload
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ghostcn",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "The shadcn/ui for Ghost CMS themes - component distribution system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/Geekbits-Org/ghost-ui#readme",
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"handlebars": "^4.7.9",
|
|
45
46
|
"chalk": "^4.1.2",
|
|
46
47
|
"commander": "^12.0.0",
|
|
47
48
|
"ora": "^5.4.1",
|
|
@@ -51,7 +52,6 @@
|
|
|
51
52
|
"@tailwindcss/cli": "^4.3.3",
|
|
52
53
|
"@types/node": "^20.11.24",
|
|
53
54
|
"@types/prompts": "^2.4.9",
|
|
54
|
-
"handlebars": "^4.7.9",
|
|
55
55
|
"ts-node": "^10.9.2",
|
|
56
56
|
"typescript": "^5.3.3"
|
|
57
57
|
}
|