astro-blog-kit 0.2.1 → 0.2.3
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/bin/cli.js +17 -1
- package/cli.ts +19 -0
- package/package.json +1 -1
- package/templates/blog-index.astro.template +14 -21
- package/templates/blog-page.astro.template +14 -21
- package/templates/blog-slug.astro.template +6 -12
package/bin/cli.js
CHANGED
|
@@ -42,6 +42,10 @@ async function main() {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}),
|
|
45
|
+
layoutComponent: () => p.text({
|
|
46
|
+
message: "Layout component path (leave empty to skip)",
|
|
47
|
+
placeholder: "../../layouts/Layout.astro"
|
|
48
|
+
}),
|
|
45
49
|
postsPerPage: () => p.text({
|
|
46
50
|
message: "Posts per page",
|
|
47
51
|
placeholder: "5",
|
|
@@ -78,11 +82,23 @@ async function main() {
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
);
|
|
85
|
+
const layoutPath = answers.layoutComponent || "";
|
|
81
86
|
const replacements = {
|
|
82
87
|
WP_URL: answers.wpUrl,
|
|
83
88
|
POSTS_PER_PAGE: answers.postsPerPage,
|
|
84
89
|
DEFAULT_LAYOUT: answers.defaultLayout,
|
|
85
|
-
LOCALE: answers.locale
|
|
90
|
+
LOCALE: answers.locale,
|
|
91
|
+
LAYOUT_IMPORT: layoutPath ? `import Layout from "${layoutPath}";` : "",
|
|
92
|
+
LAYOUT_IMPORT_PAGE: layoutPath ? `import Layout from "../${layoutPath}";` : "",
|
|
93
|
+
LAYOUT_OPEN: layoutPath ? `<Layout>` : `<html lang={config.locale ?? "en"}>
|
|
94
|
+
<head>
|
|
95
|
+
<meta charset="UTF-8" />
|
|
96
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
97
|
+
<title>Blog</title>
|
|
98
|
+
</head>
|
|
99
|
+
<body>`,
|
|
100
|
+
LAYOUT_CLOSE: layoutPath ? `</Layout>` : ` </body>
|
|
101
|
+
</html>`
|
|
86
102
|
};
|
|
87
103
|
const cwd = process.cwd();
|
|
88
104
|
const spinner2 = p.spinner();
|
package/cli.ts
CHANGED
|
@@ -65,6 +65,11 @@ async function main() {
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
}),
|
|
68
|
+
layoutComponent: () =>
|
|
69
|
+
p.text({
|
|
70
|
+
message: "Layout component path (leave empty to skip)",
|
|
71
|
+
placeholder: "../../layouts/Layout.astro",
|
|
72
|
+
}),
|
|
68
73
|
|
|
69
74
|
postsPerPage: () =>
|
|
70
75
|
p.text({
|
|
@@ -112,11 +117,25 @@ async function main() {
|
|
|
112
117
|
|
|
113
118
|
// ── Replacements ──────────────────────────────────────────
|
|
114
119
|
|
|
120
|
+
const layoutPath = (answers.layoutComponent as string) || "";
|
|
121
|
+
|
|
115
122
|
const replacements: Record<string, string> = {
|
|
116
123
|
WP_URL: answers.wpUrl as string,
|
|
117
124
|
POSTS_PER_PAGE: answers.postsPerPage as string,
|
|
118
125
|
DEFAULT_LAYOUT: answers.defaultLayout as string,
|
|
119
126
|
LOCALE: answers.locale as string,
|
|
127
|
+
LAYOUT_IMPORT: layoutPath
|
|
128
|
+
? `import Layout from "${layoutPath}";`
|
|
129
|
+
: "",
|
|
130
|
+
LAYOUT_IMPORT_PAGE: layoutPath
|
|
131
|
+
? `import Layout from "../${layoutPath}";`
|
|
132
|
+
: "",
|
|
133
|
+
LAYOUT_OPEN: layoutPath
|
|
134
|
+
? `<Layout>`
|
|
135
|
+
: `<html lang={config.locale ?? "en"}>\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>Blog</title>\n </head>\n <body>`,
|
|
136
|
+
LAYOUT_CLOSE: layoutPath
|
|
137
|
+
? `</Layout>`
|
|
138
|
+
: ` </body>\n</html>`,
|
|
120
139
|
};
|
|
121
140
|
|
|
122
141
|
// ── Copia archivos ────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { BlogList } from "astro-blog-kit/components";
|
|
3
3
|
import { createWPClient } from "astro-blog-kit/utils";
|
|
4
4
|
import config from "../../../blog.config";
|
|
5
|
+
__LAYOUT_IMPORT__
|
|
5
6
|
|
|
6
7
|
const wp = createWPClient(config.wpUrl);
|
|
7
8
|
const { posts, totalPages } = await wp.getPosts({ perPage: config.postsPerPage ?? 5 });
|
|
@@ -21,24 +22,16 @@ const t = {
|
|
|
21
22
|
const base = import.meta.env.BASE_URL;
|
|
22
23
|
---
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
blogBase={`${base}blog/`}
|
|
38
|
-
dateLocale={config.locale ?? "en"}
|
|
39
|
-
t={t}
|
|
40
|
-
locale={config.locale ?? "en"}
|
|
41
|
-
layout={config.defaultLayout ?? "magazine"}
|
|
42
|
-
/>
|
|
43
|
-
</body>
|
|
44
|
-
</html>
|
|
25
|
+
__LAYOUT_OPEN__
|
|
26
|
+
<BlogList
|
|
27
|
+
posts={posts}
|
|
28
|
+
currentPage={1}
|
|
29
|
+
totalPages={totalPages}
|
|
30
|
+
basePath={`${base}blog/page/`}
|
|
31
|
+
blogBase={`${base}blog/`}
|
|
32
|
+
dateLocale={config.locale ?? "en"}
|
|
33
|
+
t={t}
|
|
34
|
+
locale={config.locale ?? "en"}
|
|
35
|
+
layout={config.defaultLayout ?? "magazine"}
|
|
36
|
+
/>
|
|
37
|
+
__LAYOUT_CLOSE__
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { BlogList } from "astro-blog-kit/components";
|
|
3
3
|
import { createWPClient, getStaticPathsForPages } from "astro-blog-kit/utils";
|
|
4
4
|
import config from "../../../../blog.config";
|
|
5
|
+
__LAYOUT_IMPORT__
|
|
5
6
|
|
|
6
7
|
export async function getStaticPaths() {
|
|
7
8
|
const wp = createWPClient(config.wpUrl);
|
|
8
|
-
|
|
9
9
|
const posts = await wp.getAllPosts();
|
|
10
10
|
return getStaticPathsForPages(posts, { postsPerPage: config.postsPerPage ?? 5 });
|
|
11
11
|
}
|
|
@@ -27,23 +27,16 @@ const t = {
|
|
|
27
27
|
const base = import.meta.env.BASE_URL;
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
dateLocale={config.locale ?? "en"}
|
|
44
|
-
t={t}
|
|
45
|
-
locale={config.locale ?? "en"}
|
|
46
|
-
layout={config.defaultLayout ?? "magazine"}
|
|
47
|
-
/>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|
|
30
|
+
__LAYOUT_OPEN__
|
|
31
|
+
<BlogList
|
|
32
|
+
posts={posts}
|
|
33
|
+
currentPage={currentPage}
|
|
34
|
+
totalPages={totalPages}
|
|
35
|
+
basePath={`${base}blog/page/`}
|
|
36
|
+
blogBase={`${base}blog/`}
|
|
37
|
+
dateLocale={config.locale ?? "en"}
|
|
38
|
+
t={t}
|
|
39
|
+
locale={config.locale ?? "en"}
|
|
40
|
+
layout={config.defaultLayout ?? "magazine"}
|
|
41
|
+
/>
|
|
42
|
+
__LAYOUT_CLOSE__
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { BlogPost, Comments, CommentForm } from "astro-blog-kit/components";
|
|
3
3
|
import { createWPClient, getStaticPathsForPosts } from "astro-blog-kit/utils";
|
|
4
4
|
import config from "../../../blog.config";
|
|
5
|
+
__LAYOUT_IMPORT__
|
|
5
6
|
|
|
6
7
|
export async function getStaticPaths() {
|
|
7
8
|
const wp = createWPClient(config.wpUrl);
|
|
@@ -27,15 +28,8 @@ const t = {
|
|
|
27
28
|
};
|
|
28
29
|
---
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</head>
|
|
36
|
-
<body>
|
|
37
|
-
<BlogPost post={post} t={t} lang={config.locale ?? "en"} />
|
|
38
|
-
<Comments comments={comments} postId={post.id ?? 0} />
|
|
39
|
-
<CommentForm postId={post.id ?? 0} apiRoute="/api/comments" />
|
|
40
|
-
</body>
|
|
41
|
-
</html>
|
|
31
|
+
__LAYOUT_OPEN__
|
|
32
|
+
<BlogPost post={post} t={t} lang={config.locale ?? "en"} />
|
|
33
|
+
<Comments comments={comments} postId={post.id ?? 0} />
|
|
34
|
+
<CommentForm postId={post.id ?? 0} apiRoute="/api/comments" />
|
|
35
|
+
__LAYOUT_CLOSE__
|