@seip/bluebird-js 0.1.7 → 0.2.1
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/AGENTS.md +727 -620
- package/README.md +670 -607
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +55 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/table.html +15 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +92 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +93 -0
- package/app/resources/pages/Home.jsx +140 -0
- package/app/resources/pages/Login.jsx +35 -0
- package/app/resources/pages/NotFound.jsx +16 -0
- package/app/resources/pages/Register.jsx +55 -0
- package/app/resources/pages/TableDemo.jsx +85 -0
- package/app/resources/routes.jsx +59 -0
- package/app/resources/spa.js +73 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +129 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +89 -47
- package/core/ai.js +30 -10
- package/core/app.d.ts +2 -18
- package/core/app.js +987 -801
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/build.js +37 -0
- package/core/cli/dev.js +155 -0
- package/core/cli/doctor.js +37 -2
- package/core/cli/export.js +191 -0
- package/core/cli/init.js +91 -322
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +98 -161
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +1184 -1131
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +126 -310
- package/core/paths.js +55 -0
- package/core/ratelimit.js +10 -1
- package/core/react/client/api.js +239 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/datatable.js +595 -0
- package/core/react/client/i18n.js +440 -0
- package/core/react/client/index.d.ts +314 -0
- package/core/react/client/index.js +50 -0
- package/core/react/client/router.js +26 -0
- package/core/react/client/theme.css +512 -0
- package/core/render-cache.js +250 -212
- package/core/render.d.ts +25 -21
- package/core/render.js +738 -736
- package/core/router.d.ts +2 -3
- package/core/router.js +171 -171
- package/core/seo.js +10 -0
- package/core/spa.js +599 -0
- package/core/view-loader.js +155 -613
- package/core/vite-plugin.d.ts +18 -0
- package/core/vite-plugin.js +162 -0
- package/core/vite.js +250 -145
- package/index.js +22 -18
- package/jsconfig.json +5 -3
- package/package.json +114 -92
- package/production.md +8 -3
- package/public/js/bluebird.js +1886 -0
- package/templates/_auth/app/database.js +19 -0
- package/templates/_auth/app/models/user.js +22 -0
- package/templates/_auth/app/routes/auth-router.js +304 -0
- package/templates/_base/app/resources/html/layouts/main.html +55 -0
- package/templates/_base/app/resources/html/notFound.html +14 -0
- package/templates/_base/app/resources/index.html +27 -0
- package/templates/_base/app/resources/styles.css +9 -0
- package/templates/api/app/models/note.js +18 -0
- package/templates/api/app/routes/api.js +82 -0
- package/templates/api/app/routes/auth.js +11 -0
- package/templates/api/index.js +19 -0
- package/templates/api/template.json +13 -0
- package/templates/auth/app/mail.js +11 -0
- package/templates/auth/app/models/password_reset.js +18 -0
- package/templates/auth/app/resources/html/home.html +21 -0
- package/templates/auth/app/resources/html/partials/nav.html +2 -0
- package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
- package/templates/auth/app/resources/main.jsx +18 -0
- package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
- package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
- package/templates/auth/app/resources/pages/Login.jsx +36 -0
- package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
- package/templates/auth/app/resources/pages/Profile.jsx +99 -0
- package/templates/auth/app/resources/pages/Register.jsx +50 -0
- package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
- package/templates/auth/app/resources/routes.jsx +54 -0
- package/templates/auth/app/resources/spa.js +29 -0
- package/templates/auth/app/routes/api.js +17 -0
- package/templates/auth/app/routes/auth.js +13 -0
- package/templates/auth/app/routes/web.js +21 -0
- package/templates/auth/index.js +19 -0
- package/templates/auth/template.json +15 -0
- package/templates/blank/app/models/.gitkeep +0 -0
- package/templates/blank/app/resources/html/home.html +27 -0
- package/templates/blank/app/resources/html/partials/nav.html +1 -0
- package/templates/blank/app/resources/main.jsx +16 -0
- package/templates/blank/app/resources/pages/Home.jsx +42 -0
- package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
- package/templates/blank/app/resources/routes.jsx +15 -0
- package/templates/blank/app/resources/spa.js +24 -0
- package/templates/blank/app/routes/api.js +11 -0
- package/templates/blank/app/routes/web.js +21 -0
- package/templates/blank/index.js +13 -0
- package/templates/blank/template.json +12 -0
- package/templates/blog/app/lib/blog.js +149 -0
- package/templates/blog/app/models/post.js +22 -0
- package/templates/blog/app/resources/html/home.html +28 -0
- package/templates/blog/app/resources/html/not-found.html +5 -0
- package/templates/blog/app/resources/html/partials/nav.html +2 -0
- package/templates/blog/app/resources/html/partials/post-card.html +9 -0
- package/templates/blog/app/resources/html/post.html +8 -0
- package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
- package/templates/blog/app/resources/main.jsx +18 -0
- package/templates/blog/app/resources/pages/Login.jsx +31 -0
- package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
- package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
- package/templates/blog/app/resources/pages/Posts.jsx +83 -0
- package/templates/blog/app/resources/pages/Register.jsx +43 -0
- package/templates/blog/app/resources/routes.jsx +51 -0
- package/templates/blog/app/resources/spa.js +25 -0
- package/templates/blog/app/resources/styles.css +40 -0
- package/templates/blog/app/routes/api.js +77 -0
- package/templates/blog/app/routes/auth.js +10 -0
- package/templates/blog/app/routes/web.js +114 -0
- package/templates/blog/index.js +21 -0
- package/templates/blog/template.json +14 -0
- package/vite.config.js +11 -0
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -67
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/pages/about.jsx +0 -98
- package/app/views/pages/dashboard.jsx +0 -278
- package/app/views/pages/index.jsx +0 -123
- package/app/views/pages/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -355
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1597
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3265
- package/public/js/tailwind.js +0 -8
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Card, Form, Input, Link, SubmitButton, useAuth } from "@seip/bluebird-js/react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One-time admin registration. The server closes registration once the first account exists.
|
|
5
|
+
*/
|
|
6
|
+
export default function Register() {
|
|
7
|
+
const { register, registerEnabled } = useAuth();
|
|
8
|
+
|
|
9
|
+
if (!registerEnabled) {
|
|
10
|
+
return (
|
|
11
|
+
<div className="mx-auto max-w-md py-6">
|
|
12
|
+
<Card title="Registration closed" description="The admin account already exists.">
|
|
13
|
+
<Link to="/login" className="text-sm font-semibold text-foreground underline-offset-4 hover:underline">
|
|
14
|
+
Back to sign in
|
|
15
|
+
</Link>
|
|
16
|
+
</Card>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="mx-auto max-w-md py-6">
|
|
23
|
+
<Card variant="glass" title="Create the admin account" description="This account will own and manage the blog.">
|
|
24
|
+
<Form onSubmitRequest={(values) => register(values)} successMessage="Admin account created" className="space-y-4">
|
|
25
|
+
<Input name="name" label="Name" autoComplete="name" required />
|
|
26
|
+
<Input name="email" type="email" label="Email" autoComplete="email" required />
|
|
27
|
+
<Input
|
|
28
|
+
name="password"
|
|
29
|
+
type="password"
|
|
30
|
+
label="Password"
|
|
31
|
+
hint="At least 8 characters"
|
|
32
|
+
autoComplete="new-password"
|
|
33
|
+
minLength={8}
|
|
34
|
+
required
|
|
35
|
+
/>
|
|
36
|
+
<SubmitButton className="w-full" loadingText="Creating...">
|
|
37
|
+
Create account
|
|
38
|
+
</SubmitButton>
|
|
39
|
+
</Form>
|
|
40
|
+
</Card>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Suspense, lazy } from "react";
|
|
2
|
+
import { Navigate } from "react-router";
|
|
3
|
+
import { GuestOnly, PageSkeleton, RequireAuth, createRouter } from "@seip/bluebird-js/react";
|
|
4
|
+
import AdminLayout from "./layouts/AdminLayout.jsx";
|
|
5
|
+
|
|
6
|
+
const Login = lazy(() => import("./pages/Login.jsx"));
|
|
7
|
+
const Register = lazy(() => import("./pages/Register.jsx"));
|
|
8
|
+
const Posts = lazy(() => import("./pages/Posts.jsx"));
|
|
9
|
+
const PostEditor = lazy(() => import("./pages/PostEditor.jsx"));
|
|
10
|
+
const NotFound = lazy(() => import("./pages/NotFound.jsx"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wraps lazy route components in a full-width Suspense fallback.
|
|
14
|
+
* @param {import('react').ReactNode} element
|
|
15
|
+
* @returns {import('react').ReactNode}
|
|
16
|
+
*/
|
|
17
|
+
function withSuspense(element) {
|
|
18
|
+
return <Suspense fallback={<PageSkeleton />}>{element}</Suspense>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Blog admin routes under `/app`: sign in, then manage posts (admin role only).
|
|
23
|
+
*/
|
|
24
|
+
export const router = createRouter(
|
|
25
|
+
[
|
|
26
|
+
{
|
|
27
|
+
path: "/",
|
|
28
|
+
element: <AdminLayout />,
|
|
29
|
+
children: [
|
|
30
|
+
{ index: true, element: <Navigate to="/posts" replace /> },
|
|
31
|
+
{
|
|
32
|
+
element: <GuestOnly redirectTo="/posts" />,
|
|
33
|
+
children: [
|
|
34
|
+
{ path: "login", element: withSuspense(<Login />) },
|
|
35
|
+
{ path: "register", element: withSuspense(<Register />) },
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
element: <RequireAuth redirectTo="/login" roles={["admin"]} />,
|
|
40
|
+
children: [
|
|
41
|
+
{ path: "posts", element: withSuspense(<Posts />) },
|
|
42
|
+
{ path: "posts/new", element: withSuspense(<PostEditor />) },
|
|
43
|
+
{ path: "posts/:id", element: withSuspense(<PostEditor />) },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{ path: "*", element: withSuspense(<NotFound />) },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
{ basename: "/app" }
|
|
51
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React admin configuration shared by `routerWeb.spa(spa.mount, spa)` and `npx bluebird-js export`.
|
|
3
|
+
* The admin is private, so every route is `noindex`.
|
|
4
|
+
* @type {import('@seip/bluebird-js/core/index.js').SpaOptions & { mount: string }}
|
|
5
|
+
*/
|
|
6
|
+
const spa = {
|
|
7
|
+
mount: "/app",
|
|
8
|
+
lang: "en",
|
|
9
|
+
titleTemplate: "%s — %%APP_TITLE%% Admin",
|
|
10
|
+
title: "Admin",
|
|
11
|
+
head: [{ tag: "link", rel: "icon", href: "/images/favicon.ico" }],
|
|
12
|
+
htmlAttrs: { class: "dark", "data-theme": "dark" },
|
|
13
|
+
bodyAttrs: {
|
|
14
|
+
class: "min-h-screen bg-app text-foreground antialiased",
|
|
15
|
+
},
|
|
16
|
+
skeleton: "app",
|
|
17
|
+
meta: {
|
|
18
|
+
"*": { title: "Admin", robots: "noindex, nofollow", skeleton: "app" },
|
|
19
|
+
login: { title: "Sign In", robots: "noindex, nofollow", skeleton: "auth" },
|
|
20
|
+
register: { title: "Create Admin Account", robots: "noindex, nofollow", skeleton: "auth" },
|
|
21
|
+
posts: { title: "Posts" },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default spa;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
@source "./";
|
|
3
|
+
@source "../../public/js";
|
|
4
|
+
|
|
5
|
+
@custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *));
|
|
6
|
+
|
|
7
|
+
@theme {
|
|
8
|
+
--font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@layer components {
|
|
12
|
+
.post-body {
|
|
13
|
+
@apply space-y-5 text-base leading-relaxed text-foreground/90;
|
|
14
|
+
}
|
|
15
|
+
.post-body h2 {
|
|
16
|
+
@apply pt-4 text-2xl font-semibold tracking-tight text-foreground;
|
|
17
|
+
}
|
|
18
|
+
.post-body h3,
|
|
19
|
+
.post-body h4 {
|
|
20
|
+
@apply pt-2 text-xl font-semibold tracking-tight text-foreground;
|
|
21
|
+
}
|
|
22
|
+
.post-body a {
|
|
23
|
+
@apply font-medium text-foreground underline decoration-muted-foreground/40 underline-offset-4 hover:decoration-foreground;
|
|
24
|
+
}
|
|
25
|
+
.post-body ul {
|
|
26
|
+
@apply list-disc space-y-1 pl-6;
|
|
27
|
+
}
|
|
28
|
+
.post-body blockquote {
|
|
29
|
+
@apply border-l-2 border-border pl-4 italic text-muted-foreground;
|
|
30
|
+
}
|
|
31
|
+
.post-body code {
|
|
32
|
+
@apply rounded-md bg-muted px-1.5 py-0.5 text-sm;
|
|
33
|
+
}
|
|
34
|
+
.post-body pre {
|
|
35
|
+
@apply overflow-x-auto rounded-2xl border border-border bg-muted p-4 text-sm;
|
|
36
|
+
}
|
|
37
|
+
.post-body pre code {
|
|
38
|
+
@apply bg-transparent p-0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
2
|
+
import Auth from "@seip/bluebird-js/core/auth.js";
|
|
3
|
+
import Csrf from "@seip/bluebird-js/core/csrf.js";
|
|
4
|
+
import Validator from "@seip/bluebird-js/core/validate.js";
|
|
5
|
+
import Post from "../models/post.js";
|
|
6
|
+
import { postChanged, uniqueSlug } from "../lib/blog.js";
|
|
7
|
+
|
|
8
|
+
const routerApi = new Router("/api");
|
|
9
|
+
routerApi.use(Csrf.middleware());
|
|
10
|
+
|
|
11
|
+
const adminOnly = Auth.protect({ roles: "admin" });
|
|
12
|
+
|
|
13
|
+
const postValidator = new Validator(
|
|
14
|
+
{
|
|
15
|
+
title: { required: true, min: 3, max: 200 },
|
|
16
|
+
slug: { required: false, max: 200 },
|
|
17
|
+
excerpt: { required: false, max: 300 },
|
|
18
|
+
body: { required: true, min: 1 },
|
|
19
|
+
status: { required: true, in: ["draft", "published"] },
|
|
20
|
+
},
|
|
21
|
+
"en"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Picks the editable fields of a post from the request body.
|
|
26
|
+
* @param {Object} body
|
|
27
|
+
* @param {Object|null} existing - Current post when updating.
|
|
28
|
+
* @returns {Promise<Object>}
|
|
29
|
+
*/
|
|
30
|
+
async function postFields(body, existing = null) {
|
|
31
|
+
const status = body.status === "published" ? "published" : "draft";
|
|
32
|
+
return {
|
|
33
|
+
title: String(body.title).trim(),
|
|
34
|
+
slug: await uniqueSlug(body.slug || body.title, existing?.id ?? null),
|
|
35
|
+
excerpt: String(body.excerpt || "").trim().slice(0, 300),
|
|
36
|
+
body: String(body.body),
|
|
37
|
+
status,
|
|
38
|
+
published_at: status === "published" ? existing?.published_at || new Date().toISOString() : existing?.published_at || null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
routerApi.get("/posts", adminOnly, async (req, res) => {
|
|
43
|
+
const result = await Post.paginate({ order: "updated_at DESC", page: req.query.page, limit: 20 });
|
|
44
|
+
res.paginate(result.data, { page: result.page, limit: result.limit, total: result.total, totalPages: result.totalPages });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
routerApi.get("/posts/:id", adminOnly, async (req, res) => {
|
|
48
|
+
const post = await Post.find(req.params.id);
|
|
49
|
+
return post ? res.ok(post) : res.notFound("Post not found");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
routerApi.post("/posts", adminOnly, postValidator.middleware(), async (req, res) => {
|
|
53
|
+
const fields = await postFields(req.body);
|
|
54
|
+
const id = await Post.create({ ...fields, user_id: req.user.id });
|
|
55
|
+
const post = await Post.find(id);
|
|
56
|
+
await postChanged(post);
|
|
57
|
+
res.created(post, "Post created");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
routerApi.put("/posts/:id", adminOnly, postValidator.middleware(), async (req, res) => {
|
|
61
|
+
const existing = await Post.find(req.params.id);
|
|
62
|
+
if (!existing) return res.notFound("Post not found");
|
|
63
|
+
await Post.update(existing.id, await postFields(req.body, existing));
|
|
64
|
+
const post = await Post.find(existing.id);
|
|
65
|
+
await postChanged(post, existing.slug);
|
|
66
|
+
return res.ok(post, "Post saved");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
routerApi.delete("/posts/:id", adminOnly, async (req, res) => {
|
|
70
|
+
const existing = await Post.find(req.params.id);
|
|
71
|
+
if (!existing) return res.notFound("Post not found");
|
|
72
|
+
await Post.delete(existing.id);
|
|
73
|
+
await postChanged(null, existing.slug);
|
|
74
|
+
return res.ok({ id: existing.id }, "Post deleted");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export default routerApi;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createAuthRouter } from "./auth-router.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `/api/auth/*` for the blog admin. Only the first account can register (it becomes the `admin`),
|
|
5
|
+
* after that registration closes automatically.
|
|
6
|
+
*/
|
|
7
|
+
export default createAuthRouter({
|
|
8
|
+
register: "first-user",
|
|
9
|
+
firstUserAdmin: true,
|
|
10
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
2
|
+
import Render from "@seip/bluebird-js/core/render.js";
|
|
3
|
+
import { escapeHtml } from "@seip/bluebird-js/core/html.js";
|
|
4
|
+
import Post from "../models/post.js";
|
|
5
|
+
import { formatDate, renderMarkdown } from "../lib/blog.js";
|
|
6
|
+
import spa from "../resources/spa.js";
|
|
7
|
+
|
|
8
|
+
const routerWeb = new Router("/", { seo: true });
|
|
9
|
+
const BLOG_TITLE = "%%APP_TITLE%%";
|
|
10
|
+
const BLOG_DESCRIPTION = "Articles and updates from %%APP_TITLE%%.";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Public origin used for canonical URLs, RSS, and JSON-LD.
|
|
14
|
+
* @param {import('express').Request} req
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
function origin(req) {
|
|
18
|
+
return (process.env.APP_URL || `${req.protocol}://${req.get("host")}`).replace(/\/$/, "");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Serializes JSON-LD safely for an inline `<script>` tag.
|
|
23
|
+
* @param {Object} data
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
function jsonLd(data) {
|
|
27
|
+
return `<script type="application/ld+json">${JSON.stringify(data).replace(/</g, "\\u003c")}</script>`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
routerWeb.get("/", async (req, res) => {
|
|
31
|
+
const page = Math.max(1, parseInt(req.query.page, 10) || 1);
|
|
32
|
+
const result = await Post.paginate({
|
|
33
|
+
where: { status: "published" },
|
|
34
|
+
order: "published_at DESC",
|
|
35
|
+
page,
|
|
36
|
+
limit: 10,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return Render.html(
|
|
40
|
+
res,
|
|
41
|
+
"home",
|
|
42
|
+
{
|
|
43
|
+
title: page > 1 ? `${BLOG_TITLE} — Page ${page}` : BLOG_TITLE,
|
|
44
|
+
description: BLOG_DESCRIPTION,
|
|
45
|
+
canonical: `${origin(req)}/${page > 1 ? `?page=${page}` : ""}`,
|
|
46
|
+
headHtml: `<link rel="alternate" type="application/rss+xml" title="${escapeHtml(BLOG_TITLE)}" href="/feed.xml">`,
|
|
47
|
+
posts: result.data.map((post) => ({ ...post, date: formatDate(post.published_at) })),
|
|
48
|
+
prevPage: page > 1 ? page - 1 : null,
|
|
49
|
+
nextPage: page < result.totalPages ? page + 1 : null,
|
|
50
|
+
},
|
|
51
|
+
{ layout: "main", cache: 120, cacheQuery: ["page"] }
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
routerWeb.get("/blog/:slug", async (req, res) => {
|
|
56
|
+
const post = await Post.find({ slug: String(req.params.slug), status: "published" });
|
|
57
|
+
if (!post) {
|
|
58
|
+
res.status(404);
|
|
59
|
+
return Render.html(res, "not-found", { title: "Post not found" }, { layout: "main" });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const url = `${origin(req)}/blog/${post.slug}`;
|
|
63
|
+
return Render.html(
|
|
64
|
+
res,
|
|
65
|
+
"post",
|
|
66
|
+
{
|
|
67
|
+
title: `${post.title} — ${BLOG_TITLE}`,
|
|
68
|
+
description: post.excerpt || BLOG_DESCRIPTION,
|
|
69
|
+
canonical: url,
|
|
70
|
+
headHtml: jsonLd({
|
|
71
|
+
"@context": "https://schema.org",
|
|
72
|
+
"@type": "BlogPosting",
|
|
73
|
+
headline: post.title,
|
|
74
|
+
description: post.excerpt || undefined,
|
|
75
|
+
datePublished: post.published_at,
|
|
76
|
+
dateModified: post.updated_at || post.published_at,
|
|
77
|
+
mainEntityOfPage: url,
|
|
78
|
+
}),
|
|
79
|
+
post: { ...post, date: formatDate(post.published_at) },
|
|
80
|
+
bodyHtml: renderMarkdown(post.body),
|
|
81
|
+
},
|
|
82
|
+
{ layout: "main", cache: 300 }
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
routerWeb.get("/feed.xml", async (req, res) => {
|
|
87
|
+
const base = origin(req);
|
|
88
|
+
const posts = await Post.all({ where: { status: "published" }, order: "published_at DESC", limit: 20 });
|
|
89
|
+
const items = posts
|
|
90
|
+
.map(
|
|
91
|
+
(post) => ` <item>
|
|
92
|
+
<title>${escapeHtml(post.title)}</title>
|
|
93
|
+
<link>${base}/blog/${post.slug}</link>
|
|
94
|
+
<guid>${base}/blog/${post.slug}</guid>
|
|
95
|
+
<pubDate>${new Date(post.published_at || post.created_at).toUTCString()}</pubDate>
|
|
96
|
+
<description>${escapeHtml(post.excerpt || "")}</description>
|
|
97
|
+
</item>`
|
|
98
|
+
)
|
|
99
|
+
.join("\n");
|
|
100
|
+
|
|
101
|
+
res.type("application/rss+xml").send(`<?xml version="1.0" encoding="UTF-8"?>
|
|
102
|
+
<rss version="2.0">
|
|
103
|
+
<channel>
|
|
104
|
+
<title>${escapeHtml(BLOG_TITLE)}</title>
|
|
105
|
+
<link>${base}/</link>
|
|
106
|
+
<description>${escapeHtml(BLOG_DESCRIPTION)}</description>
|
|
107
|
+
${items}
|
|
108
|
+
</channel>
|
|
109
|
+
</rss>`);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
routerWeb.spa(spa.mount, spa);
|
|
113
|
+
|
|
114
|
+
export default routerWeb;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import App from "@seip/bluebird-js/core/app.js";
|
|
2
|
+
import { ensureSchema } from "./app/database.js";
|
|
3
|
+
import { syncSitemap } from "./app/lib/blog.js";
|
|
4
|
+
import User from "./app/models/user.js";
|
|
5
|
+
import Post from "./app/models/post.js";
|
|
6
|
+
import routerApi from "./app/routes/api.js";
|
|
7
|
+
import routerAuth from "./app/routes/auth.js";
|
|
8
|
+
import routerWeb from "./app/routes/web.js";
|
|
9
|
+
|
|
10
|
+
await ensureSchema([User, Post]);
|
|
11
|
+
await syncSitemap();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Application entrypoint: public blog rendered with HTML {{ }} templates, React admin on `/app`.
|
|
15
|
+
*/
|
|
16
|
+
const app = new App({
|
|
17
|
+
routes: [routerWeb, routerAuth, routerApi],
|
|
18
|
+
port: Number(process.env.PORT || 3000),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.run();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "SEO blog rendered with HTML {{ }} (list, post pages, RSS, sitemap) and a React admin on /app to write posts",
|
|
3
|
+
"layers": [
|
|
4
|
+
"_base",
|
|
5
|
+
"_auth"
|
|
6
|
+
],
|
|
7
|
+
"client": true,
|
|
8
|
+
"database": "required",
|
|
9
|
+
"routes": [
|
|
10
|
+
"/, /blog/:slug HTML {{ }} blog (cached, JSON-LD, sitemap)",
|
|
11
|
+
"/feed.xml RSS feed",
|
|
12
|
+
"/app/* React admin (the first account becomes the admin)"
|
|
13
|
+
]
|
|
14
|
+
}
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
4
|
+
import bluebird from "@seip/bluebird-js/vite";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Vite configuration (optional: Bluebird uses these same plugins when this file does not exist).
|
|
8
|
+
*/
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [bluebird(), react(), tailwindcss()],
|
|
11
|
+
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reusable Header component for dashboard and application views in React JSX.
|
|
3
|
-
*
|
|
4
|
-
* @param {Object} [props={}]
|
|
5
|
-
* @param {string} [props.title]
|
|
6
|
-
* @param {string} [props.subtitle]
|
|
7
|
-
* @param {number} [props.count]
|
|
8
|
-
* @param {Object} [props.user]
|
|
9
|
-
* @param {Object} [props.props]
|
|
10
|
-
*/
|
|
11
|
-
export default function Header(props = {}) {
|
|
12
|
-
const actualProps = props.props || props;
|
|
13
|
-
const title = actualProps.title || "Dashboard Overview";
|
|
14
|
-
const subtitle =
|
|
15
|
-
actualProps.subtitle || "Welcome to your high-performance Bluebird.js control center.";
|
|
16
|
-
const count = actualProps.count !== undefined ? actualProps.count : 0;
|
|
17
|
-
const userName = actualProps.user?.name || "Member";
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<header className="flex flex-col md:flex-row md:items-center justify-between gap-4 pb-6 mb-8 border-b border-slate-800">
|
|
21
|
-
<div>
|
|
22
|
-
<div className="flex items-center gap-3">
|
|
23
|
-
<h1 className="text-2xl md:text-3xl font-bold tracking-tight text-slate-100">{title}</h1>
|
|
24
|
-
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-sky-500/10 text-sky-400 border border-sky-500/20">
|
|
25
|
-
Active: <span id="header-counter-badge" className="ml-1 font-semibold">{count}</span>
|
|
26
|
-
</span>
|
|
27
|
-
</div>
|
|
28
|
-
<p className="text-sm text-slate-400 mt-1">{subtitle}</p>
|
|
29
|
-
</div>
|
|
30
|
-
<div className="flex items-center gap-3">
|
|
31
|
-
<div className="text-right hidden sm:block">
|
|
32
|
-
<div className="text-xs text-slate-400">Logged in as</div>
|
|
33
|
-
<div className="text-sm font-semibold text-slate-200">{userName}</div>
|
|
34
|
-
</div>
|
|
35
|
-
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-sky-400 to-indigo-600 flex items-center justify-center text-slate-950 font-bold text-sm shadow-md">
|
|
36
|
-
{userName.slice(0, 1).toUpperCase()}
|
|
37
|
-
</div>
|
|
38
|
-
</div>
|
|
39
|
-
</header>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useAction, client } from "@seip/bluebird-js/core/jsx.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Reusable reactive Client Counter component with pure JSX/TSX support.
|
|
5
|
-
* Powered by Bluebird's zero-build client runtime with hooks (useState, useEffect, useAction) and real JSX.
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} props
|
|
8
|
-
* @param {number} [props.initial=7]
|
|
9
|
-
* @param {string} [props.label="Client Component Counter"]
|
|
10
|
-
* @returns {any}
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export function LiveCounter({ initial = 7, label = "Client Component Counter" }) {
|
|
14
|
-
const [count, setCount] = useState(Number(initial) || 0);
|
|
15
|
-
const [sync, isPending] = useAction("syncCount", {
|
|
16
|
-
onSuccess(res) {
|
|
17
|
-
if (res?.data?.message && typeof window.toast === "function") {
|
|
18
|
-
window.toast({
|
|
19
|
-
title: "Server Action Executed",
|
|
20
|
-
description: res.data.message,
|
|
21
|
-
type: "success",
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const badge = document.getElementById("header-counter-badge");
|
|
29
|
-
if (badge) badge.textContent = String(count);
|
|
30
|
-
}, [count]);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<div className="h-14 rounded-xl border border-slate-800 bg-slate-950/90 px-4 flex items-center justify-between">
|
|
34
|
-
<div className="flex items-center gap-2.5">
|
|
35
|
-
<span className={`w-2 h-2 rounded-full ${isPending ? "bg-amber-400" : "bg-emerald-400"} animate-pulse`} />
|
|
36
|
-
<span className="text-xs font-medium text-slate-300">{label}:</span>
|
|
37
|
-
<strong data-counter-val className="font-mono text-base text-sky-400">{count}</strong>
|
|
38
|
-
</div>
|
|
39
|
-
<div className="flex items-center gap-2">
|
|
40
|
-
<button
|
|
41
|
-
type="button"
|
|
42
|
-
onClick={() => setCount(Math.max(0, count - 1))}
|
|
43
|
-
className="px-2.5 py-1 rounded-lg border border-slate-700 bg-slate-800 hover:bg-slate-700 text-xs font-semibold text-slate-200 transition-colors"
|
|
44
|
-
>
|
|
45
|
-
−
|
|
46
|
-
</button>
|
|
47
|
-
<button
|
|
48
|
-
type="button"
|
|
49
|
-
onClick={() => setCount(count + 1)}
|
|
50
|
-
className="px-2.5 py-1 rounded-lg bg-sky-500 hover:bg-sky-400 text-xs font-bold text-slate-950 transition-colors"
|
|
51
|
-
>
|
|
52
|
-
+
|
|
53
|
-
</button>
|
|
54
|
-
<button
|
|
55
|
-
type="button"
|
|
56
|
-
onClick={() => sync({ count })}
|
|
57
|
-
disabled={isPending}
|
|
58
|
-
className="px-2.5 py-1 rounded-lg border border-emerald-500/30 bg-emerald-500/15 hover:bg-emerald-500/25 text-xs font-semibold text-emerald-300 transition-colors disabled:opacity-50"
|
|
59
|
-
>
|
|
60
|
-
{isPending ? "Syncing..." : "Sync Action"}
|
|
61
|
-
</button>
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default client(LiveCounter, { minHeight: 56 });
|