Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ relevant tests and the formatting/lint checks in CONTRIBUTING.md before stopping
Report unavailable checks and failures accurately; a test summary followed by a
hung process is a failure.

Update the existing page or documentation migration for changed behavior. Add a
migration only for new documentation content.
Update the existing documentation page or its authored source under
`examples/official-site/content/` for changed behavior.

Build and preview the official site with the commands in its [README](./examples/official-site/README.md).
Update `configuration.md` for configuration changes.
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Architectural constraints and documentation maintenance rules are in
[AGENTS.md](./AGENTS.md).

Edit existing documentation in the [official site](./examples/official-site/) in place.
Deployment recreates the website's database from the site's SQL migrations.
Deployment recreates the website's database from the generated documentation
seed and the site's checked-in migrations.

Run `npm run site` to preview changes using the same site build as deployment.

Expand Down
10 changes: 7 additions & 3 deletions examples/official-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The SQLPage website is of course built with SQLPage !

Things that you may be interested to look at:
- The [custom component we use for our stylish home page](./sqlpage/templates/landing-page.handlebars)
- The [migrations](./sqlpage/migrations) that populate the database with the documentation for all components
- The [editable reference, examples, and articles](./content/) that populate the documentation
- The [advanced multistep form example](./examples/multistep-form/)

It is hosted as a simple Docker container on [sql-page.com](https://sql-page.com).
Expand All @@ -21,6 +21,10 @@ Run SQLPage from that directory, or run
`docker compose -f examples/official-site/docker-compose.yml up --build` from
the repository root.

The builder writes one documentation migration and its search index. SQLPage
loads it into in-memory SQLite at startup, along with the checked-in demo and
installation migrations.

Add `theme=light` or `theme=dark` to a component reference URL to preview its
live examples using SQLPage's stock theme. For example, visit
`/component.sql?component=form&theme=light`.
Expand Down Expand Up @@ -49,8 +53,8 @@ name. Keep the argument list in signature order and mark mandatory arguments wit
Component pages in `content/components/` list parameters under `top` and `row`.
Each `examples/*.md` file can contain `rows` in its YAML metadata. These rows
drive both the live preview and the copyable SQL. The Markdown body is the
example caption. Use numbered filenames to keep the examples in order.
References that have not moved still come from the SQL migrations.
example caption. The numeric filename prefix is the public anchor: `04-embed.md` is `#example-4`.
Keep existing numbers when adding or removing examples.

## Landing page

Expand Down
2 changes: 1 addition & 1 deletion examples/official-site/component.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ select 'dynamic' as component, json_array(
case when result is not null then json_object('component', 'docs-example', 'end_result', true)
else json_array() end
) as properties
from examples order by example_id;
from examples order by example_number;
36 changes: 36 additions & 0 deletions examples/official-site/content/categories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- id: display-data
title: Display data
sort_order: 1
- id: forms-and-feedback
title: Forms and feedback
sort_order: 2
- id: navigation
title: Navigation
sort_order: 3
- id: page-layout
title: Page layout and content
sort_order: 4
- id: http-responses
title: HTTP responses
sort_order: 5
- id: server-logic
title: Server logic
sort_order: 6
- id: request-data
title: Request data
sort_order: 1
- id: links-and-routing
title: Links and routing
sort_order: 2
- id: files-and-uploads
title: Files and uploads
sort_order: 3
- id: identity-and-security
title: Identity and security
sort_order: 4
- id: external-services
title: External services
sort_order: 5
- id: server-and-runtime
title: Server and runtime
sort_order: 6
56 changes: 0 additions & 56 deletions examples/official-site/sqlpage/migrations/01_documentation.sql

This file was deleted.

14 changes: 0 additions & 14 deletions examples/official-site/sqlpage/migrations/08_functions.sql

This file was deleted.

8 changes: 0 additions & 8 deletions examples/official-site/sqlpage/migrations/12_blog.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

69 changes: 0 additions & 69 deletions examples/official-site/sqlpage/migrations/82_reference_catalog.sql

This file was deleted.

12 changes: 9 additions & 3 deletions scripts/site/components.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function insertComponents(seed, content) {
}
}
});
// A component may still have a SQL-authored reference and Markdown examples.
// The foreign key on example.component checks each directory against the catalog.
const names = readdirSync(dir, { withFileTypes: true })
.filter((e) => e.isDirectory())
.map((e) => e.name)
Expand Down Expand Up @@ -84,16 +84,22 @@ function orderedJson(value) {
export function insertExamples(seed, name, dir) {
pages(
dir,
(_, meta, caption) => {
(file, meta, caption) => {
const number = Number(/^(\d+)-.+$/.exec(file)?.[1]);
if (!Number.isSafeInteger(number) || number < 1)
throw new Error(
"Expected a positive example number, such as 04-embed.md",
);
const { rows } = fields(meta, ["rows"]);
if (
rows !== undefined &&
(!Array.isArray(rows) || !rows.every((r) => r instanceof Map))
)
throw new Error("Expected a list of rows");
seed.row(
"INSERT INTO example (component, description, properties) VALUES (?, ?, ?)",
"INSERT INTO example (component, example_number, description, properties) VALUES (?, ?, ?, ?)",
name,
number,
caption,
rows === undefined ? null : orderedJson(rows),
);
Expand Down
11 changes: 11 additions & 0 deletions scripts/site/directories.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { resolve } from "node:path";
import { collection, fields, text } from "./content.mjs";

export function insertDirectories(seed, content) {
collection(content, "categories.yaml", (item) => {
const c = fields(item, ["id", "title", "sort_order"]);
if (!Number.isSafeInteger(c.sort_order))
throw new Error("Expected an integer sort_order");
seed.row(
"INSERT INTO reference_category (id, title, sort_order) VALUES (?, ?, ?)",
text(c.id, "id"),
text(c.title, "title"),
c.sort_order,
);
});
collection(content, "guides.yaml", (item) => {
const g = fields(item, ["sort_order", "title", "link", "description"]);
if (!Number.isSafeInteger(g.sort_order))
Expand Down
23 changes: 6 additions & 17 deletions scripts/site/documentation.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { DatabaseSync } from "node:sqlite";
import { insertComponents } from "./components.mjs";
Expand Down Expand Up @@ -58,27 +58,16 @@ export function insertPosts(seed, dir) {
export function writeDocumentation(content, migrations) {
const db = new DatabaseSync(":memory:");
try {
// The generated rows go after the old content tables and before the search index.
const version = 100;
const files = readdirSync(migrations)
.filter((f) => f.endsWith(".sql") && !f.endsWith(".down.sql"))
.sort((a, b) => Number.parseInt(a, 10) - Number.parseInt(b, 10));
for (const file of files) {
const n = Number.parseInt(file, 10);
if (n === version)
throw new Error(`Migration ${version} is reserved: ${file}`);
if (n < version) db.exec(readFileSync(join(migrations, file), "utf8"));
}
const seed = new Seed(db);
seed.script(readFileSync(new URL("./schema.sql", import.meta.url), "utf8"));
insertDirectories(seed, content);
insertPosts(seed, join(content, "blog"));
insertComponents(seed, content);
insertFunctions(seed, join(content, "functions"));
writeFileSync(
join(migrations, `${version}_documentation_content.sql`),
seed.toString(),
{ flag: "wx" },
);
seed.script(readFileSync(new URL("./search.sql", import.meta.url), "utf8"));
writeFileSync(join(migrations, "01_documentation.sql"), seed.toString(), {
flag: "wx",
});
} finally {
db.close();
}
Expand Down
Loading
Loading