create-spacepress 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +35 -2
- package/bin/create-spacepress.mjs +116 -0
- package/package.json +14 -4
- package/template/.editorconfig +9 -0
- package/template/.vscode/settings.json +4 -0
- package/template/README.md +39 -0
- package/template/content/notes/first-walk.md +11 -0
- package/template/content/notes/what-to-pack.md +13 -0
- package/template/gitignore +13 -0
- package/template/sp/actions.ts +10 -0
- package/template/sp/app/account/page.tsx +15 -0
- package/template/sp/app/layout.tsx +28 -0
- package/template/sp/app/not-found.tsx +12 -0
- package/template/sp/app/notes/[slug]/page.tsx +15 -0
- package/template/sp/app/notes/page.tsx +28 -0
- package/template/sp/app/page.tsx +34 -0
- package/template/sp/app/site.css +85 -0
- package/template/spacepress.config.ts +26 -0
- package/template/tsconfig.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Spacefast
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `create-spacepress`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffold a ready-to-run **SpacePress** (`spacepress.dev`) project with TypeScript schemas, sample Markdown content, server-rendered TSX pages, a progressive form action, and coding-agent setup — running on local WordPress with zero Docker or Rust setup.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- **Node.js 22+** and npm
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create spacepress@0.3.1 my-app
|
|
13
|
+
cd my-app
|
|
14
|
+
npm run dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Pass `-- --no-install` to create the directory without running `npm install`:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm create spacepress@0.3.1 my-app -- --no-install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Existing destination directories are never overwritten.
|
|
24
|
+
|
|
25
|
+
## What Gets Created
|
|
26
|
+
|
|
27
|
+
- `spacepress.config.ts` — defines a synced `notes` WordPress collection (`/notes/:slug`) and a `site` global
|
|
28
|
+
- `sp/actions.ts` — a sample server action (`greet`) compiled to PHP
|
|
29
|
+
- `sp/app/` — root `layout.tsx`, `page.tsx` with `<form action={greet}>` and `useFormState()`, dynamic `notes/[slug]/page.tsx`, `account/`, `not-found.tsx`, and `site.css`
|
|
30
|
+
- `content/notes/` — sample Markdown notes synced into WordPress
|
|
31
|
+
- `AGENTS.md`, `.mcp.json`, and skills — generated automatically by `spacepress init` for AI coding agents
|
|
32
|
+
- `package.json` scripts: `dev`, `build`, `check`, `typecheck`, `stop`, `status`, and `wp`
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { cp, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const metadata = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
7
|
+
const help = `Create SpacePress ${metadata.version}\n\nUsage: npm create spacepress@${metadata.version} <directory> [-- --no-install] [-- --dir <app-dir>]\n\nCreates a starter site with pages and sample content, served by WordPress. Installs npm dependencies\nunless --no-install is supplied, then writes AGENTS.md, .mcp.json and skills for coding\nagents (spacepress init). Existing destinations are never overwritten.\n\nOptions:\n --dir <folder> App directory inside the project (default: sp)\n --no-install Skip npm install\n\nNext: cd <directory> && npm run dev\nRequires Node.js 22+ and npm. No Rust toolchain or Docker required.\n`;
|
|
8
|
+
|
|
9
|
+
// The files a coding agent reads (AGENTS.md, .mcp.json, the skills) come from `spacepress init`, so a new
|
|
10
|
+
// project gets the same ones a later `spacepress init` writes, generated from its own config. The
|
|
11
|
+
// compiler is the one npm just installed, or SP_BIN when the install was skipped.
|
|
12
|
+
async function agentFiles(destination, installed) {
|
|
13
|
+
const first = installed ? join(destination, 'node_modules/.bin', process.platform === 'win32' ? 'spacepress.cmd' : 'spacepress')
|
|
14
|
+
: isAbsolute(process.env.SP_BIN ?? '') ? process.env.SP_BIN : null;
|
|
15
|
+
if (!first) return false;
|
|
16
|
+
return new Promise((done) => {
|
|
17
|
+
const child = spawn(first, ['init', destination], { stdio: ['ignore', 'ignore', 'inherit'], shell: process.platform === 'win32' });
|
|
18
|
+
child.once('error', () => done(false)); child.once('exit', (code) => done(code === 0));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
const args = process.argv.slice(2).filter((arg) => arg !== '--');
|
|
24
|
+
if (args.length === 1 && ['--version', '-v'].includes(args[0])) { process.stdout.write(`${metadata.version}\n`); return; }
|
|
25
|
+
if (!args.length || args.includes('--help') || args.includes('-h')) { process.stdout.write(help); return; }
|
|
26
|
+
let noInstall = false;
|
|
27
|
+
let appDir = 'sp';
|
|
28
|
+
const directories = [];
|
|
29
|
+
for (let i = 0; i < args.length; i++) {
|
|
30
|
+
const arg = args[i];
|
|
31
|
+
if (arg === '--no-install') {
|
|
32
|
+
noInstall = true;
|
|
33
|
+
} else if (arg === '--dir') {
|
|
34
|
+
const value = args[++i];
|
|
35
|
+
if (!value || value.startsWith('-')) throw new Error('--dir requires a relative folder name (e.g. --dir cms)');
|
|
36
|
+
appDir = value;
|
|
37
|
+
} else if (arg.startsWith('--dir=')) {
|
|
38
|
+
appDir = arg.slice('--dir='.length);
|
|
39
|
+
} else if (arg.startsWith('-')) {
|
|
40
|
+
throw new Error(help);
|
|
41
|
+
} else {
|
|
42
|
+
directories.push(arg);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (directories.length !== 1) throw new Error(help);
|
|
46
|
+
if (!appDir || appDir.startsWith('/') || appDir.endsWith('/') || appDir.includes('\\') || appDir.split('/').some((s) => !s || s === '.' || s === '..' || s.startsWith('.') || s === 'node_modules') || ['public', 'emails'].includes(appDir.split('/')[0])) {
|
|
47
|
+
throw new Error(`Invalid --dir "${appDir}": use a clean relative folder name like "sp" or "cms".`);
|
|
48
|
+
}
|
|
49
|
+
const destination = resolve(directories[0]);
|
|
50
|
+
const name = basename(destination).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
51
|
+
if (!name || name.length > 100 || ['node-modules', 'favicon-ico'].includes(name)) throw new Error('Choose a directory name containing letters or numbers (at most 100 characters).');
|
|
52
|
+
try { await mkdir(destination); }
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.code === 'EEXIST') throw new Error(`Destination already exists: ${destination}. Choose a new directory; nothing was overwritten.`);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const template = new URL('../template/', import.meta.url);
|
|
59
|
+
for (const entry of await readdir(template)) {
|
|
60
|
+
await cp(new URL(entry, template), join(destination, entry), { recursive: true, force: false, errorOnExist: true });
|
|
61
|
+
}
|
|
62
|
+
await rename(join(destination, 'gitignore'), join(destination, '.gitignore'));
|
|
63
|
+
if (appDir !== 'sp') {
|
|
64
|
+
const targetDir = join(destination, appDir);
|
|
65
|
+
await mkdir(resolve(targetDir, '..'), { recursive: true });
|
|
66
|
+
await rename(join(destination, 'sp'), targetDir);
|
|
67
|
+
for (const file of ['.gitignore', 'tsconfig.json', 'README.md']) {
|
|
68
|
+
const p = join(destination, file);
|
|
69
|
+
const text = await readFile(p, 'utf8');
|
|
70
|
+
await writeFile(
|
|
71
|
+
p,
|
|
72
|
+
text
|
|
73
|
+
.replaceAll('sp/dist', `${appDir}/dist`)
|
|
74
|
+
.replaceAll('sp/_generated', `${appDir}/_generated`)
|
|
75
|
+
.replaceAll('./sp/_generated', `./${appDir}/_generated`)
|
|
76
|
+
.replaceAll('sp/app', `${appDir}/app`)
|
|
77
|
+
.replaceAll('"sp"', JSON.stringify(appDir))
|
|
78
|
+
.replaceAll('`sp/`', `\`${appDir}/\``),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const cfgPath = join(destination, 'spacepress.config.ts');
|
|
82
|
+
const cfg = await readFile(cfgPath, 'utf8');
|
|
83
|
+
await writeFile(
|
|
84
|
+
cfgPath,
|
|
85
|
+
cfg.replace('name: "__SP_APP_NAME__",', `name: "__SP_APP_NAME__",\n dir: ${JSON.stringify(appDir)},`),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
for (const file of ['spacepress.config.ts', 'README.md']) {
|
|
89
|
+
const path = join(destination, file);
|
|
90
|
+
await writeFile(path, (await readFile(path, 'utf8')).replaceAll('__SP_APP_NAME__', name));
|
|
91
|
+
}
|
|
92
|
+
await writeFile(join(destination, 'package.json'), JSON.stringify({
|
|
93
|
+
name, version: '0.0.0', private: true, type: 'module', engines: { node: '>=22' },
|
|
94
|
+
scripts: {
|
|
95
|
+
dev: 'spacepress dev', build: 'spacepress build', check: 'spacepress check',
|
|
96
|
+
typecheck: 'spacepress build --quiet && tsc --noEmit',
|
|
97
|
+
stop: 'spacepress dev stop', status: 'spacepress dev status', wp: 'spacepress wp',
|
|
98
|
+
},
|
|
99
|
+
devDependencies: { 'spacepress': process.env.SP_CLI_PACKAGE || metadata.version, '@types/node': '22.19.17', typescript: '5.9.3' },
|
|
100
|
+
}, null, 2) + '\n', { flag: 'wx' });
|
|
101
|
+
} catch (error) {
|
|
102
|
+
await rm(destination, { recursive: true });
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
if (!noInstall) {
|
|
106
|
+
const code = await new Promise((done, fail) => {
|
|
107
|
+
const child = spawn(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install', '--include=dev', '--no-audit', '--no-fund'], { cwd: destination, stdio: 'inherit' });
|
|
108
|
+
child.once('error', fail); child.once('exit', (code) => done(code));
|
|
109
|
+
});
|
|
110
|
+
if (code !== 0) throw new Error(`App created at ${destination}, but npm install failed. Fix the reported download/tool error, then run npm install there. Your app was preserved.`);
|
|
111
|
+
}
|
|
112
|
+
const agents = await agentFiles(destination, !noInstall);
|
|
113
|
+
process.stdout.write(`\nCreated ${name}.\n\n cd ${JSON.stringify(directories[0])}\n${noInstall ? ' npm install\n' : ''}${agents ? '' : ' npx spacepress init # AGENTS.md, .mcp.json and skills for coding agents\n'} npm run dev\n\nOpen the Website URL printed by SpacePress.\nStart by editing ${appDir}/app/page.tsx. See README.md for the other starter files.\n${agents ? 'AGENTS.md, .mcp.json and the agent skills describe this project to coding agents; run npx spacepress init after changing the config.\n' : ''}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
main().catch((error) => { process.stderr.write(`create-spacepress: ${error.message}\n`); process.exitCode = 1; });
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-spacepress",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Create a SpacePress site with pages, sample content and a form, running on local WordPress",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/spacefast/spacepress/tree/main/packages/create-spacepress#readme",
|
|
8
|
+
"bugs": "https://github.com/spacefast/spacepress/issues",
|
|
9
|
+
"keywords": ["spacepress", "wordpress", "create", "scaffold"],
|
|
10
|
+
"engines": { "node": ">=22" },
|
|
11
|
+
"bin": { "create-spacepress": "bin/create-spacepress.mjs" },
|
|
12
|
+
"files": ["bin", "template", "LICENSE", "README.md"],
|
|
13
|
+
"scripts": { "prepack": "node ../cli/scripts/prepare-scaffolder.mjs", "test": "node --test test/*.test.mjs" },
|
|
14
|
+
"repository": { "type": "git", "url": "https://github.com/spacefast/spacepress.git", "directory": "packages/create-spacepress" },
|
|
15
|
+
"publishConfig": { "access": "public" }
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# __SP_APP_NAME__
|
|
2
|
+
|
|
3
|
+
A **SpacePress** (`spacepress.dev`) application compiled from TypeScript into native PHP and WordPress plugins.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Open the website URL printed in your terminal, and visit `/wp-admin/new/` for SpacePress Admin. Edit `sp/app/page.tsx` or `spacepress.config.ts` and save — the page reloads automatically when SpacePress finishes rebuilding.
|
|
12
|
+
|
|
13
|
+
## Project Files
|
|
14
|
+
|
|
15
|
+
- `spacepress.config.ts` — schema definitions (`notes` collection, `site` global) and app config
|
|
16
|
+
- `sp/actions.ts` — server actions compiled to native PHP endpoints
|
|
17
|
+
- `sp/app/` — file-based TSX pages, layouts, and `site.css`
|
|
18
|
+
- `content/notes/` — Markdown notes synchronized with WordPress via `npx spacepress sync`
|
|
19
|
+
- `sp/_generated/` — compiler-emitted `db.d.ts`, `routes.d.ts`, migrations, OpenAPI spec, and typed client
|
|
20
|
+
|
|
21
|
+
## Useful Scripts
|
|
22
|
+
|
|
23
|
+
| Script | What it does |
|
|
24
|
+
|---|---|
|
|
25
|
+
| `npm run dev` | Start local WordPress + SQLite and rebuild on change |
|
|
26
|
+
| `npm run stop` | Stop the local dev server while preserving data |
|
|
27
|
+
| `npm run status` | Check local dev server status |
|
|
28
|
+
| `npm run check` | Validate schemas, handlers, and pages without writing output |
|
|
29
|
+
| `npm run typecheck` | Run `spacepress build --quiet && tsc --noEmit` |
|
|
30
|
+
| `npm run build` | Emit WordPress plugins to `sp/dist/wp-content/plugins/` |
|
|
31
|
+
| `npm run wp -- <args>` | Run any WP-CLI command against the local site |
|
|
32
|
+
|
|
33
|
+
## Next Steps
|
|
34
|
+
|
|
35
|
+
- Sync Markdown content: `npx spacepress sync`
|
|
36
|
+
- Add a WooCommerce storefront: `npx spacepress add shop`
|
|
37
|
+
- Add SQL tables: `npx spacepress add db`
|
|
38
|
+
- Add OpenAPI docs at `/api`: `npx spacepress add api-reference`
|
|
39
|
+
- Read the [SpacePress Interactive Guide](https://spacepress.dev/guide)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
uid: zr_d2c870c681684da0b234
|
|
3
|
+
title: A first walk
|
|
4
|
+
slug: first-walk
|
|
5
|
+
summary: A short loop to get to know your neighborhood.
|
|
6
|
+
status: published
|
|
7
|
+
publishedAt: 2026-01-12T12:00:00.000Z
|
|
8
|
+
---
|
|
9
|
+
Take the long way to the corner shop. Pick a street you usually pass and write down one detail you would miss from a car.
|
|
10
|
+
|
|
11
|
+
Bring the same notebook next week and see what changed.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
uid: zr_18b72eeb581242eb84db
|
|
3
|
+
title: What to pack
|
|
4
|
+
slug: what-to-pack
|
|
5
|
+
summary: A few things to keep in your bag for a walk.
|
|
6
|
+
status: published
|
|
7
|
+
publishedAt: 2026-01-13T12:00:00.000Z
|
|
8
|
+
---
|
|
9
|
+
- A notebook and a pencil
|
|
10
|
+
- Water
|
|
11
|
+
- A layer for the walk home
|
|
12
|
+
|
|
13
|
+
Leave a little room for anything you find along the way.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
.sp/
|
|
3
|
+
.env
|
|
4
|
+
.env.*
|
|
5
|
+
!.env.example
|
|
6
|
+
.DS_Store
|
|
7
|
+
*.log
|
|
8
|
+
|
|
9
|
+
# sp/_generated/ is committed; sp/dist/ is build output.
|
|
10
|
+
sp/dist/
|
|
11
|
+
# @spacepress/frontend's build lock and staging, while a build runs.
|
|
12
|
+
sp/_generated/.spacepress-*-lock*
|
|
13
|
+
sp/_generated/.spacepress-*-build-*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mutation } from "spacepress";
|
|
2
|
+
import { HttpError } from "spacepress/server";
|
|
3
|
+
|
|
4
|
+
// The server validates input before calling the handler.
|
|
5
|
+
export const greet = mutation({ access: "anyone" }, ({ name }: { name: string }) => {
|
|
6
|
+
if (name.length < 1 || name.length > 60) {
|
|
7
|
+
throw new HttpError(422, "invalid_input", "name must be 1 to 60 characters", "/name");
|
|
8
|
+
}
|
|
9
|
+
return { message: `Hello, ${name}!` };
|
|
10
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { home_url } from "spacepress/server/wp";
|
|
2
|
+
|
|
3
|
+
// WordPress signs visitors in and returns them here.
|
|
4
|
+
export const guard = "authenticated";
|
|
5
|
+
export const metadata = { title: "Account", robots: { index: false } };
|
|
6
|
+
|
|
7
|
+
export default function Account() {
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<h1>Account</h1>
|
|
11
|
+
<p>You're signed in to WordPress.</p>
|
|
12
|
+
<p><a href={home_url("/wp-admin/")}>Open WordPress admin</a></p>
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { db } from "spacepress/server";
|
|
2
|
+
import { Link, type LayoutProps } from "spacepress/app";
|
|
3
|
+
import "./site.css";
|
|
4
|
+
|
|
5
|
+
// Use a blank WordPress block template so this layout owns the header and footer.
|
|
6
|
+
export const template = "blank";
|
|
7
|
+
// The browser title follows the site name an editor sets in Site settings, as the header does.
|
|
8
|
+
export const metadata = async () => {
|
|
9
|
+
const site = await db.globals.site.get();
|
|
10
|
+
return { title: { default: site.name, template: `%s · ${site.name}` } };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default async function Layout({ children }: LayoutProps) {
|
|
14
|
+
const site = await db.globals.site.get();
|
|
15
|
+
return (
|
|
16
|
+
<div className="site">
|
|
17
|
+
<header className="masthead">
|
|
18
|
+
<Link className="brand" href="/">{site.name}</Link>
|
|
19
|
+
<nav aria-label="Site">
|
|
20
|
+
<Link href="/notes">Notes</Link>
|
|
21
|
+
<Link href="/account">Account</Link>
|
|
22
|
+
</nav>
|
|
23
|
+
</header>
|
|
24
|
+
<main>{children}</main>
|
|
25
|
+
<footer>Built with <a href="https://spacepress.dev">SpacePress</a></footer>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Link } from "spacepress/app";
|
|
2
|
+
|
|
3
|
+
export const metadata = { title: "Page not found" };
|
|
4
|
+
|
|
5
|
+
export default function NotFound() {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<h1>Page not found</h1>
|
|
9
|
+
<p><Link href="/notes">Browse the notes</Link> or <Link href="/">return home</Link>.</p>
|
|
10
|
+
</>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Content, Link } from "spacepress/app";
|
|
2
|
+
import type { PageProps } from "./$types";
|
|
3
|
+
|
|
4
|
+
// SpacePress supplies the note for this slug. Missing notes use not-found.tsx.
|
|
5
|
+
export const metadata = ({ item }: PageProps) => ({ title: item.title });
|
|
6
|
+
|
|
7
|
+
export default function Note({ item }: PageProps) {
|
|
8
|
+
return (
|
|
9
|
+
<article>
|
|
10
|
+
<p><Link href="/notes">← All notes</Link></p>
|
|
11
|
+
<h1>{item.title}</h1>
|
|
12
|
+
<Content value={item.body} />
|
|
13
|
+
</article>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { db } from "spacepress/server";
|
|
2
|
+
import { Link } from "spacepress/app";
|
|
3
|
+
|
|
4
|
+
export const metadata = { title: "Notes" };
|
|
5
|
+
|
|
6
|
+
export default async function Notes() {
|
|
7
|
+
// Page queries use the current visitor's access rules.
|
|
8
|
+
const notes = await db.query.notes.findMany({
|
|
9
|
+
columns: { title: true, slug: true, summary: true },
|
|
10
|
+
orderBy: { publishedAt: "desc" },
|
|
11
|
+
limit: 20,
|
|
12
|
+
});
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<h1>Notes</h1>
|
|
16
|
+
<p>These entries started as Markdown files in <code>content/notes/</code>.</p>
|
|
17
|
+
{notes.length === 0 && <p>No notes have been published yet.</p>}
|
|
18
|
+
<ul className="notes">
|
|
19
|
+
{notes.map((note) => (
|
|
20
|
+
<li>
|
|
21
|
+
<h2><Link href={`/notes/${note.slug}`}>{note.title}</Link></h2>
|
|
22
|
+
{note.summary && <p>{note.summary}</p>}
|
|
23
|
+
</li>
|
|
24
|
+
))}
|
|
25
|
+
</ul>
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { db } from "spacepress/server";
|
|
2
|
+
import { Link, useFormState } from "spacepress/app";
|
|
3
|
+
import { greet } from "../actions";
|
|
4
|
+
|
|
5
|
+
export default async function Home() {
|
|
6
|
+
const latest = await db.query.notes.findFirst({
|
|
7
|
+
columns: { title: true, slug: true },
|
|
8
|
+
orderBy: { publishedAt: "desc" },
|
|
9
|
+
});
|
|
10
|
+
// The action returns to this page with a result or a validation error.
|
|
11
|
+
const state = useFormState(greet);
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<section className="hero">
|
|
15
|
+
<h1>Make this site yours.</h1>
|
|
16
|
+
<p>Edit <code>sp/app/page.tsx</code> and refresh this page to see your change.</p>
|
|
17
|
+
<Link className="button" href="/notes">Browse the notes <span aria-hidden="true">→</span></Link>
|
|
18
|
+
{latest && <p>Latest note: <Link href={`/notes/${latest.slug}`}>{latest.title}</Link></p>}
|
|
19
|
+
</section>
|
|
20
|
+
<section className="greeting">
|
|
21
|
+
<h2>Say hello</h2>
|
|
22
|
+
<form action={greet}>
|
|
23
|
+
<label htmlFor="name">Your name</label>
|
|
24
|
+
<div className="form-row">
|
|
25
|
+
<input id="name" name="name" defaultValue={state.values.name ?? ""} required maxLength={60} />
|
|
26
|
+
<button type="submit">Say hello</button>
|
|
27
|
+
</div>
|
|
28
|
+
</form>
|
|
29
|
+
{state.result && <p role="status">{state.result.message}</p>}
|
|
30
|
+
{state.error && <p role="alert">{state.error.fields.name ?? state.error.message}</p>}
|
|
31
|
+
</section>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
background: #faf8f2;
|
|
4
|
+
color: #192e27;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.site {
|
|
8
|
+
--accent: #1a563f;
|
|
9
|
+
--line: #d6dbcd;
|
|
10
|
+
max-width: 52rem;
|
|
11
|
+
min-height: 100vh;
|
|
12
|
+
margin-inline: auto;
|
|
13
|
+
padding-inline: clamp(1rem, 5vw, 3rem);
|
|
14
|
+
display: grid;
|
|
15
|
+
grid-template-rows: auto 1fr auto;
|
|
16
|
+
font: 1.125rem/1.65 system-ui, sans-serif;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.site a {
|
|
20
|
+
color: var(--accent);
|
|
21
|
+
text-underline-offset: 0.2em;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.masthead {
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: baseline;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
flex-wrap: wrap;
|
|
29
|
+
gap: 0.5rem 2rem;
|
|
30
|
+
padding-block: 1.25rem;
|
|
31
|
+
border-bottom: 1px solid var(--line);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.masthead nav { display: flex; gap: 1.25rem; }
|
|
35
|
+
.masthead a { text-decoration: none; }
|
|
36
|
+
.masthead a:hover { text-decoration: underline; }
|
|
37
|
+
.brand { font: bold 1.5rem Georgia, serif; }
|
|
38
|
+
|
|
39
|
+
.site main { padding-block: clamp(2.5rem, 7vw, 5rem); }
|
|
40
|
+
.site footer { border-top: 1px solid var(--line); padding-block: 1rem; font-size: 0.9rem; }
|
|
41
|
+
.site p { max-width: 62ch; }
|
|
42
|
+
.site h1, .site h2 { font-family: Georgia, serif; line-height: 1.1; }
|
|
43
|
+
.site h1 { font-size: clamp(2.75rem, 8vw, 5rem); letter-spacing: -0.05em; margin: 0 0 1rem; }
|
|
44
|
+
.site h2 { font-size: 1.75rem; margin-top: 0; }
|
|
45
|
+
.site code { font-size: 0.9em; overflow-wrap: anywhere; }
|
|
46
|
+
|
|
47
|
+
.greeting {
|
|
48
|
+
max-width: 28rem;
|
|
49
|
+
margin-top: 3rem;
|
|
50
|
+
padding: 1.5rem;
|
|
51
|
+
border: 1px solid var(--line);
|
|
52
|
+
border-radius: 0.75rem;
|
|
53
|
+
background: #fffdf7;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.form-row { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 0.4rem; }
|
|
57
|
+
.greeting input {
|
|
58
|
+
flex: 1;
|
|
59
|
+
min-width: min(100%, 10rem);
|
|
60
|
+
padding: 0.55rem 0.75rem;
|
|
61
|
+
border: 1px solid #68766d;
|
|
62
|
+
border-radius: 0.4rem;
|
|
63
|
+
color: inherit;
|
|
64
|
+
font: inherit;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.site .button, .site button {
|
|
68
|
+
display: inline-block;
|
|
69
|
+
padding: 0.55rem 1rem;
|
|
70
|
+
border: 1px solid transparent;
|
|
71
|
+
border-radius: 0.4rem;
|
|
72
|
+
background: var(--accent);
|
|
73
|
+
color: white;
|
|
74
|
+
font: inherit;
|
|
75
|
+
font-weight: 600;
|
|
76
|
+
text-decoration: none;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.site .button:hover, .site button:hover { background: #113b2b; }
|
|
81
|
+
.site :focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
|
|
82
|
+
.notes { padding: 0; list-style: none; }
|
|
83
|
+
.notes li { border-top: 1px solid var(--line); padding-block: 1.25rem; }
|
|
84
|
+
.notes h2, .notes p { margin: 0; }
|
|
85
|
+
.notes p { margin-top: 0.5rem; }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { collection, defineConfig, global, richText, slug, text } from "spacepress";
|
|
2
|
+
|
|
3
|
+
// Each note is a WordPress post. The URL binds it to the matching [slug] page.
|
|
4
|
+
export const notes = collection({
|
|
5
|
+
title: text().min(1).max(120),
|
|
6
|
+
slug: slug({ source: "title" }).optional(),
|
|
7
|
+
summary: text().max(200).optional(),
|
|
8
|
+
body: richText().optional(),
|
|
9
|
+
}, {
|
|
10
|
+
label: "Notes",
|
|
11
|
+
title: "title",
|
|
12
|
+
content: "body",
|
|
13
|
+
url: "/notes/:slug",
|
|
14
|
+
sync: "content/notes/*.md",
|
|
15
|
+
access: { read: "anyone", create: "editor", update: "editor", delete: "editor" },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// A global stores one set of editable options for the whole site.
|
|
19
|
+
export const site = global({
|
|
20
|
+
name: text().default("Field Notes"),
|
|
21
|
+
}, { label: "Site settings" });
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
name: "__SP_APP_NAME__",
|
|
25
|
+
seed: true,
|
|
26
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"allowImportingTsExtensions": true,
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"jsxImportSource": "spacepress",
|
|
11
|
+
"rootDirs": [".", "./sp/_generated/types"],
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
"paths": {
|
|
14
|
+
"react": ["./node_modules/spacepress/types/react-shim.d.ts"]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"include": ["spacepress.config.ts", "*.client.ts", "sp"],
|
|
18
|
+
"exclude": ["sp/dist"]
|
|
19
|
+
}
|