astro-blog-kit 0.3.4 → 0.3.6

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.
Files changed (2) hide show
  1. package/integration.ts +60 -106
  2. package/package.json +1 -1
package/integration.ts CHANGED
@@ -6,138 +6,98 @@ import type { AstroIntegration } from "astro";
6
6
  import type { Plugin } from "vite";
7
7
  import type { BlogKitConfig, BlogTheme } from "./types";
8
8
 
9
- const VIRTUAL_MODULE_ID = "virtual:astro-blog-kit/theme";
10
- const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
11
-
12
9
  /**
13
10
  * Genera el bloque de CSS variables a partir del tema.
14
11
  */
15
12
  function generateThemeCSS(theme: BlogTheme = {}): string {
16
13
  const t = {
17
- accent: theme.accent ?? "#facc15",
18
- background: theme.background ?? "#ffffff",
19
- surface: theme.surface ?? "#f8f8f8",
20
- text: theme.text ?? "#0a0a0a",
21
- muted: theme.muted ?? "#6b7280",
22
- mutedLight: theme.mutedLight ?? "#9ca3af",
23
- border: theme.border ?? "#e5e7eb",
24
- black: theme.black ?? "#0a0a0a",
25
- white: theme.white ?? "#ffffff",
26
- fontHeading: theme.fontHeading ?? "Georgia, serif",
27
- fontBody: theme.fontBody ?? "system-ui, sans-serif",
28
- fontMono: theme.fontMono ?? "monospace",
29
- fontDisplay: theme.fontDisplay ?? "Georgia, serif",
14
+ accent: theme.accent ?? "#facc15",
15
+ background: theme.background ?? "#ffffff",
16
+ surface: theme.surface ?? "#f8f8f8",
17
+ text: theme.text ?? "#0a0a0a",
18
+ muted: theme.muted ?? "#6b7280",
19
+ mutedLight: theme.mutedLight ?? "#9ca3af",
20
+ border: theme.border ?? "#e5e7eb",
21
+ black: theme.black ?? "#0a0a0a",
22
+ white: theme.white ?? "#ffffff",
23
+ fontHeading: theme.fontHeading ?? "Georgia, serif",
24
+ fontBody: theme.fontBody ?? "system-ui, sans-serif",
25
+ fontMono: theme.fontMono ?? "monospace",
26
+ fontDisplay: theme.fontDisplay ?? "Georgia, serif",
30
27
  containerMax: theme.containerMax ?? "1200px",
31
28
  };
32
29
 
33
- return `
34
- :root {
35
- --bk-accent: ${t.accent};
36
- --bk-background: ${t.background};
37
- --bk-surface: ${t.surface};
38
- --bk-text: ${t.text};
39
- --bk-muted: ${t.muted};
40
- --bk-muted-light: ${t.mutedLight};
41
- --bk-border: ${t.border};
42
- --bk-black: ${t.black};
43
- --bk-white: ${t.white};
44
- --bk-yellow: ${t.accent};
45
- --bk-gray-100: #f3f4f6;
46
- --bk-gray-200: #e5e7eb;
47
- --bk-gray-300: #d1d5db;
48
- --bk-gray-400: #9ca3af;
49
- --bk-gray-600: #4b5563;
50
- --bk-font-heading: ${t.fontHeading};
51
- --bk-font-body: ${t.fontBody};
52
- --bk-font-mono: ${t.fontMono};
53
- --bk-font-display: ${t.fontDisplay};
54
- --bk-container-max: ${t.containerMax};
55
- --bk-transition: all 0.2s ease;
56
- }
57
-
58
- *, *::before, *::after {
59
- box-sizing: border-box;
60
- margin: 0;
61
- padding: 0;
62
- }
63
- `.trim();
30
+ return [
31
+ ":root {",
32
+ ` --bk-accent: ${t.accent};`,
33
+ ` --bk-background: ${t.background};`,
34
+ ` --bk-surface: ${t.surface};`,
35
+ ` --bk-text: ${t.text};`,
36
+ ` --bk-muted: ${t.muted};`,
37
+ ` --bk-muted-light: ${t.mutedLight};`,
38
+ ` --bk-border: ${t.border};`,
39
+ ` --bk-black: ${t.black};`,
40
+ ` --bk-white: ${t.white};`,
41
+ ` --bk-yellow: ${t.accent};`,
42
+ ` --bk-gray-100: #f3f4f6;`,
43
+ ` --bk-gray-200: #e5e7eb;`,
44
+ ` --bk-gray-300: #d1d5db;`,
45
+ ` --bk-gray-400: #9ca3af;`,
46
+ ` --bk-gray-600: #4b5563;`,
47
+ ` --bk-font-heading: ${t.fontHeading};`,
48
+ ` --bk-font-body: ${t.fontBody};`,
49
+ ` --bk-font-mono: ${t.fontMono};`,
50
+ ` --bk-font-display: ${t.fontDisplay};`,
51
+ ` --bk-container-max: ${t.containerMax};`,
52
+ ` --bk-transition: all 0.2s ease;`,
53
+ "}",
54
+ ].join("\n");
64
55
  }
65
56
 
66
57
  /**
67
- * Plugin de Vite que expone el tema como un virtual module CSS.
68
- * Esto permite que Astro procese el CSS en SSR correctamente,
69
- * sin depender de JavaScript en el cliente para inyectar variables.
70
- *
71
- * Uso en cualquier componente .astro del paquete:
72
- * import 'virtual:astro-blog-kit/theme';
58
+ * Plugin de Vite que inyecta el CSS del tema como módulo CSS real,
59
+ * compatible con Rolldown (Astro 7+).
73
60
  */
74
61
  function createThemePlugin(theme: BlogTheme): Plugin {
62
+ const THEME_ID = "\0astro-blog-kit-theme.css";
75
63
  const css = generateThemeCSS(theme);
76
64
 
77
65
  return {
78
66
  name: "astro-blog-kit:theme",
67
+ enforce: "pre",
68
+
79
69
  resolveId(id) {
80
- if (id === VIRTUAL_MODULE_ID) {
81
- return RESOLVED_VIRTUAL_MODULE_ID;
70
+ if (id === "astro-blog-kit-theme.css") {
71
+ return THEME_ID;
82
72
  }
83
73
  },
74
+
84
75
  load(id) {
85
- if (id === RESOLVED_VIRTUAL_MODULE_ID) {
86
- // Retornamos CSS puro — Vite lo procesa como módulo CSS
76
+ if (id === THEME_ID) {
87
77
  return css;
88
78
  }
89
79
  },
90
- // Fuerza el tipo del módulo como CSS para que Vite lo trate correctamente
91
- // transform(code, id) {
92
- // if (id === RESOLVED_VIRTUAL_MODULE_ID) {
93
- // return {
94
- // code: `
95
- // const style = document.createElement('style');
96
- // style.id = 'astro-blog-kit-theme';
97
- // style.textContent = ${JSON.stringify(css)};
98
- // if (!document.getElementById('astro-blog-kit-theme')) {
99
- // document.head.appendChild(style);
100
- // }
101
- // `.trim(),
102
- // map: null,
103
- // };
104
- // }
105
- // },
80
+
81
+ transform(code, id) {
82
+ if (id === THEME_ID) {
83
+ return { code, map: null, meta: { vite: { lang: "css" } } };
84
+ }
85
+ },
106
86
  };
107
87
  }
108
88
 
109
89
  /**
110
90
  * Integración principal de astro-blog-kit.
111
- *
112
- * @example
113
- * ```js
114
- * // astro.config.mjs
115
- * import { defineConfig } from 'astro/config';
116
- * import { blogKit } from 'astro-blog-kit/integration';
117
- *
118
- * export default defineConfig({
119
- * integrations: [
120
- * blogKit({
121
- * postsPerPage: 6,
122
- * defaultLayout: 'featured',
123
- * theme: {
124
- * accent: '#facc15',
125
- * fontHeading: 'Inter, sans-serif',
126
- * },
127
- * }),
128
- * ],
129
- * });
130
- * ```
131
91
  */
132
92
  export function blogKit(config: BlogKitConfig = {}): AstroIntegration {
133
93
  const resolvedConfig: Required<BlogKitConfig> = {
134
- postsPerPage: config.postsPerPage ?? 5,
135
- defaultLayout: config.defaultLayout ?? "magazine",
94
+ postsPerPage: config.postsPerPage ?? 5,
95
+ defaultLayout: config.defaultLayout ?? "magazine",
136
96
  collectionName: config.collectionName ?? "blog",
137
- i18n: config.i18n ?? { locales: [], defaultLocale: "en" },
138
- theme: config.theme ?? {},
139
- hero: config.hero ?? {}, // ← agregar
140
- ui: config.ui ?? {},
97
+ i18n: config.i18n ?? { locales: [], defaultLocale: "en" },
98
+ theme: config.theme ?? {},
99
+ hero: config.hero ?? {},
100
+ ui: config.ui ?? {},
141
101
  };
142
102
 
143
103
  return {
@@ -149,20 +109,14 @@ export function blogKit(config: BlogKitConfig = {}): AstroIntegration {
149
109
  `astro-blog-kit initialized — layout: ${resolvedConfig.defaultLayout}, postsPerPage: ${resolvedConfig.postsPerPage}`
150
110
  );
151
111
 
152
- // Registra el virtual module como plugin de Vite
153
- // Esto garantiza que las CSS variables existen en SSR y en el build estático
154
112
  updateConfig({
155
113
  vite: {
156
114
  plugins: [createThemePlugin(resolvedConfig.theme)],
157
115
  },
158
116
  });
159
117
 
160
- // Inyecta el virtual module en cada página como CSS real
161
- // "page-ssr" = se ejecuta en el servidor, garantiza que el style
162
- // esté disponible antes del primer paint
163
- injectScript("page-ssr", `import "${VIRTUAL_MODULE_ID}";`);
118
+ injectScript("page-ssr", `import "astro-blog-kit-theme.css";`);
164
119
 
165
- // Inyecta config global accesible desde cualquier componente
166
120
  injectScript(
167
121
  "page-ssr",
168
122
  `globalThis.__BLOG_KIT_CONFIG__ = ${JSON.stringify(resolvedConfig)};`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-blog-kit",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "A ready-to-use blog system for Astro with WordPress headless support, optional i18n, multiple layouts, and a comment system.",
5
5
  "type": "module",
6
6
  "license": "MIT",