ghostcn 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -16
- package/dist/commands/add.js +42 -37
- package/dist/commands/create.d.ts +5 -0
- package/dist/commands/create.js +108 -0
- package/dist/commands/init.js +129 -26
- package/dist/commands/list.js +4 -4
- package/dist/index.js +9 -1
- package/dist/registry/components/author-card.json +2 -2
- package/dist/registry/components/featured-posts.json +27 -0
- package/dist/registry/components/member-cta.json +27 -0
- package/dist/registry/components/newsletter-form.json +9 -6
- package/dist/registry/components/pagination.json +28 -0
- package/dist/registry/components/post-card.json +2 -2
- package/dist/registry/components/post-header.json +27 -0
- package/dist/registry/components/pricing-table.json +2 -2
- package/dist/registry/components/site-footer.json +27 -0
- package/dist/registry/components/site-header.json +27 -0
- package/dist/registry/index.json +61 -1
- package/dist/utils/component-installer.d.ts +16 -0
- package/dist/utils/component-installer.js +59 -0
- package/dist/utils/registry.d.ts +1 -0
- package/dist/utils/registry.js +42 -19
- package/dist/utils/theme-files.d.ts +13 -0
- package/dist/utils/theme-files.js +104 -0
- package/dist/utils/theme-project.d.ts +29 -0
- package/dist/utils/theme-project.js +41 -0
- package/dist/utils/theme-scaffold.d.ts +21 -0
- package/dist/utils/theme-scaffold.js +288 -0
- package/dist/utils/theme.d.ts +46 -0
- package/dist/utils/theme.js +427 -0
- package/package.json +2 -1
- package/dist/test/registry.test.d.ts +0 -1
- package/dist/test/registry.test.js +0 -62
package/dist/utils/registry.js
CHANGED
|
@@ -83,39 +83,62 @@ function findLocalManifest(componentName) {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
async function getRegistryIndex() {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
// If custom registry URL explicitly configured, try remote first
|
|
87
|
+
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
88
|
+
try {
|
|
89
|
+
const res = await fetchWithTimeout(`${process.env.GHOST_UI_REGISTRY_URL}/index.json`);
|
|
90
|
+
if (res.ok) {
|
|
91
|
+
return (await res.json());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// Fallback to local
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 1. Try local bundled registry first (zero-latency, offline-first)
|
|
99
|
+
const localIndex = findLocalIndex();
|
|
100
|
+
if (localIndex && localIndex.length > 0) {
|
|
101
|
+
return localIndex;
|
|
102
|
+
}
|
|
103
|
+
// 2. Fallback to default remote registry
|
|
88
104
|
try {
|
|
89
|
-
const res = await fetchWithTimeout(`${
|
|
105
|
+
const res = await fetchWithTimeout(`${exports.DEFAULT_REGISTRY_URL}/index.json`);
|
|
90
106
|
if (res.ok) {
|
|
91
|
-
|
|
92
|
-
return data;
|
|
107
|
+
return (await res.json());
|
|
93
108
|
}
|
|
94
109
|
}
|
|
95
110
|
catch {
|
|
96
|
-
// Network or abort error
|
|
97
|
-
}
|
|
98
|
-
// 2. Fallback to local
|
|
99
|
-
const localIndex = findLocalIndex();
|
|
100
|
-
if (localIndex) {
|
|
101
|
-
return localIndex;
|
|
111
|
+
// Network or abort error
|
|
102
112
|
}
|
|
103
113
|
return [];
|
|
104
114
|
}
|
|
105
115
|
async function getComponent(componentName) {
|
|
106
116
|
const sanitized = sanitizeComponentName(componentName);
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
// If custom registry URL explicitly configured, try remote first
|
|
118
|
+
if (process.env.GHOST_UI_REGISTRY_URL) {
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetchWithTimeout(`${process.env.GHOST_UI_REGISTRY_URL}/components/${sanitized}.json`);
|
|
121
|
+
if (res.ok) {
|
|
122
|
+
return (await res.json());
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Fallback to local
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 1. Try local bundled registry first (zero-latency, offline-first)
|
|
130
|
+
const local = findLocalManifest(sanitized);
|
|
131
|
+
if (local)
|
|
132
|
+
return local;
|
|
133
|
+
// 2. Fallback to default remote registry
|
|
109
134
|
try {
|
|
110
|
-
const res = await fetchWithTimeout(`${
|
|
135
|
+
const res = await fetchWithTimeout(`${exports.DEFAULT_REGISTRY_URL}/components/${sanitized}.json`);
|
|
111
136
|
if (res.ok) {
|
|
112
|
-
|
|
113
|
-
return data;
|
|
137
|
+
return (await res.json());
|
|
114
138
|
}
|
|
115
139
|
}
|
|
116
140
|
catch {
|
|
117
|
-
// Network or abort error
|
|
141
|
+
// Network or abort error
|
|
118
142
|
}
|
|
119
|
-
|
|
120
|
-
return findLocalManifest(sanitized);
|
|
143
|
+
return null;
|
|
121
144
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StyleSyncOptions {
|
|
2
|
+
themeRoot: string;
|
|
3
|
+
cssFile: string;
|
|
4
|
+
stylesDir: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StyleSyncResult {
|
|
7
|
+
status: 'updated' | 'unchanged' | 'missing-template';
|
|
8
|
+
templatePath: string;
|
|
9
|
+
assetPaths: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveWithinTheme(themeRoot: string, relativePath: string): string;
|
|
12
|
+
export declare function toGhostAssetPath(themeRelativePath: string): string;
|
|
13
|
+
export declare function syncGhostcnStyles(options: StyleSyncOptions): StyleSyncResult;
|
|
@@ -0,0 +1,104 @@
|
|
|
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.resolveWithinTheme = resolveWithinTheme;
|
|
7
|
+
exports.toGhostAssetPath = toGhostAssetPath;
|
|
8
|
+
exports.syncGhostcnStyles = syncGhostcnStyles;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const STYLES_START = '{{!-- ghostcn:styles:start --}}';
|
|
12
|
+
const STYLES_END = '{{!-- ghostcn:styles:end --}}';
|
|
13
|
+
function normalizeRelativePath(relativePath) {
|
|
14
|
+
return relativePath.trim().replace(/\\/g, '/').replace(/^\.\//, '');
|
|
15
|
+
}
|
|
16
|
+
function resolveWithinTheme(themeRoot, relativePath) {
|
|
17
|
+
const normalized = normalizeRelativePath(relativePath);
|
|
18
|
+
if (!normalized || path_1.default.isAbsolute(normalized)) {
|
|
19
|
+
throw new Error(`Path must be relative to the Ghost theme: ${relativePath}`);
|
|
20
|
+
}
|
|
21
|
+
const root = path_1.default.resolve(themeRoot);
|
|
22
|
+
const target = path_1.default.resolve(root, normalized);
|
|
23
|
+
if (target === root || !target.startsWith(`${root}${path_1.default.sep}`)) {
|
|
24
|
+
throw new Error(`Path must stay inside the Ghost theme: ${relativePath}`);
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
function toGhostAssetPath(themeRelativePath) {
|
|
29
|
+
const normalized = normalizeRelativePath(themeRelativePath);
|
|
30
|
+
if (!normalized.startsWith('assets/')) {
|
|
31
|
+
throw new Error(`Stylesheets must be stored inside assets/: ${themeRelativePath}`);
|
|
32
|
+
}
|
|
33
|
+
const assetPath = normalized.slice('assets/'.length);
|
|
34
|
+
if (!assetPath) {
|
|
35
|
+
throw new Error(`Stylesheet path must include a file name: ${themeRelativePath}`);
|
|
36
|
+
}
|
|
37
|
+
return assetPath;
|
|
38
|
+
}
|
|
39
|
+
function stylesheetBlock(assetPaths, newline) {
|
|
40
|
+
return [
|
|
41
|
+
STYLES_START,
|
|
42
|
+
...assetPaths.map(assetPath => `<link rel="stylesheet" href="{{asset "${assetPath}"}}" />`),
|
|
43
|
+
STYLES_END
|
|
44
|
+
].join(newline);
|
|
45
|
+
}
|
|
46
|
+
function indentBlock(block, indent, newline) {
|
|
47
|
+
return block
|
|
48
|
+
.split(newline)
|
|
49
|
+
.map(line => `${indent}${line}`)
|
|
50
|
+
.join(newline);
|
|
51
|
+
}
|
|
52
|
+
function removeOwnedStylesheetLinks(template, assetPaths) {
|
|
53
|
+
const owned = new Set(assetPaths);
|
|
54
|
+
return template.replace(/^[ \t]*<link\b[^\r\n>]*>[ \t]*(?:\r?\n)?/gim, tag => {
|
|
55
|
+
if (!/rel=["']stylesheet["']/i.test(tag))
|
|
56
|
+
return tag;
|
|
57
|
+
const assetMatch = tag.match(/\{\{asset\s+["']([^"']+)["']\}\}/i);
|
|
58
|
+
return assetMatch && owned.has(assetMatch[1]) ? '' : tag;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function syncGhostcnStyles(options) {
|
|
62
|
+
const templatePath = resolveWithinTheme(options.themeRoot, 'default.hbs');
|
|
63
|
+
const cssPath = resolveWithinTheme(options.themeRoot, options.cssFile);
|
|
64
|
+
const stylesDirPath = resolveWithinTheme(options.themeRoot, options.stylesDir);
|
|
65
|
+
const assetPaths = [toGhostAssetPath(options.cssFile)];
|
|
66
|
+
if (fs_1.default.existsSync(stylesDirPath)) {
|
|
67
|
+
const componentStyles = fs_1.default
|
|
68
|
+
.readdirSync(stylesDirPath, { withFileTypes: true })
|
|
69
|
+
.filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.css'))
|
|
70
|
+
.map(entry => toGhostAssetPath(path_1.default.relative(options.themeRoot, path_1.default.join(stylesDirPath, entry.name))))
|
|
71
|
+
.sort((a, b) => a.localeCompare(b));
|
|
72
|
+
assetPaths.push(...componentStyles);
|
|
73
|
+
}
|
|
74
|
+
if (!fs_1.default.existsSync(templatePath)) {
|
|
75
|
+
return { status: 'missing-template', templatePath, assetPaths };
|
|
76
|
+
}
|
|
77
|
+
if (!fs_1.default.existsSync(cssPath)) {
|
|
78
|
+
throw new Error(`Theme tokens file does not exist: ${options.cssFile}`);
|
|
79
|
+
}
|
|
80
|
+
const original = fs_1.default.readFileSync(templatePath, 'utf8');
|
|
81
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
82
|
+
const block = stylesheetBlock(assetPaths, newline);
|
|
83
|
+
const managedBlockPattern = new RegExp(`^[ \\t]*${STYLES_START.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\s\\S]*?${STYLES_END.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[ \\t]*(?:\\r?\\n)?`, 'm');
|
|
84
|
+
const withoutManagedBlock = original.replace(managedBlockPattern, '');
|
|
85
|
+
const withoutOwnedLinks = removeOwnedStylesheetLinks(withoutManagedBlock, assetPaths);
|
|
86
|
+
const ghostHeadPattern = /^([ \t]*)\{\{ghost_head\}\}/m;
|
|
87
|
+
let updated;
|
|
88
|
+
if (ghostHeadPattern.test(withoutOwnedLinks)) {
|
|
89
|
+
updated = withoutOwnedLinks.replace(ghostHeadPattern, (_match, indent) => {
|
|
90
|
+
return `${indentBlock(block, indent, newline)}${newline}${indent}{{ghost_head}}`;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (/<\/head>/i.test(withoutOwnedLinks)) {
|
|
94
|
+
updated = withoutOwnedLinks.replace(/<\/head>/i, `${block}${newline}</head>`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return { status: 'missing-template', templatePath, assetPaths };
|
|
98
|
+
}
|
|
99
|
+
if (updated === original) {
|
|
100
|
+
return { status: 'unchanged', templatePath, assetPaths };
|
|
101
|
+
}
|
|
102
|
+
fs_1.default.writeFileSync(templatePath, updated, 'utf8');
|
|
103
|
+
return { status: 'updated', templatePath, assetPaths };
|
|
104
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ThemeConfig } from './theme';
|
|
2
|
+
import { StyleSyncResult } from './theme-files';
|
|
3
|
+
export interface GhostcnConfig {
|
|
4
|
+
$schema: string;
|
|
5
|
+
style: ThemeConfig['style'];
|
|
6
|
+
theme: Pick<ThemeConfig, 'baseColor' | 'accentColor' | 'radius'>;
|
|
7
|
+
aliases: {
|
|
8
|
+
partials: string;
|
|
9
|
+
styles: string;
|
|
10
|
+
js?: string;
|
|
11
|
+
};
|
|
12
|
+
cssFile: string;
|
|
13
|
+
}
|
|
14
|
+
export interface InitializeThemeOptions {
|
|
15
|
+
themeRoot: string;
|
|
16
|
+
config: GhostcnConfig;
|
|
17
|
+
}
|
|
18
|
+
export interface InitializeThemeResult {
|
|
19
|
+
configPath: string;
|
|
20
|
+
cssPath: string;
|
|
21
|
+
styleSync: StyleSyncResult;
|
|
22
|
+
}
|
|
23
|
+
export declare function buildGhostcnConfig(theme: ThemeConfig, paths?: {
|
|
24
|
+
partials?: string;
|
|
25
|
+
styles?: string;
|
|
26
|
+
js?: string;
|
|
27
|
+
cssFile?: string;
|
|
28
|
+
}): GhostcnConfig;
|
|
29
|
+
export declare function initializeThemeProject(options: InitializeThemeOptions): InitializeThemeResult;
|
|
@@ -0,0 +1,41 @@
|
|
|
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.buildGhostcnConfig = buildGhostcnConfig;
|
|
7
|
+
exports.initializeThemeProject = initializeThemeProject;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const theme_1 = require("./theme");
|
|
11
|
+
const theme_files_1 = require("./theme-files");
|
|
12
|
+
function buildGhostcnConfig(theme, paths = {}) {
|
|
13
|
+
return {
|
|
14
|
+
$schema: 'https://ghostcn.com/schema.json',
|
|
15
|
+
style: theme.style,
|
|
16
|
+
theme: {
|
|
17
|
+
baseColor: theme.baseColor,
|
|
18
|
+
accentColor: theme.accentColor,
|
|
19
|
+
radius: theme.radius
|
|
20
|
+
},
|
|
21
|
+
aliases: {
|
|
22
|
+
partials: paths.partials || 'partials/components',
|
|
23
|
+
styles: paths.styles || 'assets/css/components',
|
|
24
|
+
js: paths.js || 'assets/js/components'
|
|
25
|
+
},
|
|
26
|
+
cssFile: paths.cssFile || 'assets/css/ghostcn.css'
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function initializeThemeProject(options) {
|
|
30
|
+
const configPath = (0, theme_files_1.resolveWithinTheme)(options.themeRoot, 'components.json');
|
|
31
|
+
const cssPath = (0, theme_files_1.resolveWithinTheme)(options.themeRoot, options.config.cssFile);
|
|
32
|
+
fs_1.default.mkdirSync(path_1.default.dirname(cssPath), { recursive: true });
|
|
33
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify(options.config, null, 2) + '\n', 'utf8');
|
|
34
|
+
fs_1.default.writeFileSync(cssPath, (0, theme_1.generateThemeCss)({ style: options.config.style, ...options.config.theme }), 'utf8');
|
|
35
|
+
const styleSync = (0, theme_files_1.syncGhostcnStyles)({
|
|
36
|
+
themeRoot: options.themeRoot,
|
|
37
|
+
cssFile: options.config.cssFile,
|
|
38
|
+
stylesDir: options.config.aliases.styles
|
|
39
|
+
});
|
|
40
|
+
return { configPath, cssPath, styleSync };
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
2
|
+
export type ColorScheme = 'Light' | 'Dark' | 'Auto';
|
|
3
|
+
export interface ScaffoldThemeOptions {
|
|
4
|
+
parentDirectory: string;
|
|
5
|
+
themeName: string;
|
|
6
|
+
style: 'tailwind' | 'css';
|
|
7
|
+
colorScheme: ColorScheme;
|
|
8
|
+
packageManager: PackageManager;
|
|
9
|
+
authorName?: string;
|
|
10
|
+
authorEmail?: string;
|
|
11
|
+
includeNewsletter?: boolean;
|
|
12
|
+
includeAuthorCard?: boolean;
|
|
13
|
+
includePricing?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ScaffoldThemeResult {
|
|
16
|
+
themeRoot: string;
|
|
17
|
+
files: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const REQUIRED_STARTER_COMPONENTS: readonly ["site-header", "site-footer", "featured-posts", "pagination", "post-header", "member-cta", "post-card"];
|
|
20
|
+
export declare function sanitizeThemeName(value: string): string;
|
|
21
|
+
export declare function scaffoldTheme(options: ScaffoldThemeOptions): ScaffoldThemeResult;
|
|
@@ -0,0 +1,288 @@
|
|
|
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.REQUIRED_STARTER_COMPONENTS = void 0;
|
|
7
|
+
exports.sanitizeThemeName = sanitizeThemeName;
|
|
8
|
+
exports.scaffoldTheme = scaffoldTheme;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const theme_files_1 = require("./theme-files");
|
|
12
|
+
exports.REQUIRED_STARTER_COMPONENTS = [
|
|
13
|
+
'site-header',
|
|
14
|
+
'site-footer',
|
|
15
|
+
'featured-posts',
|
|
16
|
+
'pagination',
|
|
17
|
+
'post-header',
|
|
18
|
+
'member-cta',
|
|
19
|
+
'post-card'
|
|
20
|
+
];
|
|
21
|
+
function sanitizeThemeName(value) {
|
|
22
|
+
const name = value.trim().toLowerCase();
|
|
23
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name) || name.endsWith('-') || name.includes('--')) {
|
|
24
|
+
throw new Error('Theme names must use lowercase letters, numbers, and single hyphens (for example: my-theme).');
|
|
25
|
+
}
|
|
26
|
+
return name;
|
|
27
|
+
}
|
|
28
|
+
function baseThemeCss() {
|
|
29
|
+
return `/* Theme-level styles. ghostcn components keep their own portable stylesheets. */
|
|
30
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
31
|
+
html { font-size: 100%; }
|
|
32
|
+
body {
|
|
33
|
+
min-height: 100vh;
|
|
34
|
+
margin: 0;
|
|
35
|
+
color: var(--foreground, #09090b);
|
|
36
|
+
background: var(--background, #fff);
|
|
37
|
+
font-family: var(--gh-font-body, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
|
|
38
|
+
font-size: 1rem;
|
|
39
|
+
line-height: 1.6;
|
|
40
|
+
-webkit-font-smoothing: antialiased;
|
|
41
|
+
}
|
|
42
|
+
img { max-width: 100%; }
|
|
43
|
+
h1, h2, h3, h4, h5, h6 { font-family: var(--gh-font-heading, inherit); }
|
|
44
|
+
.ghcn-main { min-height: 65vh; }
|
|
45
|
+
.ghcn-page-heading { width: min(100% - 2rem, 72rem); margin: 4rem auto 2rem; }
|
|
46
|
+
.ghcn-page-heading h1 { margin: 0; font-size: clamp(2.25rem, 6vw, 4rem); line-height: 1; letter-spacing: -0.05em; }
|
|
47
|
+
.ghcn-page-heading p { max-width: 42rem; margin: 1rem 0 0; color: var(--muted-foreground); font-size: 1.125rem; }
|
|
48
|
+
.ghcn-post-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; width: min(100% - 2rem, 72rem); margin: 2rem auto 4rem; }
|
|
49
|
+
.ghcn-article { width: min(100% - 2rem, 46rem); margin: 0 auto 4rem; }
|
|
50
|
+
.ghcn-article-content { color: var(--foreground); font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: clamp(1.0625rem, 2vw, 1.1875rem); }
|
|
51
|
+
.ghcn-article-content > * { margin-block: 0 1.5em; }
|
|
52
|
+
.ghcn-article-content h2, .ghcn-article-content h3 { margin-top: 2em; line-height: 1.15; letter-spacing: -0.025em; }
|
|
53
|
+
.ghcn-article-content a { color: var(--primary); }
|
|
54
|
+
.ghcn-article-content img, .ghcn-article-content .kg-card { max-width: 100%; }
|
|
55
|
+
.ghcn-article-content .kg-width-wide { width: min(72rem, 100vw - 2rem); max-width: none; margin-left: 50%; transform: translateX(-50%); }
|
|
56
|
+
.ghcn-article-content .kg-width-full { width: 100vw; max-width: none; margin-left: 50%; transform: translateX(-50%); }
|
|
57
|
+
.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; }
|
|
58
|
+
@media (max-width: 900px) { .ghcn-post-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
|
|
59
|
+
@media (max-width: 620px) { .ghcn-post-grid { grid-template-columns: 1fr; } }
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
62
|
+
function defaultTemplate(_colorScheme) {
|
|
63
|
+
return `<!DOCTYPE html>
|
|
64
|
+
<html lang="{{@site.locale}}"{{#match @custom.color_scheme "Dark"}} class="dark-mode"{{else match @custom.color_scheme "Auto"}} class="auto-color"{{/match}}>
|
|
65
|
+
<head>
|
|
66
|
+
<meta charset="utf-8" />
|
|
67
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
68
|
+
<title>{{meta_title}}</title>
|
|
69
|
+
<link rel="stylesheet" href="{{asset "built/screen.css"}}" />
|
|
70
|
+
{{ghost_head}}
|
|
71
|
+
</head>
|
|
72
|
+
<body class="{{body_class}}">
|
|
73
|
+
{{> "components/site-header"}}
|
|
74
|
+
<main class="ghcn-main">{{{body}}}</main>
|
|
75
|
+
{{> "components/site-footer"}}
|
|
76
|
+
{{ghost_foot}}
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
function indexTemplate(options) {
|
|
82
|
+
const extras = [
|
|
83
|
+
options.includeNewsletter ? '{{> "components/newsletter-form" title="Never miss a story"}}' : '',
|
|
84
|
+
options.includePricing ? '{{> "components/pricing-table" title="Support this publication"}}' : ''
|
|
85
|
+
].filter(Boolean).join('\n\n');
|
|
86
|
+
return `{{!< default}}
|
|
87
|
+
|
|
88
|
+
{{#is "home"}}{{> "components/featured-posts"}}{{/is}}
|
|
89
|
+
|
|
90
|
+
<header class="ghcn-page-heading">
|
|
91
|
+
<h1>{{@site.title}}</h1>
|
|
92
|
+
{{#if @site.description}}<p>{{@site.description}}</p>{{/if}}
|
|
93
|
+
</header>
|
|
94
|
+
|
|
95
|
+
{{#if posts}}
|
|
96
|
+
<section class="ghcn-post-grid" aria-label="Latest posts">
|
|
97
|
+
{{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
|
|
98
|
+
</section>
|
|
99
|
+
{{else}}
|
|
100
|
+
<div class="ghcn-empty">Publish your first post in Ghost Admin to see it here.</div>
|
|
101
|
+
{{/if}}
|
|
102
|
+
|
|
103
|
+
{{pagination}}
|
|
104
|
+
${extras ? `\n${extras}\n` : ''}`;
|
|
105
|
+
}
|
|
106
|
+
function postTemplate(options) {
|
|
107
|
+
const author = options.includeAuthorCard
|
|
108
|
+
? '\n {{#primary_author}}{{> "components/author-card"}}{{/primary_author}}\n'
|
|
109
|
+
: '';
|
|
110
|
+
return `{{!< default}}
|
|
111
|
+
|
|
112
|
+
{{#post}}
|
|
113
|
+
{{> "components/post-header"}}
|
|
114
|
+
<article class="ghcn-article {{post_class}}">
|
|
115
|
+
<div class="ghcn-article-content">{{content}}</div>
|
|
116
|
+
</article>
|
|
117
|
+
{{> "components/member-cta"}}
|
|
118
|
+
${author} {{comments}}
|
|
119
|
+
{{/post}}
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
function pageTemplate() {
|
|
123
|
+
return `{{!< default}}
|
|
124
|
+
|
|
125
|
+
{{#post}}
|
|
126
|
+
{{#match @page.show_title_and_feature_image}}
|
|
127
|
+
{{> "components/post-header"}}
|
|
128
|
+
{{/match}}
|
|
129
|
+
<article class="ghcn-article {{post_class}}">
|
|
130
|
+
<div class="ghcn-article-content">{{content}}</div>
|
|
131
|
+
</article>
|
|
132
|
+
{{/post}}
|
|
133
|
+
`;
|
|
134
|
+
}
|
|
135
|
+
function archiveTemplate(kind) {
|
|
136
|
+
const header = kind === 'tag'
|
|
137
|
+
? `{{#tag}}<header class="ghcn-page-heading"><h1>{{name}}</h1>{{#if description}}<p>{{description}}</p>{{/if}}</header>{{/tag}}`
|
|
138
|
+
: `{{#author}}<header class="ghcn-page-heading"><h1>{{name}}</h1>{{#if bio}}<p>{{bio}}</p>{{/if}}</header>{{/author}}`;
|
|
139
|
+
return `{{!< default}}
|
|
140
|
+
|
|
141
|
+
${header}
|
|
142
|
+
<section class="ghcn-post-grid" aria-label="Posts">
|
|
143
|
+
{{#foreach posts}}{{> "components/post-card"}}{{/foreach}}
|
|
144
|
+
</section>
|
|
145
|
+
{{pagination}}
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
function packageJson(options) {
|
|
149
|
+
const gscanCommand = {
|
|
150
|
+
npm: 'npx --yes gscan@6.4.2 .',
|
|
151
|
+
pnpm: 'pnpm dlx gscan@6.4.2 .',
|
|
152
|
+
yarn: 'yarn dlx gscan@6.4.2 .',
|
|
153
|
+
bun: 'bunx gscan@6.4.2 .'
|
|
154
|
+
};
|
|
155
|
+
const scripts = options.style === 'tailwind'
|
|
156
|
+
? {
|
|
157
|
+
dev: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --watch',
|
|
158
|
+
build: 'tailwindcss -i ./assets/css/source.css -o ./assets/built/screen.css --minify',
|
|
159
|
+
test: 'node ./scripts/check.mjs',
|
|
160
|
+
validate: gscanCommand[options.packageManager]
|
|
161
|
+
}
|
|
162
|
+
: {
|
|
163
|
+
dev: 'node ./scripts/dev.mjs',
|
|
164
|
+
build: 'node ./scripts/build.mjs',
|
|
165
|
+
test: 'node ./scripts/check.mjs',
|
|
166
|
+
validate: gscanCommand[options.packageManager]
|
|
167
|
+
};
|
|
168
|
+
const devDependencies = {};
|
|
169
|
+
if (options.style === 'tailwind') {
|
|
170
|
+
devDependencies.tailwindcss = '^4.1.0';
|
|
171
|
+
devDependencies['@tailwindcss/cli'] = '^4.1.0';
|
|
172
|
+
}
|
|
173
|
+
return JSON.stringify({
|
|
174
|
+
name: options.themeName,
|
|
175
|
+
description: `A Ghost theme created with ghostcn`,
|
|
176
|
+
version: '1.0.0',
|
|
177
|
+
private: true,
|
|
178
|
+
author: {
|
|
179
|
+
name: options.authorName || 'Theme Author',
|
|
180
|
+
email: options.authorEmail || 'hello@example.com'
|
|
181
|
+
},
|
|
182
|
+
engines: { ghost: '>=5.0.0' },
|
|
183
|
+
license: 'MIT',
|
|
184
|
+
keywords: ['ghost-theme', 'ghost', 'ghostcn'],
|
|
185
|
+
scripts,
|
|
186
|
+
devDependencies,
|
|
187
|
+
config: {
|
|
188
|
+
posts_per_page: 9,
|
|
189
|
+
card_assets: true,
|
|
190
|
+
image_sizes: { xs: { width: 160 }, s: { width: 400 }, m: { width: 750 }, l: { width: 1200 }, xl: { width: 2000 } },
|
|
191
|
+
custom: {
|
|
192
|
+
color_scheme: { type: 'select', options: ['Light', 'Dark', 'Auto'], default: options.colorScheme }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, null, 2) + '\n';
|
|
196
|
+
}
|
|
197
|
+
function readme(options) {
|
|
198
|
+
const run = options.packageManager === 'npm' ? 'npm run' : `${options.packageManager} run`;
|
|
199
|
+
return `# ${options.themeName}
|
|
200
|
+
|
|
201
|
+
A Ghost theme generated by [ghostcn](https://www.npmjs.com/package/ghostcn).
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
\`\`\`bash
|
|
206
|
+
${options.packageManager} install
|
|
207
|
+
${run} dev
|
|
208
|
+
\`\`\`
|
|
209
|
+
|
|
210
|
+
Use \`${run} build\` for a production stylesheet, \`${run} test\` for offline scaffold checks, and \`${run} validate\` for official gscan validation (downloads the pinned validator on demand).
|
|
211
|
+
|
|
212
|
+
Components are copied into \`partials/components\` and \`assets/css/components\`, so you own and can customize every file. Put durable overrides in \`assets/css/source.css\`.
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
const vanillaBuildScript = `import { copyFileSync, mkdirSync } from 'node:fs';
|
|
216
|
+
mkdirSync(new URL('../assets/built/', import.meta.url), { recursive: true });
|
|
217
|
+
copyFileSync(new URL('../assets/css/source.css', import.meta.url), new URL('../assets/built/screen.css', import.meta.url));
|
|
218
|
+
console.log('Built assets/built/screen.css');
|
|
219
|
+
`;
|
|
220
|
+
const vanillaDevScript = `import { watch } from 'node:fs';
|
|
221
|
+
import './build.mjs';
|
|
222
|
+
const source = new URL('../assets/css/source.css', import.meta.url);
|
|
223
|
+
let timer;
|
|
224
|
+
console.log('Watching assets/css/source.css — press Ctrl+C to stop.');
|
|
225
|
+
watch(source, () => {
|
|
226
|
+
clearTimeout(timer);
|
|
227
|
+
timer = setTimeout(() => import('./build.mjs?' + Date.now()), 50);
|
|
228
|
+
});
|
|
229
|
+
`;
|
|
230
|
+
const checkScript = `import { existsSync, readFileSync } from 'node:fs';
|
|
231
|
+
const required = ['package.json', 'default.hbs', 'index.hbs', 'post.hbs', 'page.hbs', 'assets/css/ghostcn.css', 'assets/built/screen.css'];
|
|
232
|
+
const missing = required.filter(file => !existsSync(new URL('../' + file, import.meta.url)));
|
|
233
|
+
if (missing.length) {
|
|
234
|
+
console.error('Missing required theme files:', missing.join(', '));
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
const layout = readFileSync(new URL('../default.hbs', import.meta.url), 'utf8');
|
|
238
|
+
if (!layout.includes('{{ghost_head}}') || !layout.includes('{{ghost_foot}}')) {
|
|
239
|
+
console.error('default.hbs must include {{ghost_head}} and {{ghost_foot}}.');
|
|
240
|
+
process.exit(1);
|
|
241
|
+
}
|
|
242
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
243
|
+
if (!pkg.engines?.ghost || !pkg.author?.email) {
|
|
244
|
+
console.error('package.json must define engines.ghost and author.email.');
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
console.log('Theme scaffold checks passed.');
|
|
248
|
+
`;
|
|
249
|
+
function scaffoldTheme(options) {
|
|
250
|
+
const themeName = sanitizeThemeName(options.themeName);
|
|
251
|
+
const parent = path_1.default.resolve(options.parentDirectory);
|
|
252
|
+
const themeRoot = path_1.default.resolve(parent, themeName);
|
|
253
|
+
if (themeRoot === parent || !themeRoot.startsWith(`${parent}${path_1.default.sep}`)) {
|
|
254
|
+
throw new Error('The generated theme must stay inside the selected parent directory.');
|
|
255
|
+
}
|
|
256
|
+
if (fs_1.default.existsSync(themeRoot) && fs_1.default.readdirSync(themeRoot).length > 0) {
|
|
257
|
+
throw new Error(`Cannot create "${themeName}" because that directory is not empty.`);
|
|
258
|
+
}
|
|
259
|
+
fs_1.default.mkdirSync(themeRoot, { recursive: true });
|
|
260
|
+
const css = baseThemeCss();
|
|
261
|
+
const sourceCss = options.style === 'tailwind'
|
|
262
|
+
? `@import "tailwindcss";\n@source "../../**/*.hbs";\n\n${css}`
|
|
263
|
+
: css;
|
|
264
|
+
const files = {
|
|
265
|
+
'package.json': packageJson({ ...options, themeName }),
|
|
266
|
+
'default.hbs': defaultTemplate(options.colorScheme),
|
|
267
|
+
'index.hbs': indexTemplate(options),
|
|
268
|
+
'post.hbs': postTemplate(options),
|
|
269
|
+
'page.hbs': pageTemplate(),
|
|
270
|
+
'tag.hbs': archiveTemplate('tag'),
|
|
271
|
+
'author.hbs': archiveTemplate('author'),
|
|
272
|
+
'assets/css/source.css': sourceCss,
|
|
273
|
+
'assets/built/screen.css': css,
|
|
274
|
+
'scripts/check.mjs': checkScript,
|
|
275
|
+
'.gitignore': 'node_modules\n*.zip\n.DS_Store\n',
|
|
276
|
+
'README.md': readme(options)
|
|
277
|
+
};
|
|
278
|
+
if (options.style === 'css') {
|
|
279
|
+
files['scripts/build.mjs'] = vanillaBuildScript;
|
|
280
|
+
files['scripts/dev.mjs'] = vanillaDevScript;
|
|
281
|
+
}
|
|
282
|
+
for (const [relativePath, content] of Object.entries(files)) {
|
|
283
|
+
const target = (0, theme_files_1.resolveWithinTheme)(themeRoot, relativePath);
|
|
284
|
+
fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
|
|
285
|
+
fs_1.default.writeFileSync(target, content, 'utf8');
|
|
286
|
+
}
|
|
287
|
+
return { themeRoot, files: Object.keys(files) };
|
|
288
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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';
|
|
4
|
+
export interface ThemeConfig {
|
|
5
|
+
style: 'tailwind' | 'css';
|
|
6
|
+
baseColor: BaseColor;
|
|
7
|
+
accentColor: AccentColor;
|
|
8
|
+
radius: Radius;
|
|
9
|
+
}
|
|
10
|
+
interface ColorTokens {
|
|
11
|
+
background: string;
|
|
12
|
+
foreground: string;
|
|
13
|
+
card: string;
|
|
14
|
+
cardForeground: string;
|
|
15
|
+
popover: string;
|
|
16
|
+
popoverForeground: string;
|
|
17
|
+
secondary: string;
|
|
18
|
+
secondaryForeground: string;
|
|
19
|
+
muted: string;
|
|
20
|
+
mutedForeground: string;
|
|
21
|
+
accent: string;
|
|
22
|
+
accentForeground: string;
|
|
23
|
+
destructive: string;
|
|
24
|
+
destructiveForeground: string;
|
|
25
|
+
border: string;
|
|
26
|
+
input: string;
|
|
27
|
+
ring: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const BASE_PALETTES: Record<BaseColor, {
|
|
30
|
+
light: ColorTokens;
|
|
31
|
+
dark: ColorTokens;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const ACCENT_COLORS: Record<AccentColor, {
|
|
34
|
+
light: {
|
|
35
|
+
primary: string;
|
|
36
|
+
primaryForeground: string;
|
|
37
|
+
ring?: string;
|
|
38
|
+
};
|
|
39
|
+
dark: {
|
|
40
|
+
primary: string;
|
|
41
|
+
primaryForeground: string;
|
|
42
|
+
ring?: string;
|
|
43
|
+
};
|
|
44
|
+
}>;
|
|
45
|
+
export declare function generateThemeCss(config: ThemeConfig): string;
|
|
46
|
+
export {};
|