zero-query 1.0.1 → 1.0.2
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 +47 -6
- package/cli/help.js +2 -1
- package/cli/scaffold/default/app/app.js +3 -6
- package/cli/scaffold/default/global.css +12 -3
- package/cli/scaffold/default/index.html +8 -8
- package/cli/scaffold/minimal/app/app.js +3 -9
- package/cli/scaffold/minimal/global.css +12 -3
- package/cli/scaffold/minimal/index.html +3 -3
- package/cli/scaffold/ssr/app/app.js +18 -6
- package/cli/scaffold/ssr/app/components/about.js +42 -15
- package/cli/scaffold/ssr/app/components/blog/index.js +65 -0
- package/cli/scaffold/ssr/app/components/blog/post.js +78 -0
- package/cli/scaffold/ssr/app/routes.js +4 -2
- package/cli/scaffold/ssr/global.css +117 -1
- package/cli/scaffold/ssr/index.html +8 -2
- package/cli/scaffold/ssr/server/data/posts.js +144 -0
- package/cli/scaffold/ssr/server/index.js +151 -11
- package/dist/zquery.dist.zip +0 -0
- package/dist/zquery.js +21 -6
- package/dist/zquery.min.js +2 -2
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/component.js +17 -2
- package/tests/component.test.js +480 -0
- package/tests/test-minifier.js +4 -4
- package/types/misc.d.ts +23 -1
|
@@ -49,6 +49,8 @@ body {
|
|
|
49
49
|
padding: 0.4rem 0.8rem;
|
|
50
50
|
border-radius: var(--radius);
|
|
51
51
|
transition: color 0.2s, background 0.2s;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
user-select: none;
|
|
52
54
|
}
|
|
53
55
|
.nav-link:hover, .nav-link.active {
|
|
54
56
|
color: var(--accent);
|
|
@@ -58,7 +60,7 @@ body {
|
|
|
58
60
|
/* -- Main content -- */
|
|
59
61
|
z-outlet {
|
|
60
62
|
display: block;
|
|
61
|
-
max-width:
|
|
63
|
+
max-width: 1200px;
|
|
62
64
|
margin: 2rem auto;
|
|
63
65
|
padding: 0 1.5rem;
|
|
64
66
|
}
|
|
@@ -91,6 +93,15 @@ z-outlet {
|
|
|
91
93
|
border-radius: 4px;
|
|
92
94
|
font-size: 0.9em;
|
|
93
95
|
}
|
|
96
|
+
.card a {
|
|
97
|
+
color: var(--accent);
|
|
98
|
+
text-decoration: none;
|
|
99
|
+
transition: color 0.15s;
|
|
100
|
+
}
|
|
101
|
+
.card a:hover {
|
|
102
|
+
color: var(--accent-hover);
|
|
103
|
+
text-decoration: underline;
|
|
104
|
+
}
|
|
94
105
|
|
|
95
106
|
.badge {
|
|
96
107
|
display: inline-block;
|
|
@@ -102,6 +113,111 @@ z-outlet {
|
|
|
102
113
|
.badge-ssr { background: rgba(0,212,255,0.15); color: var(--accent); }
|
|
103
114
|
.badge-csr { background: rgba(255,165,0,0.15); color: #ffa500; }
|
|
104
115
|
|
|
116
|
+
/* -- Blog Grid -- */
|
|
117
|
+
.blog-grid {
|
|
118
|
+
display: grid;
|
|
119
|
+
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
|
120
|
+
gap: var(--gap);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.blog-card {
|
|
124
|
+
display: block;
|
|
125
|
+
text-decoration: none;
|
|
126
|
+
color: inherit;
|
|
127
|
+
background: var(--surface);
|
|
128
|
+
border: 1px solid rgba(255,255,255,0.06);
|
|
129
|
+
border-radius: var(--radius);
|
|
130
|
+
padding: 1.5rem;
|
|
131
|
+
transition: border-color 0.2s, transform 0.2s;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
}
|
|
134
|
+
.blog-card:hover {
|
|
135
|
+
border-color: rgba(0, 212, 255, 0.25);
|
|
136
|
+
transform: translateY(-2px);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.blog-card-header {
|
|
140
|
+
display: flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
justify-content: space-between;
|
|
143
|
+
margin-bottom: 0.75rem;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.blog-date {
|
|
147
|
+
font-size: 0.8em;
|
|
148
|
+
color: var(--muted);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.blog-title {
|
|
152
|
+
font-size: 1.1rem;
|
|
153
|
+
margin-bottom: 0.5rem;
|
|
154
|
+
color: var(--text);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.blog-summary {
|
|
158
|
+
color: var(--muted);
|
|
159
|
+
font-size: 0.9rem;
|
|
160
|
+
line-height: 1.6;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* -- Blog Post Detail -- */
|
|
164
|
+
.back-link {
|
|
165
|
+
display: inline-block;
|
|
166
|
+
color: var(--accent);
|
|
167
|
+
font-size: 0.9rem;
|
|
168
|
+
margin-bottom: 1rem;
|
|
169
|
+
transition: opacity 0.15s;
|
|
170
|
+
text-decoration: none;
|
|
171
|
+
cursor: pointer;
|
|
172
|
+
}
|
|
173
|
+
.back-link:hover { opacity: 0.75; }
|
|
174
|
+
|
|
175
|
+
.blog-post-meta {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: 0.75rem;
|
|
179
|
+
margin-top: 0.5rem;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.blog-post-body {
|
|
183
|
+
background: var(--surface);
|
|
184
|
+
border: 1px solid rgba(255,255,255,0.06);
|
|
185
|
+
border-radius: var(--radius);
|
|
186
|
+
padding: 2rem;
|
|
187
|
+
line-height: 1.8;
|
|
188
|
+
font-size: 0.95rem;
|
|
189
|
+
}
|
|
190
|
+
.blog-post-body h4 {
|
|
191
|
+
color: var(--accent);
|
|
192
|
+
margin: 1.5rem 0 0.75rem;
|
|
193
|
+
font-size: 1.05rem;
|
|
194
|
+
}
|
|
195
|
+
.blog-post-body h4:first-child { margin-top: 0; }
|
|
196
|
+
.blog-post-body ul, .blog-post-body ol {
|
|
197
|
+
padding-left: 1.5rem;
|
|
198
|
+
margin: 0.5rem 0;
|
|
199
|
+
}
|
|
200
|
+
.blog-post-body li { margin-bottom: 0.4rem; }
|
|
201
|
+
.blog-post-body pre {
|
|
202
|
+
background: rgba(0,0,0,0.3);
|
|
203
|
+
border-radius: var(--radius);
|
|
204
|
+
padding: 1rem 1.25rem;
|
|
205
|
+
overflow-x: auto;
|
|
206
|
+
margin: 0.75rem 0;
|
|
207
|
+
font-size: 0.85rem;
|
|
208
|
+
line-height: 1.5;
|
|
209
|
+
}
|
|
210
|
+
.blog-post-body code {
|
|
211
|
+
background: rgba(255,255,255,0.06);
|
|
212
|
+
padding: 0.15em 0.4em;
|
|
213
|
+
border-radius: 4px;
|
|
214
|
+
font-size: 0.9em;
|
|
215
|
+
}
|
|
216
|
+
.blog-post-body pre code {
|
|
217
|
+
background: none;
|
|
218
|
+
padding: 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
105
221
|
/* -- Footer -- */
|
|
106
222
|
.footer {
|
|
107
223
|
text-align: center;
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>{{NAME}}</title>
|
|
7
|
+
<meta name="description" content="">
|
|
8
|
+
<meta property="og:title" content="{{NAME}}">
|
|
9
|
+
<meta property="og:description" content="">
|
|
10
|
+
<meta property="og:type" content="website">
|
|
11
|
+
<meta name="robots" content="index, follow">
|
|
7
12
|
<base href="/">
|
|
8
13
|
<link rel="stylesheet" href="global.css">
|
|
9
14
|
<script src="zquery.min.js"></script>
|
|
@@ -15,8 +20,9 @@
|
|
|
15
20
|
<nav class="navbar">
|
|
16
21
|
<span class="brand">⚡ {{NAME}}</span>
|
|
17
22
|
<div class="nav-links">
|
|
18
|
-
<a z-link="/" class="nav-link">Home</a>
|
|
19
|
-
<a z-link="/
|
|
23
|
+
<a z-link="/" class="nav-link" z-active-route="/" z-active-exact>Home</a>
|
|
24
|
+
<a z-link="/blog" class="nav-link" z-active-route="/blog">Blog</a>
|
|
25
|
+
<a z-link="/about" class="nav-link" z-active-route="/about">About</a>
|
|
20
26
|
</div>
|
|
21
27
|
</nav>
|
|
22
28
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// server/data/posts.js - Blog post data
|
|
2
|
+
//
|
|
3
|
+
// Simulates a database or CMS. In a real app you'd fetch from a DB,
|
|
4
|
+
// headless CMS, or markdown files. The server imports this data and
|
|
5
|
+
// passes it as props to blog components during SSR.
|
|
6
|
+
|
|
7
|
+
export const posts = [
|
|
8
|
+
{
|
|
9
|
+
slug: 'why-ssr-matters',
|
|
10
|
+
title: 'Why Server-Side Rendering Matters',
|
|
11
|
+
date: '2025-12-15',
|
|
12
|
+
tag: 'SSR',
|
|
13
|
+
summary:
|
|
14
|
+
'SSR delivers fully rendered HTML to the browser, improving first contentful paint, SEO indexability, and perceived performance on slower connections.',
|
|
15
|
+
body: `
|
|
16
|
+
<p>Server-Side Rendering (SSR) generates the full HTML for a page on the server
|
|
17
|
+
before sending it to the browser. Instead of shipping an empty shell and waiting
|
|
18
|
+
for JavaScript to populate it, the user sees content immediately.</p>
|
|
19
|
+
|
|
20
|
+
<h4>Key Benefits</h4>
|
|
21
|
+
<ul>
|
|
22
|
+
<li><strong>Faster First Paint</strong> — HTML arrives ready to display.
|
|
23
|
+
No waiting for JS bundles to download and execute.</li>
|
|
24
|
+
<li><strong>SEO Friendly</strong> — Search engine crawlers see complete
|
|
25
|
+
content without running JavaScript.</li>
|
|
26
|
+
<li><strong>Social Sharing</strong> — Open Graph meta tags are present in
|
|
27
|
+
the initial response, so link previews work everywhere.</li>
|
|
28
|
+
<li><strong>Accessibility</strong> — Content is available even if JS fails
|
|
29
|
+
to load or is disabled.</li>
|
|
30
|
+
</ul>
|
|
31
|
+
|
|
32
|
+
<h4>The Trade-Off</h4>
|
|
33
|
+
<p>SSR adds server-side compute cost per request. Strategies like render
|
|
34
|
+
caching, edge deployment, and stale-while-revalidate headers help keep
|
|
35
|
+
response times low while maintaining the benefits of dynamic rendering.</p>
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
slug: 'hydration-explained',
|
|
40
|
+
title: 'Hydration: Picking Up Where the Server Left Off',
|
|
41
|
+
date: '2025-12-20',
|
|
42
|
+
tag: 'Architecture',
|
|
43
|
+
summary:
|
|
44
|
+
'After the server sends HTML, the client "hydrates" the page — attaching event listeners and reactive state so the SPA takes over without a full re-render.',
|
|
45
|
+
body: `
|
|
46
|
+
<p>Hydration is the process where the client-side framework takes ownership
|
|
47
|
+
of server-rendered HTML. The DOM is already there — hydration wires up event
|
|
48
|
+
handlers, reactive state, and component lifecycles on top of it.</p>
|
|
49
|
+
|
|
50
|
+
<h4>How It Works in zQuery</h4>
|
|
51
|
+
<ol>
|
|
52
|
+
<li>The server renders a component to HTML with <code>app.renderToString()</code>,
|
|
53
|
+
adding a <code>data-zq-ssr</code> marker.</li>
|
|
54
|
+
<li>The HTML is injected into the page shell and sent to the browser.</li>
|
|
55
|
+
<li>The client loads the same component definitions and registers them
|
|
56
|
+
with <code>$.component()</code>.</li>
|
|
57
|
+
<li>The router detects the SSR marker and hydrates instead of re-rendering,
|
|
58
|
+
preserving the existing DOM while activating reactivity.</li>
|
|
59
|
+
</ol>
|
|
60
|
+
|
|
61
|
+
<h4>Why This Matters</h4>
|
|
62
|
+
<p>Without hydration, the client would discard the server HTML and re-render
|
|
63
|
+
from scratch — causing a flash of empty content. Hydration gives you the best
|
|
64
|
+
of both worlds: fast server-rendered first paint with full client interactivity.</p>
|
|
65
|
+
`,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
slug: 'shared-components',
|
|
69
|
+
title: 'Shared Components Across Client and Server',
|
|
70
|
+
date: '2026-01-05',
|
|
71
|
+
tag: 'Components',
|
|
72
|
+
summary:
|
|
73
|
+
'Write your component once and use it everywhere. The same definition object that powers client rendering can be imported by the SSR server to produce identical markup.',
|
|
74
|
+
body: `
|
|
75
|
+
<p>In zQuery, a component is a plain JavaScript object with <code>state</code>,
|
|
76
|
+
<code>render()</code>, and optional lifecycle hooks. This simple contract means
|
|
77
|
+
the same file works on both sides:</p>
|
|
78
|
+
|
|
79
|
+
<pre><code>// components/greeting.js
|
|
80
|
+
export const greeting = {
|
|
81
|
+
state: () => ({ name: 'World' }),
|
|
82
|
+
render() {
|
|
83
|
+
return \`<h1>Hello, \${this.state.name}!</h1>\`;
|
|
84
|
+
}
|
|
85
|
+
};</code></pre>
|
|
86
|
+
|
|
87
|
+
<h4>Client</h4>
|
|
88
|
+
<pre><code>import { greeting } from './components/greeting.js';
|
|
89
|
+
$.component('greeting', greeting);</code></pre>
|
|
90
|
+
|
|
91
|
+
<h4>Server</h4>
|
|
92
|
+
<pre><code>import { greeting } from '../app/components/greeting.js';
|
|
93
|
+
app.component('greeting', greeting);
|
|
94
|
+
const html = await app.renderToString('greeting', { name: 'Tony' });</code></pre>
|
|
95
|
+
|
|
96
|
+
<p>No special file conventions, no build-time transforms. Just JavaScript
|
|
97
|
+
modules shared between environments.</p>
|
|
98
|
+
`,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
slug: 'ssr-caching-strategies',
|
|
102
|
+
title: 'Caching Strategies for SSR Pages',
|
|
103
|
+
date: '2026-01-18',
|
|
104
|
+
tag: 'Performance',
|
|
105
|
+
summary:
|
|
106
|
+
'Combine stale-while-revalidate headers, in-memory render caching, and CDN edge caching to serve SSR pages at static-site speed without sacrificing freshness.',
|
|
107
|
+
body: `
|
|
108
|
+
<p>SSR is powerful but adds per-request compute. Smart caching lets you keep
|
|
109
|
+
the dynamic benefits while serving at near-static speed.</p>
|
|
110
|
+
|
|
111
|
+
<h4>Layer 1: In-Memory Cache</h4>
|
|
112
|
+
<p>Cache rendered HTML in a <code>Map</code> keyed by route. Set a TTL
|
|
113
|
+
(e.g. 60 seconds) and serve cached responses until they expire. Simple and
|
|
114
|
+
effective for moderate traffic.</p>
|
|
115
|
+
|
|
116
|
+
<h4>Layer 2: HTTP Cache Headers</h4>
|
|
117
|
+
<pre><code>Cache-Control: public, s-maxage=60, stale-while-revalidate=300</code></pre>
|
|
118
|
+
<p>This tells CDNs to serve cached content for 60s, then revalidate in the
|
|
119
|
+
background for up to 5 minutes. Users always get a fast response.</p>
|
|
120
|
+
|
|
121
|
+
<h4>Layer 3: CDN Edge Caching</h4>
|
|
122
|
+
<p>Deploy behind a CDN (Cloudflare, Vercel Edge, Fastly) so cached pages are
|
|
123
|
+
served from the nearest edge node. Combine with geographic routing for
|
|
124
|
+
sub-100ms global TTFB.</p>
|
|
125
|
+
|
|
126
|
+
<h4>When to Skip Caching</h4>
|
|
127
|
+
<p>User-specific pages (dashboards, settings) shouldn't be edge-cached.
|
|
128
|
+
Use <code>Cache-Control: private</code> and rely on in-memory caching
|
|
129
|
+
or skip caching entirely for authenticated routes.</p>
|
|
130
|
+
`,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
/** Find a single post by slug. Returns undefined if not found. */
|
|
135
|
+
export function getPostBySlug(slug) {
|
|
136
|
+
return posts.find(p => p.slug === slug);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Return all posts (summary only — no body). */
|
|
140
|
+
export function getAllPosts() {
|
|
141
|
+
return posts.map(({ slug, title, date, tag, summary }) => ({
|
|
142
|
+
slug, title, date, tag, summary,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
@@ -17,9 +17,14 @@ import { createSSRApp } from 'zero-query/ssr';
|
|
|
17
17
|
// Shared component definitions - same ones the client registers
|
|
18
18
|
import { homePage } from '../app/components/home.js';
|
|
19
19
|
import { aboutPage } from '../app/components/about.js';
|
|
20
|
+
import { blogList } from '../app/components/blog/index.js';
|
|
21
|
+
import { blogPost } from '../app/components/blog/post.js';
|
|
20
22
|
import { notFound } from '../app/components/not-found.js';
|
|
21
23
|
import { routes } from '../app/routes.js';
|
|
22
24
|
|
|
25
|
+
// Server-side data — simulates a database or CMS
|
|
26
|
+
import { getAllPosts, getPostBySlug } from './data/posts.js';
|
|
27
|
+
|
|
23
28
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
24
29
|
const ROOT = join(__dirname, '..');
|
|
25
30
|
const PORT = parseInt(process.env.PORT || '3000', 10);
|
|
@@ -29,13 +34,107 @@ const PORT = parseInt(process.env.PORT || '3000', 10);
|
|
|
29
34
|
const app = createSSRApp();
|
|
30
35
|
app.component('home-page', homePage);
|
|
31
36
|
app.component('about-page', aboutPage);
|
|
37
|
+
app.component('blog-list', blogList);
|
|
38
|
+
app.component('blog-post', blogPost);
|
|
32
39
|
app.component('not-found', notFound);
|
|
33
40
|
|
|
34
41
|
// --- Route matching ---------------------------------------------------------
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Match a pathname to a route definition. Supports :param segments.
|
|
45
|
+
* Returns { component, params } or the not-found fallback.
|
|
46
|
+
*/
|
|
36
47
|
function matchRoute(pathname) {
|
|
37
|
-
const route
|
|
38
|
-
|
|
48
|
+
for (const route of routes) {
|
|
49
|
+
const paramNames = [];
|
|
50
|
+
const pattern = route.path.replace(/:(\w+)/g, (_, name) => {
|
|
51
|
+
paramNames.push(name);
|
|
52
|
+
return '([^/]+)';
|
|
53
|
+
});
|
|
54
|
+
const match = new RegExp(`^${pattern}$`).exec(pathname);
|
|
55
|
+
if (match) {
|
|
56
|
+
const params = {};
|
|
57
|
+
paramNames.forEach((name, i) => { params[name] = match[i + 1]; });
|
|
58
|
+
return { component: route.component, params };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { component: 'not-found', params: {} };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// --- Server-side data fetching ----------------------------------------------
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Fetch data for a matched route. This is where you'd query a database,
|
|
68
|
+
* call an API, or read from the filesystem in a real application.
|
|
69
|
+
* The returned object is passed as props to the component during SSR.
|
|
70
|
+
*/
|
|
71
|
+
function getPropsForRoute(component, params) {
|
|
72
|
+
switch (component) {
|
|
73
|
+
case 'blog-list':
|
|
74
|
+
return { posts: getAllPosts() };
|
|
75
|
+
case 'blog-post':
|
|
76
|
+
return { post: getPostBySlug(params.slug) || null };
|
|
77
|
+
default:
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- SEO metadata per route -------------------------------------------------
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Return page-specific metadata for SEO, social sharing, and browser tabs.
|
|
86
|
+
* The server injects these into the HTML shell's <head> before sending.
|
|
87
|
+
*
|
|
88
|
+
* In a real app you'd pull this from a CMS or database alongside the content.
|
|
89
|
+
* Open Graph tags ensure rich link previews on social media.
|
|
90
|
+
*/
|
|
91
|
+
function getMetaForRoute(component, params, props) {
|
|
92
|
+
const base = {
|
|
93
|
+
title: '{{NAME}}',
|
|
94
|
+
description: 'A zQuery SSR application.',
|
|
95
|
+
ogType: 'website',
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
switch (component) {
|
|
99
|
+
case 'home-page':
|
|
100
|
+
return {
|
|
101
|
+
...base,
|
|
102
|
+
title: '{{NAME}} — Home',
|
|
103
|
+
description: 'A server-rendered application built with zQuery. Fast first paint, SEO-friendly, zero dependencies.',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
case 'blog-list':
|
|
107
|
+
return {
|
|
108
|
+
...base,
|
|
109
|
+
title: 'Blog — {{NAME}}',
|
|
110
|
+
description: 'Articles on server-side rendering, hydration, shared components, and modern web architecture.',
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
case 'blog-post': {
|
|
114
|
+
const post = props.post;
|
|
115
|
+
if (!post) return { ...base, title: 'Post Not Found — {{NAME}}' };
|
|
116
|
+
return {
|
|
117
|
+
...base,
|
|
118
|
+
title: `${post.title} — {{NAME}}`,
|
|
119
|
+
description: post.summary,
|
|
120
|
+
ogType: 'article',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
case 'about-page':
|
|
125
|
+
return {
|
|
126
|
+
...base,
|
|
127
|
+
title: 'About — {{NAME}}',
|
|
128
|
+
description: 'Learn about zQuery — a zero-dependency frontend micro-library for reactive components, routing, SSR, and state management.',
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
title: 'Page Not Found — {{NAME}}',
|
|
135
|
+
description: 'The page you\'re looking for doesn\'t exist.',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
39
138
|
}
|
|
40
139
|
|
|
41
140
|
// --- Render a full HTML page ------------------------------------------------
|
|
@@ -50,20 +149,42 @@ async function getShell() {
|
|
|
50
149
|
}
|
|
51
150
|
|
|
52
151
|
async function render(pathname) {
|
|
53
|
-
const component = matchRoute(pathname);
|
|
54
|
-
const
|
|
152
|
+
const { component, params } = matchRoute(pathname);
|
|
153
|
+
const props = getPropsForRoute(component, params);
|
|
154
|
+
const meta = getMetaForRoute(component, params, props);
|
|
155
|
+
|
|
156
|
+
// SSR render — pass server-fetched data as props to the component
|
|
157
|
+
const body = await app.renderToString(component, props);
|
|
55
158
|
const shell = await getShell();
|
|
56
159
|
|
|
57
|
-
// Inject SSR content into <z-outlet …>
|
|
160
|
+
// Inject SSR content into <z-outlet …>
|
|
58
161
|
let html = shell.replace(/(<z-outlet[^>]*>)(<\/z-outlet>)?/, `$1${body}</z-outlet>`);
|
|
59
162
|
|
|
60
|
-
//
|
|
163
|
+
// Inject page-specific <title> and meta tags for SEO / social sharing
|
|
164
|
+
html = html.replace(/<title>[^<]*<\/title>/, `<title>${meta.title}</title>`);
|
|
165
|
+
html = html.replace(
|
|
166
|
+
/<meta name="description" content="[^"]*">/,
|
|
167
|
+
`<meta name="description" content="${meta.description}">`
|
|
168
|
+
);
|
|
169
|
+
html = html.replace(
|
|
170
|
+
/<meta property="og:title" content="[^"]*">/,
|
|
171
|
+
`<meta property="og:title" content="${meta.title}">`
|
|
172
|
+
);
|
|
173
|
+
html = html.replace(
|
|
174
|
+
/<meta property="og:description" content="[^"]*">/,
|
|
175
|
+
`<meta property="og:description" content="${meta.description}">`
|
|
176
|
+
);
|
|
177
|
+
html = html.replace(
|
|
178
|
+
/<meta property="og:type" content="[^"]*">/,
|
|
179
|
+
`<meta property="og:type" content="${meta.ogType}">`
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
// Embed server data so the client can hydrate without re-fetching.
|
|
183
|
+
// Also include meta so client can update document.title on navigation.
|
|
184
|
+
const ssrData = JSON.stringify({ component, params, props, meta });
|
|
61
185
|
html = html.replace(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
href === pathname
|
|
65
|
-
? `${before} active${after}`
|
|
66
|
-
: `${before}${after}`
|
|
186
|
+
'</head>',
|
|
187
|
+
`<script>window.__SSR_DATA__=${ssrData};</script>\n</head>`
|
|
67
188
|
);
|
|
68
189
|
|
|
69
190
|
return html;
|
|
@@ -100,6 +221,25 @@ createServer(async (req, res) => {
|
|
|
100
221
|
// Static assets (CSS, images, etc.)
|
|
101
222
|
if (pathname !== '/' && await serveStatic(res, pathname)) return;
|
|
102
223
|
|
|
224
|
+
// --- JSON API for client-side navigation ----------------------------------
|
|
225
|
+
// The client fetches data here when navigating via SPA (after initial SSR).
|
|
226
|
+
// In a real app, these would query a database or external API.
|
|
227
|
+
|
|
228
|
+
if (pathname === '/api/posts') {
|
|
229
|
+
const json = JSON.stringify(getAllPosts());
|
|
230
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
231
|
+
res.end(json);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const postMatch = /^\/api\/posts\/([^/]+)$/.exec(pathname);
|
|
236
|
+
if (postMatch) {
|
|
237
|
+
const post = getPostBySlug(postMatch[1]) || null;
|
|
238
|
+
res.writeHead(post ? 200 : 404, { 'Content-Type': 'application/json' });
|
|
239
|
+
res.end(JSON.stringify(post));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
103
243
|
// SSR route
|
|
104
244
|
try {
|
|
105
245
|
const html = await render(pathname);
|
package/dist/zquery.dist.zip
CHANGED
|
Binary file
|
package/dist/zquery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* zQuery (zeroQuery) v1.0.
|
|
2
|
+
* zQuery (zeroQuery) v1.0.2
|
|
3
3
|
* Lightweight Frontend Library
|
|
4
4
|
* https://github.com/tonywied17/zero-query
|
|
5
5
|
* (c) 2026 Anthony Wiedman - MIT License
|
|
@@ -3498,13 +3498,28 @@ class Component {
|
|
|
3498
3498
|
if (el.contains(e.target)) continue;
|
|
3499
3499
|
}
|
|
3500
3500
|
|
|
3501
|
-
// Key modifiers - filter keyboard events by key
|
|
3501
|
+
// Key modifiers - filter keyboard events by key.
|
|
3502
|
+
// Named shortcuts map common names to their e.key values.
|
|
3503
|
+
// Any modifier not recognised as a built-in behaviour, timing,
|
|
3504
|
+
// or system modifier is matched against e.key (case-insensitive)
|
|
3505
|
+
// so that arbitrary keys work: .a, .f1, .+, .0, .arrowup, etc.
|
|
3502
3506
|
const _keyMap = { enter: 'Enter', escape: 'Escape', tab: 'Tab', space: ' ', delete: 'Delete|Backspace', up: 'ArrowUp', down: 'ArrowDown', left: 'ArrowLeft', right: 'ArrowRight' };
|
|
3507
|
+
const _nonKeyMods = new Set(['prevent','stop','self','once','outside','capture','passive','debounce','throttle','ctrl','shift','alt','meta']);
|
|
3503
3508
|
let keyFiltered = false;
|
|
3504
|
-
for (
|
|
3509
|
+
for (let mi = 0; mi < modifiers.length; mi++) {
|
|
3510
|
+
const mod = modifiers[mi];
|
|
3505
3511
|
if (_keyMap[mod]) {
|
|
3506
3512
|
const keys = _keyMap[mod].split('|');
|
|
3507
3513
|
if (!e.key || !keys.includes(e.key)) { keyFiltered = true; break; }
|
|
3514
|
+
} else if (_nonKeyMods.has(mod)) {
|
|
3515
|
+
continue;
|
|
3516
|
+
} else if (/^\d+$/.test(mod) && mi > 0 && (modifiers[mi - 1] === 'debounce' || modifiers[mi - 1] === 'throttle')) {
|
|
3517
|
+
// Numeric value following debounce/throttle — skip (it's a ms parameter)
|
|
3518
|
+
continue;
|
|
3519
|
+
} else {
|
|
3520
|
+
// Dynamic key match — compare modifier against e.key
|
|
3521
|
+
// Case-insensitive: .a matches 'a' and 'A', .f1 matches 'F1'
|
|
3522
|
+
if (!e.key || e.key.toLowerCase() !== mod.toLowerCase()) { keyFiltered = true; break; }
|
|
3508
3523
|
}
|
|
3509
3524
|
}
|
|
3510
3525
|
if (keyFiltered) continue;
|
|
@@ -6189,9 +6204,9 @@ $.validate = validate;
|
|
|
6189
6204
|
$.formatError = formatError;
|
|
6190
6205
|
|
|
6191
6206
|
// --- Meta ------------------------------------------------------------------
|
|
6192
|
-
$.version = '1.0.
|
|
6193
|
-
$.libSize = '~
|
|
6194
|
-
$.unitTests = {"passed":
|
|
6207
|
+
$.version = '1.0.2';
|
|
6208
|
+
$.libSize = '~107 KB';
|
|
6209
|
+
$.unitTests = {"passed":1906,"failed":0,"total":1906,"suites":521,"duration":3744,"ok":true};
|
|
6195
6210
|
$.meta = {}; // populated at build time by CLI bundler
|
|
6196
6211
|
|
|
6197
6212
|
$.noConflict = () => {
|