diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 496277efa..4c18cf074 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,7 @@ jobs: shared-key: rust-sqlpage-proj-test save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo fmt --all -- --check + - run: cargo test --locked --features config-schema --test mod configuration_docs - run: cargo clippy --all-targets --all-features -- -D warnings # The database matrix below runs the same Rust test harnesses against # different DATABASE_URL values. Package the Linux test executables once diff --git a/CHANGELOG.md b/CHANGELOG.md index 180a01640..e9ace4e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +- Each `login` component’s labels target its own fields. Set `false AS autofocus` to keep the username field from taking focus when the page opens. +- The official documentation now connects tutorials, component examples, and the function reference through shared navigation. Browse by task, open search with Ctrl+K or ⌘K, and share a link to a specific parameter. Code blocks have copy controls. Wide examples show SQL beside the live result. - JSON `shell` menu items with a link are now links in the accessibility tree instead of being announced as buttons; only submenu toggles keep `role="button"`. - The new [`status_bar` component](https://sql-page.com/component.sql?component=status_bar) displays short status messages and links along the bottom of the screen or inline with page content. - A file input with `multiple` now keeps every selected file, instead of only the last one. The new [`sqlpage.persist_uploaded_files`](https://sql-page.com/functions.sql?function=persist_uploaded_files) function saves them all and returns a JSON array with the `path`, original `name`, `mime_type` and `size` of each file. diff --git a/Cargo.lock b/Cargo.lock index 565cc9428..15c5167d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4210,10 +4210,23 @@ checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e" dependencies = [ "dyn-clone", "ref-cast", + "schemars_derive", "serde", "serde_json", ] +[[package]] +name = "schemars_derive" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1c3a92094fa7d61aa124645844facb6b554dfc797136d0f5fd1f890e2bffc69" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 3.0.10", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -4315,6 +4328,17 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "serde_derive_internals" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f852137cce035d6a4df67ccce505ff6b3e9fd3a10e3e52b24dc71e650bb1a9bd" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "serde_json" version = "1.0.154" @@ -4630,6 +4654,7 @@ dependencies = [ "rustls", "rustls-acme", "rustls-native-certs", + "schemars 1.2.3", "serde", "serde_json", "sha2 0.11.1", diff --git a/Cargo.toml b/Cargo.toml index d5c3b4fa8..94a2789cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ tokio = { version = "1.24.1", features = ["macros", "rt", "process", "sync"] } tokio-stream = "0.1.9" anyhow = "1" serde = "1" +schemars = { version = "1", optional = true } serde_json = { version = "1.0.82", features = [ "preserve_order", "raw_value", @@ -137,6 +138,7 @@ opentelemetry-semantic-conventions = { version = "0.33", features = ["semconv_ex [features] default = [] +config-schema = ["dep:schemars"] odbc-static = ["odbc-sys", "odbc-sys/vendored-unix-odbc"] lambda-web = [ "dep:actix-http", @@ -151,3 +153,7 @@ actix-http = "3" tempfile = "3" tokio = { version = "1", features = ["rt", "time", "test-util"] } +[[example]] +name = "export_config_schema" +required-features = ["config-schema"] + diff --git a/examples/export_config_schema.rs b/examples/export_config_schema.rs new file mode 100644 index 000000000..3101475b3 --- /dev/null +++ b/examples/export_config_schema.rs @@ -0,0 +1,15 @@ +use schemars::generate::SchemaSettings; +use sqlpage::app_config::AppConfig; +use std::io::{self, Write}; + +fn main() -> anyhow::Result<()> { + let settings = + SchemaSettings::draft2020_12().with(|settings| settings.inline_subschemas = true); + let schema = settings + .into_generator() + .into_root_schema_for::(); + let mut stdout = io::stdout().lock(); + serde_json::to_writer_pretty(&mut stdout, &schema)?; + writeln!(stdout)?; + Ok(()) +} diff --git a/examples/official-site/404.sql b/examples/official-site/404.sql index a788a9055..d2b083a32 100644 --- a/examples/official-site/404.sql +++ b/examples/official-site/404.sql @@ -1,6 +1,6 @@ select 'status_code' as component, 404 as status; select 'http_header' as component, 'no-store, max-age=0' as "Cache-Control"; -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Page not found - SQLPage' as title; select 'hero' as component, 'Not Found' as title, diff --git a/examples/official-site/assets/copy-code.js b/examples/official-site/assets/copy-code.js new file mode 100644 index 000000000..ef5a68518 --- /dev/null +++ b/examples/official-site/assets/copy-code.js @@ -0,0 +1,15 @@ +/** Select the code for the browser's Copy command if clipboard access is unavailable. */ +export async function copyCode(code, label) { + try { + await navigator.clipboard.writeText(code.textContent); + return `${label} copied.`; + } catch { + code.closest("[tabindex]")?.focus({ preventScroll: true }); + const range = document.createRange(); + range.selectNodeContents(code); + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + return `${label} selected. Use Copy.`; + } +} diff --git a/examples/official-site/assets/docs/catalog-preview.css b/examples/official-site/assets/docs/catalog-preview.css new file mode 100644 index 000000000..8a13a5b86 --- /dev/null +++ b/examples/official-site/assets/docs/catalog-preview.css @@ -0,0 +1,112 @@ +.catalog-picks { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 0.5rem; + width: 100%; + max-width: 29rem; +} +.catalog-pick { + min-width: 0; + border: 1px solid #304256; + border-radius: 0.5rem; + background: #101a26; + color: #dce8f6; + text-decoration: none; +} +.catalog-pick:is(:hover, :focus-visible) { + border-color: #85acdb; + color: #fff; + text-decoration: none; +} +.catalog-pick-art { + display: grid; + place-items: center; + height: 5rem; + padding: 0.55rem; + border-radius: 0.5rem 0.5rem 0 0; + background: linear-gradient(145deg, #192a3e, #121c2a); + pointer-events: none; + user-select: none; +} +.catalog-pick-label { + display: flex; + justify-content: space-between; + align-items: center; + gap: 0.2rem; + padding: 0.4rem 0.55rem; + border-top: 1px solid #304256; + font: 500 0.85rem / 1.4 var(--tblr-font-monospace); +} +.catalog-pick-label svg { + color: #94b6de; +} +.catalog-thumb-table, +.catalog-thumb-form, +.catalog-thumb-chart { + width: 100%; + max-width: 6.25rem; +} +.catalog-thumb-table, +.catalog-thumb-form { + font: 500 0.55rem / 1.1 var(--tblr-font-monospace); + color: #bdcde1; +} +.catalog-thumb-table { + border: 1px solid #3b506b; + border-collapse: separate; + border-spacing: 0; + border-radius: 0.2rem; + overflow: hidden; + background: #101b29; +} +.catalog-thumb-table :is(th, td) { + padding: 0.12rem 0.3rem; + text-align: left; +} +.catalog-thumb-table tr > :last-child { + border-left: 1px solid #304258; + text-align: right; +} +.catalog-thumb-table th { + background: #283e58; + color: #d5e7ff; +} +.catalog-thumb-table td { + border-top: 1px solid #293a4e; +} +.catalog-thumb-form { + display: grid; + gap: 0.28rem; +} +.catalog-thumb-form b { + display: block; + margin-top: 0.1rem; + padding: 0.15rem 0.3rem; + border: 1px solid #526c8b; + border-radius: 0.16rem; + background: #101b29; + color: #d5e7ff; + font-weight: 400; +} +.catalog-thumb-chart { + display: flex; + align-items: end; + justify-content: space-evenly; + height: 3.2rem; + padding-inline: 3%; + border-left: 1px solid #556b86; + border-bottom: 1px solid #556b86; + background: repeating-linear-gradient( + to top, + transparent 0 calc(33.333% - 1px), + #2d415a calc(33.333% - 1px) 33.333% + ); +} +.catalog-thumb-chart i { + width: 9%; + border-radius: 0.12rem 0.12rem 0 0; + background: #6896ca; +} +.catalog-thumb-chart i:last-child { + background: #a6ceff; +} diff --git a/examples/official-site/assets/docs/catalog.css b/examples/official-site/assets/docs/catalog.css new file mode 100644 index 000000000..e6a9cb350 --- /dev/null +++ b/examples/official-site/assets/docs/catalog.css @@ -0,0 +1,450 @@ +.is-catalog { + padding-top: clamp(1.4rem, 3vw, 2rem); +} +.is-catalog .docs-main { + max-width: 80rem; +} +.catalog-intro { + display: grid; + grid-template-columns: minmax(0, 1fr) minmax(0, 43%); + align-items: center; + gap: clamp(1.5rem, 4vw, 4rem); + padding: clamp(1.25rem, 2.3vw, 2rem); + border: 1px solid var(--docs-line); + border-radius: 0.75rem; + background: + radial-gradient(ellipse at 90% 12%, #152740, transparent 67%), #0e151f; +} +.catalog-intro > :last-child { + width: 100%; + max-width: 29rem; + justify-self: end; +} +.catalog-back, +.catalog-related, +.catalog-call figcaption :is(a, span), +.catalog-example-count, +.catalog-empty a { + display: inline-flex; + align-items: center; + gap: 0.45rem; +} +.catalog-back, +.catalog-related { + font-size: 0.9rem; + text-decoration: none; + color: var(--docs-muted); +} +.catalog-back:hover, +.catalog-related:hover, +.catalog-clear:hover { + color: var(--docs-blue); + text-decoration: underline; +} +.catalog-intro h1 { + margin: 0.7rem 0; + font-size: clamp(2.7rem, 4.6vw, 4.1rem); + font-weight: 550; + line-height: 1.02; + letter-spacing: -0.055em; +} +.catalog-intro p { + margin: 0; + max-width: 48ch; + color: #b3c0ce; + font-size: clamp(1rem, 1.3vw, 1.15rem); + line-height: 1.55; +} +.catalog-intro-copy code { + color: var(--docs-blue); + background: transparent; + padding: 0; +} +.catalog-call { + margin: 0; + border: 1px solid #304256; + border-radius: 0.6rem; + overflow: hidden; + background: #0e1722; +} +.catalog-call figcaption, +.catalog-call > div { + display: flex; + align-items: center; + gap: 0.85rem; + padding: 0.55rem 1rem; + color: var(--docs-muted); + font-size: 0.85rem; +} +.catalog-call figcaption { + justify-content: space-between; + border-bottom: 1px solid var(--docs-line); + background: #152233; +} +.catalog-call figcaption a { + color: var(--docs-blue); + text-decoration: none; +} +.catalog-call figcaption a:hover { + text-decoration: underline; +} +.catalog-call > code { + display: block; + color: #e3ebf4; + background: transparent; + padding: 1.05rem 1rem 0.8rem; + overflow-wrap: anywhere; + font-size: 0.94rem; +} +.catalog-call b, +.catalog-call em { + font-weight: inherit; + font-style: normal; +} +.catalog-call b { + color: #94bbff; +} +.catalog-call em { + color: #afd5ce; + white-space: nowrap; +} +.catalog-call > div { + padding-top: 0; + padding-bottom: 1rem; +} +.catalog-call samp { + color: #cbd8e7; +} +.catalog-directory { + display: grid; + grid-template-columns: minmax(12rem, 14rem) minmax(0, 1fr); + align-items: start; + gap: clamp(1.75rem, 4vw, 4.5rem); + margin-top: 1.6rem; +} +.catalog-sidebar { + position: sticky; + top: calc(var(--docs-header-height) + 1.25rem); +} +.catalog-categories summary { + margin: 0 0 0.6rem; + padding: 0.6rem 0.65rem; +} +.catalog-selected-category { + margin-left: auto; + margin-right: 0.5rem; + color: var(--docs-blue); + font-size: 0.9rem; + letter-spacing: normal; + text-transform: none; +} +.catalog-categories[open] .catalog-selected-category { + display: none; +} +.catalog-categories nav { + display: grid; + gap: 0.15rem; +} +.catalog-categories nav a { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: 0.55rem; + padding: 0.55rem 0.7rem; + color: var(--docs-muted); + line-height: 1.35; + text-decoration: none; +} +.catalog-categories nav span, +.catalog-count { + color: var(--docs-muted); + font-variant-numeric: tabular-nums; + font-size: 0.85rem; + white-space: nowrap; +} +.catalog-categories nav a[aria-current] span { + color: inherit; +} +.catalog-related { + margin-top: 1.25rem; + padding: 1rem 0.65rem 0; + border-top: 1px solid var(--docs-line); +} +.catalog-related svg, +.catalog-search > svg { + flex-shrink: 0; +} +.catalog-results { + min-width: 0; + container-type: inline-size; +} +.catalog-tools { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 0.5rem 1rem; +} +.catalog-search { + display: flex; + align-items: center; + gap: 0.65rem; + flex: 1 1 18rem; + padding: 0.3rem 0.3rem 0.3rem 0.9rem; + border: 1px solid #3b4d63; + border-radius: 0.5rem; + background: var(--docs-surface); + color: var(--docs-muted); +} +.catalog-search:focus-within { + border-color: var(--docs-blue); +} +.catalog-search input[type="search"] { + flex: 1; + width: 100%; + min-width: 0; + min-height: 2.25rem; + border: 0; + padding: 0; + background: transparent; + font: inherit; + color: var(--tblr-heading-color); +} +.catalog-search input::placeholder { + color: #a4b2c4; +} +.catalog-search button { + border: 1px solid #435b75; + border-radius: 0.3rem; + padding: 0.4rem 0.8rem; + background: #20314a; + color: #cee4ff; + font: 500 0.9rem / 1.4 var(--tblr-font-sans-serif); +} +.catalog-search button:hover { + background: #2a4262; +} +.catalog-clear { + font-size: 0.9rem; + color: var(--docs-blue); +} +.catalog-group { + margin-top: 1.75rem; +} +.catalog-group h2, +.catalog-empty h2 { + margin: 0 0 0.85rem; + font-size: clamp(1.25rem, 2vw, 1.6rem); + line-height: 1.25; + letter-spacing: -0.025em; +} +.catalog-entries { + margin: 0; + padding: 0; + list-style: none; +} +.catalog-entries li { + min-width: 0; +} +.catalog-entry { + display: grid; + color: var(--tblr-heading-color); + text-decoration: none; +} +.catalog-entry:hover, +.catalog-entry:focus-visible { + color: #daebff; + text-decoration: none; +} +.catalog-entry h3 { + margin: 0; + font: 550 1rem / 1.45 var(--tblr-font-monospace); + overflow-wrap: anywhere; +} +.catalog-entry p { + margin: 0; + font-size: 0.98rem; + line-height: 1.45; + color: #afbdce; +} +.catalog-icon, +.catalog-arrow { + display: inline-grid; + place-items: center; +} +.catalog-icon { + color: #a4c7f3; +} +.catalog-arrow { + color: #7e94ae; +} +:where(.catalog-entry:hover, .catalog-entry:focus-visible) .catalog-arrow { + color: #b7d9ff; +} +.catalog-components { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); + gap: 0.75rem; +} +.catalog-components .catalog-entry { + height: 100%; + grid-template-columns: auto minmax(0, 1fr) auto; + grid-template-rows: auto 1fr auto; + align-items: center; + gap: 0.7rem 0.6rem; + padding: 1rem; + border: 1px solid var(--docs-line); + border-radius: 0.55rem; + background: var(--docs-surface); +} +.catalog-components .catalog-entry:is(:hover, :focus-visible) { + border-color: #607f9f; + background: #141e2b; +} +.catalog-components .catalog-icon { + width: 2rem; + height: 2rem; + border-radius: 0.4rem; + background: #1b2c41; +} +.catalog-components p { + grid-column: 1 / -1; + align-self: start; +} +.catalog-components .catalog-arrow { + grid-area: 1 / 3; +} +.catalog-example-count { + grid-column: 1 / -1; + color: var(--docs-muted); + font-size: 0.8rem; +} +.catalog-functions { + border: 1px solid var(--docs-line); + border-radius: 0.55rem; + background: var(--docs-surface); +} +.catalog-functions li + li { + border-top: 1px solid var(--docs-line); +} +.catalog-functions .catalog-entry { + grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) auto; + gap: 0.8rem; + align-items: center; + padding: 0.9rem 1rem; +} +.catalog-functions .catalog-entry:is(:hover, :focus-visible) { + background: #172332; + border-radius: 0.4rem; +} +.catalog-arguments { + font-weight: 400; + color: #9cadc1; +} +.catalog-functions h3 > [id] { + display: inline-block; + max-width: 100%; +} +.catalog-empty { + padding: 2.7rem 1.5rem; + margin-top: 1.75rem; + border: 1px solid var(--docs-line); + border-radius: 0.55rem; + background: var(--docs-surface); + text-align: center; +} +.catalog-empty > svg { + color: var(--docs-blue); +} +.catalog-empty h2 { + margin-top: 0.75rem; +} +.catalog-empty p { + color: var(--docs-muted); +} +.is-catalog #evaluation, +.is-catalog #evaluation + .article-text { + max-width: 51rem; + margin-inline: auto; +} +.is-catalog #evaluation { + padding-top: 2.5rem; +} +@container (max-width: 44rem) { + .catalog-functions .catalog-entry { + grid-template-columns: auto minmax(0, 1fr) auto; + gap: 0.2rem 0.7rem; + } + .catalog-functions p { + grid-column: 2; + } + .catalog-functions .catalog-arrow { + grid-area: 1 / 3 / 3; + } +} +@container (max-width: 26rem) { + .catalog-functions .catalog-entry { + grid-template-columns: minmax(0, 1fr) auto; + padding-inline: 0.8rem; + } + .catalog-functions .catalog-icon { + display: none; + } + .catalog-functions h3 { + grid-column: 1 / -1; + font-size: 0.95rem; + } + .catalog-functions p { + grid-column: 1; + } + .catalog-functions .catalog-arrow { + grid-area: 2 / 2; + } +} +@media (max-width: 61.999rem) { + .catalog-directory { + grid-template-columns: minmax(0, 1fr); + gap: 1rem; + margin-top: 1.25rem; + } + .catalog-sidebar { + position: static; + } + .catalog-categories { + border-block: 1px solid var(--docs-line); + } + .catalog-categories summary { + margin: 0; + min-height: 2.65rem; + padding-inline: 0.2rem; + } + .catalog-categories nav { + grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); + padding-bottom: 0.65rem; + } + .catalog-related { + margin: 0 0 0.75rem; + border: 0; + padding: 0; + } +} +@media (max-width: 45rem) { + .catalog-intro { + grid-template-columns: minmax(0, 1fr); + gap: 1.1rem; + padding: 0; + border: 0; + background: transparent; + } + .catalog-intro > :last-child { + justify-self: start; + } + .catalog-intro h1 { + margin-block: 0.4rem; + } + .catalog-tools { + gap: 0.45rem 0.8rem; + } + .catalog-group { + margin-top: 1.25rem; + } +} diff --git a/examples/official-site/assets/docs/examples.css b/examples/official-site/assets/docs/examples.css new file mode 100644 index 000000000..9c5e06aee --- /dev/null +++ b/examples/official-site/assets/docs/examples.css @@ -0,0 +1,132 @@ +.docs-example { + container: example / inline-size; + margin: 2rem 0 0.625rem; + border-top: 1px solid var(--tblr-border-color); + padding-top: 1.25rem; +} +.docs-example-notes > :last-child { + margin-bottom: 0; +} +.docs-example > h3 { + margin-bottom: 0.5rem; +} +.docs-example > h3 > a { + color: var(--tblr-heading-color); + text-decoration: none; +} +.docs-example > h3 > a:hover { + text-decoration: underline; +} +.docs-example-source, +.docs-example-result { + min-width: 0; +} +.docs-example > .docs-example-source, +.docs-example-layout { + margin-top: 1rem; + border: 1px solid var(--docs-line); + border-radius: 0.6rem; + background: #080d16; +} +.docs-example-result { + border-top: 1px solid var(--docs-line); + background: var(--docs-surface); + border-radius: 0 0 0.6rem 0.6rem; +} +.docs-example-output { + display: flow-root; + container-type: inline-size; + padding: 1rem; + --tblr-carousel-control-icon-filter: none; + --tblr-carousel-indicator-active-bg: var(--tblr-heading-color); +} +/* Tabler sizes columns against the viewport. A card in a preview can have much less room. */ +.docs-example-output > .row > * { + flex-grow: 1; + min-width: min(100%, 17rem); +} +.docs-example-output form .row > label { + min-width: min(100%, 12rem); +} +.docs-example-output .card { + max-width: 100%; +} +.docs-example-output .table-freeze-columns tr > :first-child { + width: clamp(7rem, 32cqi, 11rem); + min-width: min(9rem, 40cqi); + white-space: normal; +} +.docs-example-output .pagination { + flex-wrap: wrap; +} +.docs-example-output .markdown table { + display: block; + overflow-x: auto; +} +@container example (min-width: 52rem) { + .docs-example-layout { + display: grid; + grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); + } + .docs-example-layout > .docs-example-source { + position: sticky; + top: var(--docs-header-height); + align-self: start; + } + .docs-example-result { + display: grid; + grid-template-rows: auto 1fr; + border-top: 0; + border-left: 1px solid var(--docs-line); + border-radius: 0 0.6rem 0.6rem 0; + } + .docs-example-output { + align-self: center; + } +} + +.docs-example-toolbar { + display: flex; + align-items: center; + gap: 0.45rem; + margin: 0; + min-height: 2.75rem; + padding: 0.25rem 0.9rem; + border-bottom: 1px solid var(--tblr-border-color); + font: 0.875rem var(--tblr-font-monospace); + color: var(--tblr-primary); + background: var(--tblr-bg-surface-secondary); +} +.docs-example-toolbar span { + display: inline-flex; + align-items: center; + gap: 0.45rem; +} +.docs-example-toolbar button:not([hidden]) { + display: inline-flex; + align-items: center; + gap: 0.4rem; +} +@media print { + .docs-example-toolbar button:not([hidden]) { + display: none; + } +} +.docs-example-source pre, +.docs-example-source pre code { + margin: 0; + border: 0; + border-radius: 0; + background: transparent; +} +.docs-example-source pre { + max-height: min(24rem, 60svh); + overflow: auto; + padding: 1rem; +} +.docs-example-source pre code { + padding: 0; + font: 0.9rem / 1.65 var(--tblr-font-monospace); + white-space: pre-wrap; + overflow-wrap: anywhere; +} diff --git a/examples/official-site/assets/docs/examples.js b/examples/official-site/assets/docs/examples.js new file mode 100644 index 000000000..5f121eac5 --- /dev/null +++ b/examples/official-site/assets/docs/examples.js @@ -0,0 +1,41 @@ +import { copyCode } from "../copy-code.js"; + +function enableCopy(button, code, kind) { + const label = button.querySelector("span") ?? button; + const initialLabel = label.textContent; + let reset; + button.hidden = false; + button.addEventListener("click", async () => { + clearTimeout(reset); + label.textContent = await copyCode(code, kind); + reset = setTimeout(() => { + label.textContent = initialLabel; + }, 2500); + }); +} + +for (const source of document.querySelectorAll(".docs-example-source")) { + enableCopy( + source.querySelector("button"), + source.querySelector("code"), + "SQL", + ); +} + +// Keep the rendered example intact. Its source already has a copy button. +const toolbar = document.getElementById("docs-snippet-tools"); +for (const code of document.querySelectorAll(".docs-main pre > code")) { + if (code.closest(".docs-example-source, .docs-example-output")) continue; + const pre = code.parentElement; + const tools = toolbar.content.cloneNode(true); + const language = Array.from(code.classList).find((name) => + name.startsWith("language-"), + ); + if (language) + tools.querySelector("span").textContent = language.slice( + "language-".length, + ); + enableCopy(tools.querySelector("button"), code, "Code"); + pre.before(tools); + pre.tabIndex = 0; +} diff --git a/examples/official-site/assets/docs/guides.css b/examples/official-site/assets/docs/guides.css new file mode 100644 index 000000000..71aa973be --- /dev/null +++ b/examples/official-site/assets/docs/guides.css @@ -0,0 +1,149 @@ +.docs-intro { + position: relative; + isolation: isolate; + overflow: hidden; + margin-bottom: 1.25rem; + padding: clamp(1.5rem, 4vw, 3.25rem); + border: 1px solid var(--tblr-border-color); + border-radius: 1rem; + background: linear-gradient(115deg, #111c30, #0b1322 62%, #080d16); +} +.docs-intro-copy { + position: relative; + z-index: 1; + max-width: 37rem; + width: 66%; +} +.docs-version { + color: var(--tblr-primary); + font: 0.875rem / 1.5 var(--tblr-font-monospace); +} +.docs-intro h1 { + margin: 0.4rem 0 0.9rem; + color: var(--tblr-heading-color); + font-size: clamp(2.25rem, 4.5vw, 4.5rem); + font-weight: 600; + letter-spacing: -0.045em; + line-height: 1.05; +} +.docs-intro p { + max-width: 38ch; + margin: 0 0 1.5rem; + color: var(--tblr-secondary-color); + font-size: clamp(1rem, 1.6vw, 1.2rem); + line-height: 1.5; +} +.docs-intro-art { + position: absolute; + inset: 0 0 0 auto; + width: 35%; + height: 100%; + object-fit: contain; +} +.docs-intro-photo .docs-intro-art { + object-fit: cover; +} +.docs-start { + display: inline-flex; + align-items: center; + min-height: 2.75rem; + padding: 0.6rem 1rem; + border-radius: 0.45rem; + background: var(--tblr-primary); + color: #09111e; + font-weight: 600; + line-height: 1.3; + text-decoration: none; +} +.docs-start:hover, +.docs-start:focus-visible { + background: var(--tblr-link-hover-color); + color: #09111e; + text-decoration: none; +} +.docs-links { + margin-block: 2.25rem; +} +.docs-links h2 { + margin-bottom: 1rem; +} +.docs-link-grid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); + gap: 0.875rem; +} +.docs-link-card { + position: relative; + padding: 1.25rem; + border: 1px solid var(--tblr-border-color); + border-radius: 0.65rem; + background: var(--tblr-bg-surface); +} +.docs-link-card:where(:hover, :focus-within) { + border-color: var(--tblr-primary); +} +.docs-link-card h3 { + margin: 0 0 0.65rem; + font-size: 1.25rem; +} +.docs-link-card h3 a { + display: flex; + align-items: center; + gap: 0.7rem; + color: var(--tblr-heading-color); + text-decoration: none; +} +.docs-link-card h3 a::after { + position: absolute; + inset: 0; + border-radius: inherit; + content: ""; +} +.docs-link-card h3 svg { + color: var(--tblr-primary); +} +.docs-link-card p { + margin: 0; + color: var(--tblr-secondary-color); +} +.docs-link-card ul { + display: flex; + flex-wrap: wrap; + gap: 0.4rem; + margin: 1rem 0 0; + padding: 0; + list-style: none; +} +.docs-link-card li a { + position: relative; + display: inline-block; + padding: 0.2rem 0.5rem; + border-radius: 0.3rem; + background: var(--tblr-bg-surface-secondary); + color: var(--tblr-link-color); +} +.docs-link-card code { + padding: 0; + color: inherit; + background: transparent; +} +@media (max-width: 35rem) { + .docs-intro-copy { + width: 100%; + } + .docs-intro-art { + display: none; + } + .docs-intro-photo { + padding-bottom: 0; + } + .docs-intro-photo .docs-intro-art { + position: static; + display: block; + width: calc(100% + 3rem); + max-width: none; + height: 10rem; + object-position: center 25%; + margin: 1.5rem -1.5rem 0; + } +} diff --git a/examples/official-site/assets/docs/navigation.js b/examples/official-site/assets/docs/navigation.js new file mode 100644 index 000000000..812912620 --- /dev/null +++ b/examples/official-site/assets/docs/navigation.js @@ -0,0 +1,119 @@ +const search = document.querySelector(".docs-search input"); +const shortcut = document.querySelector(".docs-search kbd"); +shortcut.textContent = /Mac|iPhone|iPad/.test(navigator.platform) + ? "⌘ K" + : "Ctrl K"; +shortcut.hidden = false; +search.setAttribute("aria-keyshortcuts", "Control+k Meta+k"); +let shortcutOrigin; + +search.addEventListener("blur", () => { + shortcutOrigin = null; +}); +document.addEventListener("keydown", (event) => { + if (event.defaultPrevented || event.isComposing) return; + if (event.key === "Escape" && event.target === search && shortcutOrigin) { + event.preventDefault(); + const origin = shortcutOrigin; + search.blur(); + origin.focus({ preventScroll: true }); + return; + } + if ( + event.key.toLowerCase() === "k" && + (event.ctrlKey || event.metaKey) && + !event.altKey && + !event.shiftKey && + !event.target.closest( + "input, textarea, select, [contenteditable], [role=textbox], dialog, [aria-modal=true]", + ) + ) { + event.preventDefault(); + shortcutOrigin = document.activeElement; + search.focus(); + search.select(); + } +}); + +// Keep navigation directly browsable when JavaScript is unavailable. +const narrow = window.matchMedia("(max-width: 61.999rem)"); +const rails = document.querySelectorAll(".docs-disclosure"); +function sizeRails() { + for (const rail of rails) rail.open = !narrow.matches; +} +sizeRails(); +narrow.addEventListener("change", sizeRails); + +const filter = document.querySelector(".docs-filter"); +if (filter) { + const input = filter.querySelector("input"); + const list = document.getElementById(input.getAttribute("aria-controls")); + const links = Array.from(list.querySelectorAll("a")); + const status = filter.parentElement.querySelector('[role="status"]'); + filter.hidden = false; + input.addEventListener("input", () => { + const query = input.value.trim().toLowerCase(); + let matches = 0; + for (const link of links) { + link.hidden = !link.textContent.toLowerCase().includes(query); + if (!link.hidden) matches++; + } + status.textContent = query ? `${matches} of ${links.length} shown` : ""; + list.scrollTop = 0; + if (!query) revealCurrent(); + }); + + const current = list.querySelector('[aria-current="page"]'); + function revealCurrent() { + if (!current || current.hidden || !list.clientHeight) return; + const top = current.offsetTop; + if ( + top < list.scrollTop || + top + current.offsetHeight > list.scrollTop + list.clientHeight + ) { + list.scrollTop = top - (list.clientHeight - current.offsetHeight) / 2; + } + } + revealCurrent(); + list.closest("details").addEventListener("toggle", revealCurrent); +} + +const sections = Array.from(document.querySelectorAll(".docs-outline a")) + .map((link) => ({ + link, + target: document.getElementById(link.hash.slice(1)), + })) + .filter(({ target }) => target); +if (sections.length) { + const header = document.querySelector(".docs-header"); + let activeLink; + function markSection() { + const top = header.getBoundingClientRect().bottom + 32; + // A fragment can land below the header when fonts or a preview finish loading. + const selected = sections.find(({ link, target }) => { + if (link.hash !== location.hash) return false; + const position = target.getBoundingClientRect().top; + return position >= 0 && position < innerHeight / 2; + }); + const nearEnd = + window.scrollY > 0 && + window.scrollY + innerHeight >= document.documentElement.scrollHeight - 1; + const section = + selected ?? + (nearEnd + ? sections.at(-1) + : (sections.findLast( + ({ target }) => target.getBoundingClientRect().top <= top, + ) ?? sections[0])); + const { link } = section; + if (activeLink === link) return; + activeLink?.removeAttribute("aria-current"); + link.setAttribute("aria-current", "location"); + activeLink = link; + } + new ResizeObserver(markSection).observe(document.querySelector("main")); + markSection(); + window.addEventListener("scroll", markSection, { passive: true }); + window.addEventListener("resize", markSection); + window.addEventListener("hashchange", markSection); +} diff --git a/examples/official-site/assets/docs/reference.css b/examples/official-site/assets/docs/reference.css new file mode 100644 index 000000000..665cc3e33 --- /dev/null +++ b/examples/official-site/assets/docs/reference.css @@ -0,0 +1,92 @@ +.docs-reference-heading { + margin: 0 0 1.75rem; + padding-bottom: 1.5rem; + border-bottom: 1px solid var(--tblr-border-color); +} +.docs-reference-collection { + display: inline-flex; + align-items: center; + gap: 0.45rem; + color: var(--tblr-primary); + font-weight: 500; + text-decoration: none; +} +.docs-reference-heading h1 { + margin: 0.7rem 0; + font-size: clamp(2rem, 3.4vw, 3.5rem); + font-weight: 550; + line-height: 1.1; + letter-spacing: -0.045em; + overflow-wrap: anywhere; +} +.docs-reference-heading p { + margin-bottom: 0; + max-width: 60ch; + color: var(--tblr-secondary-color); + font-size: 1.125rem; +} +.docs-reference-meta, +.docs-reference-jump { + display: inline-block; + margin-right: 1rem; + font-size: 0.875rem; +} +.docs-reference-meta { + color: var(--tblr-secondary-color); +} +.docs-parameters { + margin-block: 2.5rem; +} +.docs-parameters > p { + color: var(--tblr-secondary-color); +} +.docs-parameters dl { + border-block: 1px solid var(--tblr-border-color); +} +.docs-parameters dl > div { + display: grid; + grid-template-columns: minmax(9rem, 30%) minmax(0, 1fr); + gap: 0.5rem 1.25rem; + padding: 1rem 0.6rem; +} +.docs-parameters dl > div:target { + background: var(--tblr-bg-surface-secondary); +} +.docs-parameters dl > div + div { + border-top: 1px solid var(--tblr-border-color); +} +.docs-parameters dt, +.docs-parameters dd { + min-width: 0; + margin: 0; + overflow-wrap: anywhere; +} +.docs-parameters dt > code { + padding: 0; + background: none; + font-weight: 600; + font-size: 1rem; + color: var(--tblr-heading-color); +} +.docs-parameters small { + display: block; + margin-top: 0.3rem; + font: 0.8125rem / 1.5 var(--tblr-font-monospace); + color: var(--tblr-muted-color); +} +.docs-parameters small strong { + margin-left: 0.5rem; + font: 500 0.8125rem var(--tblr-font-sans-serif); + color: var(--tblr-primary); +} +.docs-parameters dd > :last-child { + margin-bottom: 0; +} +.docs-reference-collection:hover { + text-decoration: underline; +} +@media (max-width: 40rem) { + .docs-parameters dl > div { + grid-template-columns: 1fr; + } +} diff --git a/examples/official-site/assets/docs/shell.css b/examples/official-site/assets/docs/shell.css new file mode 100644 index 000000000..c540f08aa --- /dev/null +++ b/examples/official-site/assets/docs/shell.css @@ -0,0 +1,573 @@ +.docs-site { + --docs-line: #27313e; + --docs-muted: #a4b1c1; + --docs-blue: #9dc6f2; + --docs-surface: #101720; + --docs-header-height: 4.5rem; + --docs-gutter: clamp(1rem, 3.5vw, 4rem); + --docs-width: 120rem; + --tblr-body-color: #dce3ec; + --tblr-bg-surface: #111922; + --tblr-bg-surface-secondary: #151f2b; + --tblr-bg-surface-tertiary: #1b2634; + --tblr-border-color: var(--docs-line); + --tblr-link-color: var(--docs-blue); + margin: 0; + height: auto; + min-height: 100vh; + background: #0a0e14; + color: var(--tblr-body-color); + font: + 1rem / 1.55 Outfit, + system-ui, + sans-serif; + -webkit-font-smoothing: antialiased; +} + +.docs-site :focus-visible { + outline: 2px solid var(--docs-blue); + outline-offset: 3px; +} + +.docs-skip { + position: fixed; + top: 0.5rem; + left: 0.5rem; + z-index: 1100; + padding: 0.6rem 1rem; + transform: translateY(-160%); + border-radius: 0.4rem; + background: var(--docs-blue); + color: #09111d; +} + +.docs-skip:focus { + transform: none; +} + +.docs-header { + position: sticky; + top: 0; + z-index: 1010; + border-bottom: 1px solid var(--docs-line); + background: #0b1017; +} + +.docs-bar, +.docs-footer, +.docs-layout { + width: min(100%, var(--docs-width)); + margin-inline: auto; + padding-inline: var(--docs-gutter); +} + +.docs-bar, +.docs-wordmark, +.docs-brand, +.docs-primary, +.docs-tools, +.docs-search, +.docs-filter, +.docs-footer, +.docs-footer nav { + display: flex; + align-items: center; +} + +.docs-bar { + min-height: var(--docs-header-height); + gap: clamp(1rem, 2.5vw, 3rem); + justify-content: space-between; +} + +.docs-bar a, +.docs-topics a, +.docs-outline a, +.docs-footer a { + color: inherit; + text-decoration: none; +} + +.docs-brand { + gap: 0.45rem; + font-size: 1.65rem; + font-weight: 600; + letter-spacing: -0.045em; + color: #f2f5fa; +} + +.docs-brand img { + object-fit: contain; +} + +.docs-home { + display: flex; + align-items: center; + gap: 0.85rem; + margin-left: 0.85rem; + font-size: 1rem; + color: var(--docs-muted); +} + +.docs-home::before { + width: 1px; + height: 1.3rem; + transform: skew(-15deg); + background: var(--docs-line); + content: ""; +} + +.docs-primary { + gap: clamp(0.6rem, 2vw, 2.25rem); + margin-left: auto; +} + +.docs-primary > a { + padding-block: 0.65rem; + color: var(--docs-muted); + font-weight: 500; + white-space: nowrap; +} + +.docs-primary > a[aria-current], +.docs-bar a:hover, +.docs-footer a:hover { + color: var(--docs-blue); +} + +.docs-primary > a[aria-current] { + font-weight: 650; +} + +.docs-disclosure > summary { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.3rem; + color: #a5b6c9; + font-size: 0.8rem; + font-weight: 600; + letter-spacing: 0.1em; + text-transform: uppercase; + list-style: none; + cursor: pointer; +} + +.docs-disclosure > summary::-webkit-details-marker { + display: none; +} + +:where(.docs-disclosure[open]) > summary svg { + transform: rotate(180deg); +} + +.docs-tools { + gap: 1rem; +} + +.docs-search, +.docs-filter { + gap: 0.35rem; + border: 1px solid var(--docs-line); + border-radius: 0.45rem; + background: var(--docs-surface); + color: var(--docs-muted); +} + +.docs-search button, +.docs-search input, +.docs-filter input { + min-width: 0; + padding: 0.35rem; + border: 0; + background: transparent; + color: inherit; + font: inherit; +} + +.docs-search button { + display: grid; + place-items: center; + padding: 0.55rem 0 0.55rem 0.7rem; +} + +.docs-search input { + width: 8rem; + padding-right: 0.55rem; +} + +.docs-search kbd { + margin-right: 0.45rem; + padding: 0.1rem 0.3rem; + border: 1px solid var(--docs-line); + border-radius: 0.25rem; + background: transparent; + color: var(--docs-muted); + font: 0.75rem / 1.4 var(--tblr-font-monospace); + white-space: nowrap; +} + +@media (max-width: 61.999rem), (pointer: coarse) { + .docs-search kbd { + display: none; + } +} + +.docs-search input::placeholder, +.docs-filter input::placeholder { + color: var(--docs-muted); +} + +.docs-github { + display: grid; + place-items: center; + min-height: 2.5rem; +} + +.docs-layout { + display: grid; + grid-template-columns: minmax(0, 1fr); + align-items: start; + gap: clamp(1.25rem, 3vw, 3.5rem); + padding-block: clamp(1.5rem, 3.5vw, 3.75rem) 4rem; + min-height: 75vh; +} + +.docs-layout.with-topics { + grid-template-columns: clamp(11rem, 15vw, 15rem) minmax(0, 1fr); +} + +.docs-layout.with-outline { + grid-template-columns: minmax(0, 1fr) clamp(9rem, 12vw, 13rem); +} + +.docs-layout.with-topics.with-outline { + grid-template-columns: clamp(11rem, 15vw, 15rem) minmax(0, 1fr) clamp( + 9rem, + 12vw, + 13rem + ); +} + +.docs-main { + grid-row: 1; + width: 100%; + min-width: 0; + max-width: 74rem; + margin-inline: auto; +} + +.docs-main, +.docs-main :where([id]) { + scroll-margin-top: calc(var(--docs-header-height) + 1rem); +} + +.with-topics > .docs-main { + grid-column: 2; +} + +.docs-self-link { + color: inherit; + text-decoration: none; +} + +.docs-self-link:is(:hover, :focus-visible) { + color: var(--docs-blue); + text-decoration: underline; + text-underline-offset: 0.15em; +} + +:where(h1, h2, h3, h4) > .docs-self-link::after { + content: " #" / ""; + color: var(--docs-muted); + font: 0.7em var(--tblr-font-monospace); +} + +.docs-main .article-text { + width: 100%; + margin: 1rem 0; + font: inherit; + line-height: 1.65; +} + +.docs-main .article-text p::first-letter { + font: inherit; +} + +.docs-main blockquote { + margin-inline: 0; + padding: 0.75rem 1rem; + border: 0; + border-radius: 0.4rem; + background: var(--docs-surface); +} + +.docs-main :where(p, li) { + overflow-wrap: anywhere; +} + +.docs-main pre { + max-width: 100%; + overflow-x: auto; +} + +.docs-snippet-tools { + display: flex; + align-items: center; + gap: 0.5rem; + padding: 0.25rem 0.65rem; + border: 1px solid var(--docs-line); + border-radius: 0.5rem 0.5rem 0 0; + background: var(--tblr-bg-surface-secondary); + color: var(--docs-muted); + font: 0.8rem var(--tblr-font-monospace); +} + +.docs-main .docs-snippet-tools + pre { + margin-top: 0; + border-radius: 0 0 0.5rem 0.5rem; +} + +.docs-snippet-copy, +.docs-example-toolbar button { + margin-left: auto; + padding: 0.35rem 0.55rem; + border: 1px solid var(--docs-line); + border-radius: 0.3rem; + background: var(--tblr-bg-surface); + color: var(--tblr-secondary-color); + font: 0.875rem var(--tblr-font-sans-serif); +} + +:is(.docs-snippet-tools, .docs-example-toolbar) button:hover { + border-color: var(--docs-blue); + color: var(--docs-blue); +} + +@media print { + .docs-snippet-tools { + display: none; + } +} + +.docs-main img { + max-width: 100%; +} + +.docs-topics, +.docs-outline { + position: sticky; + top: calc(var(--docs-header-height) + 1.5rem); + min-width: 0; + color: var(--docs-muted); +} + +.docs-outline { + grid-column: -2; + grid-row: 1; +} + +.docs-rail-title { + margin: 0 0 0.85rem; + padding-block: 0.4rem; +} + +.docs-filter { + padding-inline: 0.6rem; + margin-bottom: 0.8rem; + font-size: 0.9rem; +} + +.docs-filter[hidden] { + display: none; +} + +.docs-filter input { + width: 100%; +} + +.docs-topic-list, +.docs-outline nav { + position: relative; + display: grid; + align-content: start; + max-height: calc(100dvh - var(--docs-header-height) - 11rem); + overflow-y: auto; + overscroll-behavior: contain; + scrollbar-color: #33445a transparent; + scrollbar-width: thin; +} + +.docs-topic-list a, +.docs-outline a { + min-width: 0; + padding: 0.38rem 0.65rem; + overflow-wrap: anywhere; + font-size: 0.95rem; +} + +:where(.docs-filter) + .docs-topic-list a { + font-family: var(--tblr-font-monospace); + font-size: 0.86rem; +} + +.docs-disclosure nav a { + border-radius: 0.35rem; +} + +.docs-disclosure nav a:hover { + background: #172331; + color: var(--tblr-heading-color); +} + +.docs-disclosure nav a[aria-current], +.docs-site + .list-group-item:is(.active, :has(.list-group-selectable-check:checked)) { + background: #192d43; + color: #c1dfff; + font-weight: 600; + box-shadow: none; +} + +/* Both scrollable rails clip an outline placed outside their links. */ +.docs-disclosure nav a:focus-visible { + outline-offset: -2px; +} + +.docs-site .docs-rail-return { + display: flex; + align-items: center; + gap: 0.5rem; + margin-top: 1rem; + padding: 0.9rem 0.3rem 0; + border-top: 1px solid var(--docs-line); + color: var(--docs-blue); + font-size: 0.9rem; +} + +.docs-footer { + flex-wrap: wrap; + justify-content: space-between; + gap: 1rem; + padding-block: 1.5rem; + border-top: 1px solid var(--docs-line); + color: var(--docs-muted); + font-size: 0.9rem; +} + +.docs-footer nav { + flex-wrap: wrap; + gap: 0.5rem 1.25rem; +} + +@media (max-width: 61.999rem) { + .docs-bar { + gap: 0.8rem; + } + + .docs-primary { + gap: 1rem; + } + + .docs-search input { + width: 6.25rem; + } + + .docs-layout, + .docs-layout.with-topics, + .docs-layout.with-outline, + .docs-layout.with-topics.with-outline { + display: flex; + flex-direction: column; + gap: 0.75rem; + } + + .docs-topics, + .docs-outline { + position: static; + width: 100%; + border-bottom: 1px solid var(--docs-line); + } + + .docs-rail-title { + margin: 0; + padding-block: 0.6rem; + } + + :where(.docs-disclosure[open]) nav { + margin-bottom: 0.75rem; + } + + .docs-topic-list, + .docs-outline nav { + max-height: 13rem; + } +} + +@media (max-width: 46rem) { + .docs-site { + --docs-header-height: 6.6rem; + } + + .docs-bar { + flex-wrap: wrap; + gap: 0 0.5rem; + padding-top: 0.4rem; + } + + .docs-brand { + font-size: 1.4rem; + } + + .docs-brand img { + width: 1.9rem; + height: 2.2rem; + } + + .docs-home { + gap: 0.6rem; + margin-left: 0.6rem; + } + + .docs-tools { + gap: 0.65rem; + margin-left: auto; + font-size: 0.9rem; + } + + .docs-search input { + width: clamp(4.8rem, 18vw, 8rem); + } + + .docs-primary { + flex-basis: 100%; + order: 1; + justify-content: space-between; + gap: 0.35rem; + font-size: 0.94rem; + } + + .docs-primary > a { + padding-block: 0.55rem; + } +} + +@media (max-width: 23rem) { + .docs-brand { + gap: 0.25rem; + font-size: 1.2rem; + } + .docs-brand img { + width: 1.5rem; + } + .docs-home { + margin-left: 0.35rem; + } + .docs-home, + .docs-tools { + gap: 0.35rem; + } + .docs-search input { + width: 3.6rem; + } +} diff --git a/examples/official-site/assets/highlightjs-launch.js b/examples/official-site/assets/highlightjs-launch.js index 66ce4773c..763a18571 100644 --- a/examples/official-site/assets/highlightjs-launch.js +++ b/examples/official-site/assets/highlightjs-launch.js @@ -1 +1,23 @@ -hljs.highlightAll(); +// Code remains readable while the optional highlighter loads. +if (document.querySelector("pre code")) { + highlightCode().catch(() => { + // The CDN may be unavailable. + }); +} + +async function highlightCode() { + const base = + "https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.11.1/es"; + const { default: engine } = await import(`${base}/highlight.min.js`); + await Promise.all( + ["sql", "json", "handlebars", "nginx"].map(async (language) => { + if (engine.getLanguage(language)) return; + if (!document.querySelector(`code.language-${language}`)) return; + const { default: grammar } = await import( + `${base}/languages/${language}.min.js` + ); + engine.registerLanguage(language, grammar); + }), + ); + engine.highlightAll(); +} diff --git a/examples/official-site/assets/landing/js/component-demos.js b/examples/official-site/assets/landing/js/component-demos.js index 50046e5fb..1d45054eb 100644 --- a/examples/official-site/assets/landing/js/component-demos.js +++ b/examples/official-site/assets/landing/js/component-demos.js @@ -1,3 +1,4 @@ +import { copyCode } from "../../copy-code.js"; import { initSqlHighlight } from "./sql-highlight.js"; import { initTabs, selectTab } from "./tabs.js"; @@ -63,15 +64,12 @@ export function initComponentDemos(root, signal) { preview.addEventListener("load", fitPreview, { signal }); fitPreview(); - root.querySelector("[data-copy-sql]").addEventListener( + const copy = root.querySelector("[data-copy-sql]"); + copy.hidden = false; + copy.addEventListener( "click", async () => { - try { - await navigator.clipboard.writeText(source.textContent); - status.textContent = "SQL copied."; - } catch { - status.textContent = "Copy unavailable. Select the SQL below."; - } + status.textContent = await copyCode(source, "SQL"); }, { signal }, ); @@ -183,8 +181,12 @@ export function initComponentDemos(root, signal) { root.querySelector('[data-file="save"]').hidden = next !== "form"; root.querySelector("#demo-filename").textContent = `${next}.sql`; const link = panel.querySelector(".demo-docs"); - link.href = `/component.sql?component=${next}`; - link.firstChild.textContent = `Explore the ${next} component `; + link.href = files + ? `/component.sql?component=${next}` + : "/components.sql"; + link.firstChild.textContent = files + ? `Explore the ${next} component ` + : "Browse the component reference "; if (files) { sourceFiles = { main: files.source, save: files.save_source }; // Avoid an intermediate one-line loading state or a nested resize. diff --git a/examples/official-site/assets/landing/styles/component-demos.css b/examples/official-site/assets/landing/styles/component-demos.css index 3c7ab349b..d129be7f9 100644 --- a/examples/official-site/assets/landing/styles/component-demos.css +++ b/examples/official-site/assets/landing/styles/component-demos.css @@ -37,32 +37,21 @@ display: flex; align-self: stretch; } -.sql-editor-header .source-tabs button { - border-radius: 0; - border: 0; - border-right: 1px solid var(--tblr-bg-surface-tertiary); +.source-tabs button { padding: 12px 18px; - background: transparent; - color: var(--tblr-muted-color); - font: 12px var(--tblr-font-monospace); - box-shadow: inset 0 2px transparent; } -.sql-editor-header .source-tabs button[aria-selected="true"] { - color: var(--tblr-body-color); +.source-tabs button[aria-selected="true"] { + color: var(--tblr-primary); background: var(--tblr-bg-surface-secondary); - box-shadow: inset 0 2px var(--tblr-primary); + font-weight: 600; +} +.sql-editor-header button:focus-visible { + outline-offset: -3px; } .sql-editor-header svg { width: 15px; height: 15px; } -.sql-editor .code-panel { - margin: 0; - border: 0; - border-radius: 0; - padding: 18px 20px; - overflow-x: auto; -} #demo-source { color: var(--tblr-secondary-color); display: block; @@ -85,6 +74,22 @@ text-align: right; user-select: none; } +.demo-annotation { + position: absolute; + top: -86px; + left: 48%; + margin: 0; + color: color-mix(in srgb, var(--tblr-dark), var(--tblr-white) 40%); + font: italic 17px / 1.35 cursive; + transform: rotate(-6deg); + pointer-events: none; +} +.demo-annotation svg { + display: block; + width: 36px; + height: 36px; + margin-left: 18px; +} .demo-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); @@ -107,10 +112,7 @@ border-radius: 6px; background: transparent; color: inherit; - transition: - background 0.2s, - box-shadow 0.2s, - transform 0.2s; + transition: background 0.2s; } .component-picker button > svg { width: 28px; @@ -130,16 +132,12 @@ margin-top: 6px; } .component-picker button:hover { - transform: translateX(3px); background: color-mix(in srgb, var(--tblr-blue) 6.27%, transparent); } .component-picker button[aria-selected="true"] { - background: var(--tblr-body-bg); - color: white; - border-color: var(--tblr-bg-surface-tertiary); - border-left: 3px solid var(--tblr-primary); - box-shadow: 0 12px 28px - color-mix(in srgb, var(--tblr-body-bg) 18.82%, transparent); + background: var(--tblr-bg-surface-secondary); + color: var(--tblr-heading-color); + border-color: var(--tblr-primary); } .component-picker button[aria-selected="true"] svg { color: var(--tblr-blue); @@ -148,22 +146,6 @@ position: relative; min-width: 0; } -.demo-annotation { - position: absolute; - top: -86px; - left: 48%; - margin: 0; - color: color-mix(in srgb, var(--tblr-dark), var(--tblr-white) 40%); - font: italic 17px / 1.35 cursive; - transform: rotate(-6deg); - pointer-events: none; -} -.demo-annotation svg { - display: block; - width: 36px; - height: 36px; - margin-left: 18px; -} .demo-preview { position: relative; height: 280px; @@ -185,12 +167,13 @@ pointer-events: none; } .code-panel { + margin: 0; + border: 0; + padding: 18px 20px; background: var(--tblr-body-bg); color: var(--tblr-secondary-color); font: 13px / 1.8 var(--tblr-font-monospace); - border: 1px solid var(--tblr-blue); - border-radius: 12px; - padding: 22px; + overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; } @@ -231,9 +214,6 @@ .demo-annotation { display: none; } - .sql-editor .code-panel { - padding: 16px 12px; - } .sql-line { white-space: pre-wrap; overflow-wrap: anywhere; @@ -270,7 +250,7 @@ flex-basis: 22px; } .code-panel { - padding: 16px; + padding: 16px 12px; font-size: 11px; } } @@ -294,7 +274,6 @@ } #demo-panel[data-demo="catalog"] .sql-editor, #demo-panel[data-demo="catalog"] .demo-annotation, -#demo-panel[data-demo="catalog"] .demo-docs, #demo-panel[data-demo="catalog"] .demo-status { display: none; } diff --git a/examples/official-site/blog.sql b/examples/official-site/blog.sql index 4ed924e31..781e4fa13 100644 --- a/examples/official-site/blog.sql +++ b/examples/official-site/blog.sql @@ -1,10 +1,7 @@ select 'redirect' as component, '/blog.sql' as link where ($post IS NULL AND sqlpage.path() <> '/blog.sql') OR ($post IS NOT NULL AND NOT EXISTS (SELECT 1 FROM blog_posts WHERE title = $post)); -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', coalesce($post || ' - ', '') || 'SQLPage Blog' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, coalesce($post || ' - ', '') || 'SQLPage Blog' as title; SELECT 'text' AS component, true as article, diff --git a/examples/official-site/component.sql b/examples/official-site/component.sql index 53453fe32..747882aab 100644 --- a/examples/official-site/component.sql +++ b/examples/official-site/component.sql @@ -1,154 +1,37 @@ --- ensure that the component exists and do not render this page if it does not select 'redirect' as component, 'component_not_found.sql' || coalesce('?component=' || sqlpage.url_encode($component), '') as link where not exists (select 1 from component where name = $component); --- This line, at the top of the page, tells web browsers to keep the page locally in cache once they have it. -select 'http_header' as component, +select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", printf('<%s>; rel="canonical"', sqlpage.link('component', json_object('component', $component))) as "Link"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', coalesce($component || ' - ', '') || 'SQLPage Documentation' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; - -select 'breadcrumb' as component; -select 'SQLPage' as title, '/' as link, 'Home page' as description; -select 'Components' as title, '/documentation.sql' as link, 'List of all components' as description; -select $component as title, '/component.sql?component=' || sqlpage.url_encode($component) as link; - -select 'text' as component, 'component' as id, true as article, - format('# The **%s** component - -%s', $component, description) as contents_md -from component where name = $component; - -select format('Introduced in SQLPage v%s.', introduced_in_version) as contents, 1 as size -from component -where name = $component and introduced_in_version IS NOT NULL; - -select 'title' as component, 3 as level, 'Top-level parameters' as contents where $component IS NOT NULL; -select 'table' as component, true as striped, true as hoverable, true as freeze_columns, - 'type' as markdown, 'description' as markdown - where $component IS NOT NULL; -select - name, - CASE WHEN optional THEN '' ELSE 'REQUIRED' END as required, - CASE type - WHEN 'COLOR' THEN printf('[%s](/colors.sql)', type) - WHEN 'ICON' THEN printf('[%s](https://tabler-icons.io/?ref=sqlpage)', type) - ELSE type - END AS type, - coalesce(description_md, description) as description -from parameter where component = $component AND top_level -ORDER BY optional, name; - - -select 'title' as component, 3 as level, 'Row-level parameters' as contents -WHERE $component IS NOT NULL AND EXISTS (SELECT 1 from parameter where component = $component AND NOT top_level); -select 'table' as component, true as striped, true as hoverable, true as freeze_columns, - 'type' as markdown, 'description' as markdown - where $component IS NOT NULL; -select - name, - CASE WHEN optional THEN '' ELSE 'REQUIRED' END as required, - CASE type - WHEN 'COLOR' THEN printf('[%s](/colors.sql)', type) - WHEN 'ICON' THEN printf('[%s](https://tabler-icons.io/?ref=sqlpage)', type) - ELSE type - END AS type, - coalesce(description_md, description) as description -from parameter where component = $component AND NOT top_level -ORDER BY optional, name; - -select - 'dynamic' as component, - '[ - {"component": "code"}, - { - "title": "Example ' || (row_number() OVER ()) || '", - "description_md": ' || json_quote(description) || ', - "language": "sql", - "contents": ' || json_quote(( - select - group_concat( - 'select ' || char(10) || - ( - with t as ( - select *, - case type - when 'array' then json_array_length(value)>1 - else false - end as is_arr - from json_tree(top.value) - ), - key_val as (select - CASE t.type - WHEN 'integer' THEN t.atom - WHEN 'real' THEN t.atom - WHEN 'true' THEN 'TRUE' - WHEN 'false' THEN 'FALSE' - WHEN 'null' THEN 'NULL' - WHEN 'object' THEN 'JSON(' || quote(t.value) || ')' - WHEN 'array' THEN 'JSON(' || quote(t.value) || ')' - ELSE quote(t.value) - END as val, - CASE parent.fullkey - WHEN '$' THEN t.key - ELSE parent.key - END as key - from t inner join t parent on parent.id = t.parent - where ((parent.fullkey = '$' and not t.is_arr) - or (parent.path = '$' and parent.is_arr)) - ), - key_val_padding as (select - CASE - WHEN (key LIKE '% %') or (key LIKE '%-%') THEN - format('"%w"', key) - ELSE - key - END as key, - val, - 1 + max(0, max(case when length(val) < 30 then length(val) else 0 end) over () - length(val)) as padding - from key_val - ) - select group_concat( - format(' %s%.*cas %s', val, padding, ' ', key), - ',' || char(10) - ) from key_val_padding - ) || ';', - char(10) - ) - from json_each(properties) AS top - )) || ' - }, '|| - CASE component - WHEN 'shell' THEN '{"component": "text", "contents": ""}' - WHEN 'http_header' THEN '{ "component": "text", "contents": "" }' - ELSE ' - {"component": "title", "level": 3, "contents": "Result"}, - {"component": "dynamic", "properties": ' || properties ||' } - ' - END || ' - ] - ' as properties -from example where component = $component AND properties IS NOT NULL; - -SELECT 'title' AS component, 3 AS level, 'Examples' AS contents -WHERE EXISTS (SELECT 1 FROM example WHERE component = $component AND properties IS NULL); -SELECT 'text' AS component, description AS contents_md -FROM example WHERE component = $component AND properties IS NULL; - - -select 'title' as component, 2 as level, 'See also: other components' as contents; -select - 'button' as component, - 'sm' as size, - 'pill' as shape; -select - name as title, - icon, - sqlpage.set_variable('component', name) as link -from component -order by name; \ No newline at end of file +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-reference.sql', json_object( + 'kind', 'component', 'name', $component +)) as properties; + +select 'title' as component, 2 as level, 'Examples' as contents, 'examples' as id +where exists (select 1 from example where component = $component); + +with examples as ( + -- HTTP headers and shells can only run at the start of a response. + select *, + case when component not in ('shell', 'http_header') then properties end as result, + case when length(trim(description)) <= 120 + and glob('*[^a-zA-Z0-9 ,.''()-]*', trim(description)) = 0 + then trim(description) end as short_title + from example_with_source where component = $component +) +select 'dynamic' as component, json_array( + json_object( + 'component', 'docs-example', 'number', example_number, + 'title', short_title, 'description_md', case when short_title is null then description end, + 'source', source, + 'preview', result is not null + ), + json(coalesce(result, '[]')), + -- Keep every native component of the example inside the same result panel. + 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; diff --git a/examples/official-site/component_not_found.sql b/examples/official-site/component_not_found.sql index e4b9656bb..5ab6f307d 100644 --- a/examples/official-site/component_not_found.sql +++ b/examples/official-site/component_not_found.sql @@ -1,6 +1,6 @@ select 'http_header' as component, 'noindex' as "X-Robots-Tag"; -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Component not found - SQLPage' as title; select 'hero' as component, diff --git a/examples/official-site/components.sql b/examples/official-site/components.sql index dc9bbcd6d..e3d93cebe 100644 --- a/examples/official-site/components.sql +++ b/examples/official-site/components.sql @@ -1 +1,8 @@ -SELECT 'redirect' as component, 'documentation.sql' as link; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Components - SQLPage Documentation', 'section', 'Components', + 'description', 'Explore SQLPage components by purpose, with live examples and parameters for each one.' +)) as properties; + +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-catalog.sql', json_object( + 'kind', 'component', 'q', $q, 'category', $category +)) as properties; diff --git a/examples/official-site/custom_components.sql b/examples/official-site/custom_components.sql index 24e12e651..cb8375a52 100644 --- a/examples/official-site/custom_components.sql +++ b/examples/official-site/custom_components.sql @@ -1,6 +1,9 @@ -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Creating custom components | SQLPage', + 'section', 'Guides', 'current', 'Custom components' +)) as properties; -select 'text' as component, ' +select 'text' as component, true as article, ' # Creating your own SQLPage components @@ -171,6 +174,12 @@ If you don''t want to start from scratch, you can copy the default `shell` compo ## Examples +The documentation you are reading uses the same features. Its +[shell template](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/sqlpage/templates/shell-docs.handlebars) +renders the guide and reference navigation. The +[documentation home page](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/documentation.sql) +selects rows for a [custom links component](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/sqlpage/templates/docs-links.handlebars). + All the default components are written in handlebars, and you can read their source code to learn how to write your own. [See the default components source code](https://github.com/sqlpage/SQLPage/blob/main/sqlpage/templates). @@ -184,3 +193,9 @@ Some interesting examples are: - and the `@key` to work with objects whose keys are not known in advance. ' as contents_md; + +select 'docs-links' as component, 'Related reference' as title, 'reference' as id; +select 'Shell parameters' as title, 'layout' as icon, '/component.sql?component=shell' as link, + 'Explore the built-in shell and its navigation, layout and asset options.' as description; +select 'Component catalog' as title, 'layout-grid' as icon, '/components.sql' as link, + 'Inspect the behavior and examples of the built-in components.' as description; diff --git a/examples/official-site/documentation.sql b/examples/official-site/documentation.sql index e848f3510..58a8074a4 100644 --- a/examples/official-site/documentation.sql +++ b/examples/official-site/documentation.sql @@ -1,57 +1,45 @@ --- ensure that the component exists and do not render this page if it does not +-- Preserve links from older guides to individual components. select 'redirect' as component, sqlpage.link('component.sql', json_object('component', $component)) as link where $component is not null; --- This line, at the top of the page, tells web browsers to keep the page locally in cache once they have it. select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', coalesce($component || ' - ', '') || 'SQLPage Documentation' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; - -select 'text' as component, format('SQLPage v%s documentation', sqlpage.version()) as title; -select ' -If you are completely new to SQLPage, you should start by reading the [get started tutorial](/your-first-sql-website/), -which will guide you through the process of creating your first SQLPage application. - -Building an application with SQLPage is quite simple. -To create a new web page, just create a new SQL file. -For each SELECT statement that you write, the data it returns will be analyzed and rendered to the user. -The two most important concepts in SQLPage are **components** and **parameters**. - - - **components** are small user interface elements that you can use to display your data in a certain way. - - *top-level* **parameters** are the properties of these components, allowing you to customize their appearance and behavior. - - *row-level* **parameters** constitute the data that you want to display in the components. - -To select a component and set its top-level properties, you write the following SQL statement: - -```sql -SELECT ''component_name'' AS component, ''my value'' AS top_level_parameter_1; -``` - -Then, you can set its row-level parameters by writing a second SELECT statement: - -```sql -SELECT my_column_1 AS row_level_parameter_1, my_column_2 AS row_level_parameter_2 FROM my_table; -``` - -This page documents all the components provided by default in SQLPage and their parameters. -Use this as a reference when building your SQL application. -For more information about SQLPage variables and [SQLPage functions](/functions), -read about [the SQLPage data model](/extensions-to-sql). - -If at any point you need help, you can ask for it on the [SQLPage forum](https://github.com/sqlpage/SQLPage/discussions). - -If you know some [HTML](https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics), -you can also easily [create your own components for your application](./custom_components.sql). -' as contents_md; - -select 'list' as component, 'components' as title; -select - name as title, - description, - icon, - sqlpage.link('component.sql', json_object('component', name)) as link -from component -order by name; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'SQLPage Documentation', + 'section', 'Documentation', + 'current', 'Documentation', + 'outline', '[{"title":"Overview","link":"#overview"},{"title":"Reference","link":"#reference"},{"title":"Anatomy of a SQL page","link":"#how-it-works"},{"title":"Guides","link":"#guides"}]' +)) as properties; + +select 'docs-intro' as component, + 'Documentation' as title, + 'Build your first website in SQL, or look up a component or function for the page you are writing.' as description, + sqlpage.version() as version, + '/assets/landing/assets/scene-first-frame.webp' as image, + '/your-first-sql-website/' as link, 'Build your first website' as link_text; + +select 'docs-links' as component, 'Reference' as title, 'reference' as id; +select case kind when 'component' then 'Components' else 'Functions' end as title, + case kind when 'component' then 'layout-grid' else 'function' end as icon, + '/' || kind || 's.sql' as link, + case kind when 'component' then format('Browse %d components with their parameters, SQL examples and previews.', count(*)) + else format('Look up the arguments and behavior of %d built-in SQLPage functions.', count(*)) end as description, + json_group_array(json_object('title', name, 'link', link) order by name) filter (where + (kind = 'component' and name in ('form', 'table', 'map', 'chart', 'button')) or + (kind = 'function' and name in ('fetch', 'link', 'run_sql', 'variables')) + ) as links +from reference_entry group by kind order by kind; + +select 'title' as component, 'Anatomy of a SQL page' as contents, 2 as level, 'how-it-works' as id; +select 'text' as component, 'Each SQL file is a page. Its first SELECT names a component and sets its top-level parameters. The rows returned by the next SELECT supply the row-level parameters. This list uses both.' as contents; +select 'docs-example' as component, 1 as number, 'A reading list' as title, true as preview, + sqlpage.read_file_as_text('sqlpage/docs-intro-example.sql') as source; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-intro-example.sql') as properties; +select 'docs-example' as component, true as end_result; + +select 'docs-links' as component, 'Guides' as title, 'guides' as id; +select title, link, description +from guide +order by sort_order; + +select 'text' as component, 'Have a question? Ask on the [SQLPage forum](https://github.com/sqlpage/SQLPage/discussions).' as contents_md; diff --git a/examples/official-site/examples/authentication/basic_auth.sql b/examples/official-site/examples/authentication/basic_auth.sql index 5eed40780..4f644d167 100644 --- a/examples/official-site/examples/authentication/basic_auth.sql +++ b/examples/official-site/examples/authentication/basic_auth.sql @@ -9,7 +9,7 @@ SELECT 'authentication' AS component, end AS password_hash, -- this is a hash of the password 'password' sqlpage.basic_auth_password() AS password; -- this is the password that the user entered in the browser popup -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'HTTP basic authentication | SQLPage' as title, 'Examples' as section; select 'text' as component, ' # Authentication diff --git a/examples/official-site/examples/authentication/login.sql b/examples/official-site/examples/authentication/login.sql index b0a39f5b8..ea59be3c3 100644 --- a/examples/official-site/examples/authentication/login.sql +++ b/examples/official-site/examples/authentication/login.sql @@ -1,4 +1,4 @@ -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Password protection | SQLPage' as title, 'Examples' as section; select 'login' as component, diff --git a/examples/official-site/examples/handle_picture_upload.sql b/examples/official-site/examples/handle_picture_upload.sql index 2b2e7b3fa..248709c3c 100644 --- a/examples/official-site/examples/handle_picture_upload.sql +++ b/examples/official-site/examples/handle_picture_upload.sql @@ -1,4 +1,4 @@ -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'File uploads | SQLPage' as title, 'Examples' as section; select 'title' as component, 'SQLPage Image Upload Demo' as contents; diff --git a/examples/official-site/examples/hash_password.sql b/examples/official-site/examples/hash_password.sql index a9e850499..dae127222 100644 --- a/examples/official-site/examples/hash_password.sql +++ b/examples/official-site/examples/hash_password.sql @@ -1,4 +1,4 @@ -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Password hashing | SQLPage' as title, 'Examples' as section; select 'text' as component, ' diff --git a/examples/official-site/examples/index.sql b/examples/official-site/examples/index.sql index 371d206cd..eda69397d 100644 --- a/examples/official-site/examples/index.sql +++ b/examples/official-site/examples/index.sql @@ -1 +1,35 @@ -select 'redirect' as component, '/examples/tabs' as link; \ No newline at end of file +select 'http_header' as component, '; rel="canonical"' as "Link"; +select 'shell-docs' as component, 'Examples | SQLPage' as title, 'Examples' as section; + +select 'title' as component, 'Examples' as contents; +select 'docs-links' as component, 'Try a live example' as title, 'live-examples' as id; +select column1 as title, column2 as icon, column3 as link, column4 as description +from (values + ('Multi-step form', 'forms', '/examples/multistep-form/', 'Book a flight with a form that carries your choices from one page to the next.'), + ('File uploads', 'upload', '/examples/handle_picture_upload.sql', 'Upload a picture and display it on the page.'), + ('Password protection', 'lock', '/examples/authentication/', 'Sign in to a page that uses a database-backed session.'), + ('Page layouts', 'layout', '/examples/layouts.sql', 'Switch between boxed, horizontal, and fluid layouts and try the sidebar.') +); + +select 'title' as component, 'Example projects' as contents, 2 as level, 'projects' as id; +select 'text' as component, 'Choose a database to find a complete project and read its SQL on GitHub.' as contents; + +select 'tab' as component, true as center; +select 'Show all examples' as title, 'All database examples' as description, '/examples/#projects' as link, $db is null as active; +select db_engine as title, + format('%s database examples', db_engine) as description, + sqlpage.link('/examples/', json_object('db', db_engine), 'projects') as link, + $db=db_engine as active, + case $db when db_engine then db_engine end as color +from example_cards +group by db_engine; + +select 'card' as component; +select title, description, + format('/examples/tabs/images/%s.svg', folder) as top_image, + db_engine as color, + 'https://github.com/sqlpage/SQLPage/tree/main/examples/' || folder as link +from example_cards +where $db is null or $db = db_engine; + +select 'text' as component, '[Browse all example projects on GitHub](https://github.com/sqlpage/SQLPage/tree/main/examples)' as contents_md; diff --git a/examples/official-site/examples/multistep-form/index.sql b/examples/official-site/examples/multistep-form/index.sql index cccaafbf1..5936ee6f3 100644 --- a/examples/official-site/examples/multistep-form/index.sql +++ b/examples/official-site/examples/multistep-form/index.sql @@ -1,5 +1,5 @@ -- This demonstrates how to build multi-step forms using the `form` component, and hidden inputs. -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Multi-step form | SQLPage' as title, 'Examples' as section; select 'text' as component, ' # SQLPage Multi-Step Form Example diff --git a/examples/official-site/examples/multistep-form/result.sql b/examples/official-site/examples/multistep-form/result.sql index 8e1985b72..2bb44d712 100644 --- a/examples/official-site/examples/multistep-form/result.sql +++ b/examples/official-site/examples/multistep-form/result.sql @@ -1,4 +1,4 @@ -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Booking confirmation | SQLPage' as title, 'Examples' as section; select 'hero' as component, 'Booking confirmation' as title, @@ -32,13 +32,9 @@ select value as title, 'Child' as description, 'baby-carriage' as icon from json select 'divider' as component, 'Technical details' as contents; select 'text' as component, ' -# How is this even possible ? +## Booking form implementation -Not a single line of *HTML*, *CSS*, *JavaScript*, *Python*, *PHP* or *Ruby* was written to implement -SQLPage Airlines'' multi-step, conditional booking process. How is this even possible ? - -The entire form and result page are dynamically generated by a few simple SQL queries, that -select graphical components from [SQLPage''s component library](/documentation.sql). +SQL queries select the fields for each step and render the confirmation page using [SQLPage components](/components.sql). You can find the [**full source code** of this example on GitHub](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/examples/multistep-form). ' as contents_md; diff --git a/examples/official-site/examples/tabs/index.sql b/examples/official-site/examples/tabs/index.sql index b5f328554..5f878cb38 100644 --- a/examples/official-site/examples/tabs/index.sql +++ b/examples/official-site/examples/tabs/index.sql @@ -1,27 +1,3 @@ -select 'http_header' as component, '; rel="canonical"' as "Link"; - -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'SQLPage - SQL website examples', - 'description', 'These small focused examples each illustrate one feature of the SQLPage website builder.' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; - -select 'tab' as component, true as center; -select 'Show all examples' as title, 'All database examples' as description, '?' as link, $db is null as active; -select db_engine as title, - format('%s database examples', db_engine) as description, - format('?db=%s', db_engine) as link, - $db=db_engine as active, - case $db when db_engine then db_engine end as color -from example_cards -group by db_engine; - -select 'card' as component; -select title, description, - format('images/%s.svg', folder) as top_image, - db_engine as color, - 'https://github.com/sqlpage/SQLPage/tree/main/examples/' || folder as link -from example_cards -where $db is null or $db = db_engine; - -select 'text' as component, 'See [source code on GitHub](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/examples/tabs/)' as contents_md; +-- Preserve bookmarks to the database-filtered example projects. +select 'redirect' as component, sqlpage.link('/examples/', + case when $db is not null then json_object('db', $db) end, 'projects') as link; diff --git a/examples/official-site/extensions-to-sql.md b/examples/official-site/extensions-to-sql.md index 7ef679bfc..a8d3a69e8 100644 --- a/examples/official-site/extensions-to-sql.md +++ b/examples/official-site/extensions-to-sql.md @@ -1,4 +1,4 @@ -## How SQLPage runs your SQL +## SQL statement execution SQLPage reads your SQL file and runs one statement at a time. For each statement, it @@ -12,7 +12,7 @@ SQLPage reads your SQL file and runs one statement at a time. For each statement This page explains every step of the process, with examples and details about differences between how SQLPage understands SQL and how your database does. -## What runs where +## SQLPage and database responsibilities ### Handled locally by SQLPage @@ -136,7 +136,7 @@ SET my_var = 'custom value'; -- This value takes precedence over ?my_var=... This means `SET` variables always take precedence over request parameters when using `$var` or `:var` syntax. -**How SET works:** +**Assignment rules** - If the right-hand side is purely literals/variables, SQLPage computes it directly. See the section about *static simple select* above. - If it needs the database (for example, calls a database function), SQLPage runs an internal `SELECT` to compute it and stores the first column of the first row of results. diff --git a/examples/official-site/extensions-to-sql.sql b/examples/official-site/extensions-to-sql.sql index 752eac725..f147998b6 100644 --- a/examples/official-site/extensions-to-sql.sql +++ b/examples/official-site/extensions-to-sql.sql @@ -1,12 +1,20 @@ select 'http_header' as component, 'public, max-age=300, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'SQLPage - Extensions to SQL' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'SQL and variables | SQLPage', + 'section', 'Guides', 'current', 'SQL and variables' +)) as properties; + +select 'title' as component, 'SQL and variables' as contents; -- Article by Matthew Larkin select 'text' as component, sqlpage.read_file_as_text('extensions-to-sql.md') as contents_md, true as article; + +select 'docs-links' as component, 'Related reference' as title, 'reference' as id; +select 'Built-in functions' as title, 'function' as icon, '/functions.sql' as link, + 'Find signatures and examples for the sqlpage.* functions you can call in a query.' as description; +select 'Form parameters' as title, 'forms' as icon, '/component.sql?component=form' as link, + 'Set up the fields that supply POST parameters to your page.' as description; diff --git a/examples/official-site/functions.sql b/examples/official-site/functions.sql index b8064343b..9a5b9375b 100644 --- a/examples/official-site/functions.sql +++ b/examples/official-site/functions.sql @@ -1,25 +1,31 @@ +select 'status_code' as component, 404 as status +where $function is not null and not exists (select 1 from sqlpage_functions where name = $function); + select 'http_header' as component, printf('<%s>; rel="canonical"', - iif($function is not null, sqlpage.link('functions', json_object('function', $function)), 'functions.sql') + iif($function is not null, sqlpage.link('functions', json_object('function', $function)), 'functions.sql') ) as "Link"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', coalesce($function || ' - ', '') || 'SQLPage Functions Documentation' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-reference.sql', json_object( + 'kind', 'function', 'name', $function +)) as properties where $function is not null; + +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Functions - SQLPage Documentation', 'section', 'Functions', + 'description', 'Find SQLPage functions by purpose and see their arguments at a glance.' +)) as properties where $function is null; -select 'breadcrumb' as component; -select 'SQLPage' as title, '/' as link, 'Home page' as description; -select 'Functions' as title, '/functions.sql' as link, 'List of all functions' as description; -select $function as title, sqlpage.set_variable('function', $function) as link where $function IS NOT NULL; +select 'empty_state' as component, 'Function not found' as title, 'function' as icon, + 'Browse functions' as link_text, '/functions.sql' as link +where $function is not null and not exists (select 1 from sqlpage_functions where name = $function); -select 'text' as component, 'SQLPage built-in functions' as title where $function IS NULL; -select ' -In addition to normal SQL functions supported by your database, -SQLPage provides a few special functions to help you extract data from user requests. +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-catalog.sql', json_object( + 'kind', 'function', 'q', $q, 'category', $category +)) as properties where $function is null; -These functions are special because they are not database functions. -SQLPage evaluates them itself, either before or after the database query. +select 'title' as component, 'Function evaluation' as contents, 2 as level, 'evaluation' as id where $function is null; +select 'text' as component, true as article, ' +SQLPage evaluates its built-in functions itself, either before or after the database query. When a SQLPage function call is the whole value of a selected column, SQLPage first lets the database decide which rows exist. It selects the function arguments as hidden columns, then calls the SQLPage function once for each returned row. @@ -35,42 +41,3 @@ If a function should run only when a database row exists, put it as a standalone For more information about how SQLPage functions are evaluated, and data types in SQLPage, read [the SQLPage data model documentation](/extensions-to-sql). ' as contents_md where $function IS NULL; - -select 'list' as component, 'SQLPage functions' as title where $function IS NULL; -select name as title, - icon, - '?function=' || name || '#function' as link, - $function = name as active -from sqlpage_functions -where $function IS NULL -order by name; - -select 'text' as component, 'sqlpage.' || $function || '(' || string_agg(name, ', ') || ')' as title, 'function' as id -from sqlpage_function_parameters where $function IS NOT NULL and "function" = $function; - -select 'text' as component; -select 'Introduced in SQLPage ' || introduced_in_version || '.' as contents, 1 as size from sqlpage_functions where name = $function; - -SELECT description_md as contents_md FROM sqlpage_functions WHERE name = $function; - -select 'title' as component, 3 as level, 'Parameters' as contents where $function IS NOT NULL AND EXISTS (SELECT 1 from sqlpage_function_parameters where "function" = $function); -select 'card' as component, 3 AS columns where $function IS NOT NULL; -select - name as title, - description_md as description, - type as footer, - 'azure' as color -from sqlpage_function_parameters where "function" = $function -ORDER BY "index"; - -select - 'button' as component, - 'sm' as size, - 'pill' as shape; -select - name as title, - icon, - sqlpage.set_variable('function', name) as link -from sqlpage_functions -where $function IS NOT NULL -order by name; diff --git a/examples/official-site/index-old.sql b/examples/official-site/index-old.sql index 297d79070..ff13509d0 100644 --- a/examples/official-site/index-old.sql +++ b/examples/official-site/index-old.sql @@ -1,232 +1 @@ -select 'http_header' as component, - 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", - '; rel="canonical"' as "Link"; - --- Fetch the page title and header from the database -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; - -SELECT 'hero' as component, - 'From database to data app, fast.' as title, - '**SQLPage** lets you build data-driven applications in a few SQL queries. - -It's free, [open-source](https://github.com/sqlpage/SQLPage), lightweight, and easy to use. - ' as description_md, - 'sqlpage_cover_image.webp' as image, - TRUE as rounded, - 'your-first-sql-website/' as link, - 'Build your first SQL website !' as link_text; - --- the mantra: fast, beautiful, easy -SELECT 'Easy' as title, - 'You can teach yourself enough SQL to query and edit a database through SQLPage in a weekend. -We handle [security](safety.sql) and [performance](performance.sql) for you, so you can focus on your data.' as description_md, - 'sofa' as icon, - 'blue' as color; -SELECT 'Beautiful' as title, - 'The page you are looking at right now is written entirely in SQL. -No design skills are required, yet your website will be responsive, and look professional and modern by default.' as description, - 'eye' as icon, - 'green' as color; -SELECT 'Fast' as title, - 'Pages [load instantly](performance.sql), even on slow mobile networks. - SQLPage is designed as a single **lightweight** executable leveraging server-side rendering to ensure fast page loads even on low-cost servers.' as description_md, - 'mail-fast' as icon, - 'red' as color; - -SELECT 'hero' as component, - true as reverse, - '🧩 SQL User Interfaces' as title, - 'At the core of SQLPage is a [rich library of user interface components](/documentation.sql) for tables, charts, maps, timelines, forms and much more. - -To build your app, you just populate the components with data returned by your database queries.' as description_md, - 'sqlpage_illustration_components.webp' as image; - -SELECT 'hero' as component, - '🪄 Seamlessly' as title, - 'SQLPage handles HTTP requests, database connections, streaming rendering, styling, [security](safety.sql), and [performance](performance.sql) for you. - -Focus only on your data, and how you want to present it. We''ve tamed the tech, you tame the data.' as description_md, - 'sqlpage_illustration_alien.webp' as image; - --- Quick feature overview -SELECT 'card' as component, - 'What is SQLPage ?' as title, - 1 as columns; -SELECT '✨ SQLPage turns your SQL queries into eye-catching websites' as title, - ' -SQLPage is a tool that allows you to **build websites** using nothing more than **SQL queries**. -You write simple text files containing SQL queries, SQLPage runs them on your database, and **renders the results as a website**. - -You can display the information you `SELECT` from your database in -lists, tables, charts, maps, forms, and many other user interface widgets. -But you can also `INSERT`, `UPDATE` and `DELETE` data from your database using SQLPage, and build a full webapp.' as description_md, - 'paint' as icon, - 'blue' as color; -SELECT '🧩 Pre-built components let you construct websites Quickly and Easily' as title, - 'At the core of SQLPage is [a rich library of **components**](./documentation.sql). - These components are built using traditional web technologies, but you never have to edit them if you don''t want to. - SQLPage populates the components with data returned by your SQL queries. - You can build entire web applications just by combining the components that come bundled with SQLPage. - -As an example, the list of features on this page is generated using a simple SQL query that looks like this: - -```sql -SELECT ''card'' as component, ''What is SQLPage ?'' as title; -SELECT header AS title, contents AS description_md FROM homepage_features; -``` - -However, you can also create your own components, or edit the existing ones to customize your website to your liking. -Creating a new component is as simple as creating an HTML template file. -' as description_md, - 'rocket' as icon, - 'green' as color; -SELECT '🛡️ A secure web server written in Rust' as title, - 'SQLPage removes a lot of the complexity and bloat of the modern web. -It''s a **lightweight web server** that just receives a request, finds the file to execute, runs it, -and returns a web page for the browser to display. - -Written in a fast and secure programming language ([**Rust**](https://en.wikipedia.org/wiki/Rust_(programming_language))), -it empowers non-developers to build secure web applications easily. You download [a single executable file](https://github.com/sqlpage/SQLPage/releases), -write an `index.sql`, and in five minutes you turned your database into a website that you can -[deploy on the internet easily](https://datapage.app). - -We made all the [optimizations](performance.sql), wrote all of the HTTP request handling code and rendering logic, -implemented all of the security features, so that you can think about your data, and nothing else. - -When SQLPage receives a request, it finds the corresponding SQL file (with or without the .sql extension), runs it on the database, passing it information from the web request as SQL statement parameters [in a safe manner](safety.sql). -When the database starts returning rows for the query, -SQLPage maps each piece of information in the row to a parameter in the template of a pre-defined component, -and streams the result back to the user's browser. -' as description_md, - 'server' as icon, - 'purple' as color; -SELECT '🌱 Start Simple, Scale to Advanced' as title, - 'SQLPage is a great starting point for building websites, internal tools, dashboards and data applications, -especially if you don''t have a lot of time, but need something more powerful and user-friendly than a spreadsheet. - -When your app grows, you can take the same underlying data structure and queries, -and wrap them in a more established framework with a dedicated front end if you need to. -There is no lock-in, only simple, standard SQL queries that run directly on your database. - -**Focus on what matters** first: your data and your users. Not centering boxes in CSS, not setting up a web framework.' as description_md, - 'world-cog' as icon, - 'orange' as color; - --- Useful links -SELECT 'list' as component, - 'Get started: where to go from here ?' as title, - 'Here are some useful links to get you started with SQLPage.' as description; -SELECT 'Download' as title, - 'https://github.com/sqlpage/SQLPage/releases' as link, - 'SQLPage is distributed as a single binary that you can execute locally or on a web server to get started quickly.' as description, - 'green' as color, - 'download' as icon; -SELECT 'Tutorial' as title, - 'get started.sql' as link, - 'A short tutorial that will guide you through the creation of your first SQL-only website.' as description, - 'orange' as color, - 'book' as icon, - TRUE as active; -SELECT 'SQLPage Documentation' as title, - 'documentation.sql' as link, - 'List of all available components, with examples of how to use them.' as description, - 'purple' as color, - 'book' as icon; -SELECT 'Technical documentation on Github' as title, - 'https://github.com/sqlpage/SQLPage/blob/main/README.md#sqlpage' as link, - 'The official README file on Github contains instructions to get started using SQLPage.' as description, - 'yellow' as color, - 'file-text' as icon; -SELECT 'Youtube Video Series' as title, - 'https://www.youtube.com/playlist?list=PLTue_qIAHxAf9fEjBY2CN0N_5XOiffOk_' as link, - 'A series of video tutorials that will guide you through the creation of an application with SQLPage.' as description, - 'red' as color, - 'brand-youtube' as icon; -SELECT 'Learnsqlpage.com' as title, - 'https://learnsqlpage.com' as link, - 'A website dedicated to learning SQLPage, with detailed tutorials.' as description, - 'blue' as color, - 'globe' as icon; - -SELECT 'list' as component, 'Examples' as title; -SELECT 'Github Examples' as title, - 'https://github.com/sqlpage/SQLPage/tree/main/examples/' as link, - 'SQL source code for examples and demos of websites built with SQLPage.' as description, - 'teal' as color, - 'code' as icon; -SELECT 'Corporate Conundrum' as title, - 'https://conundrum.ophir.dev' as link, - 'A demo web application powered by SQLPage, designed for playing a fun trivia board game with friends.' as description, - 'cyan' as color, - 'affiliate' as icon; - -SELECT 'list' as component, 'Community' as title; -SELECT 'Discussion forum' as title, - 'https://github.com/sqlpage/SQLPage/discussions' as link, - 'Come to our community page to discuss SQLPage with other users and ask questions.' as description, - 'pink' as color, - 'user-heart' as icon; --- github link -SELECT 'Source code' as title, - 'https://github.com/sqlpage/SQLPage' as link, - 'The rust source code for SQLPage itself is open and available on Github.' as description, - 'github' as color, - 'brand-github' as icon; -SELECT 'Report a bug, make a suggestion' as title, - 'https://github.com/sqlpage/SQLPage/issues' as link, - 'If you have a question, a suggestion, or if you found a bug, please open an issue on Github.' as description, - 'red' as color, - 'bug' as icon; - --- User personas: who is SQLPage for ? -SELECT 'card' as component, - 'Is SQLPage for you ?' as title, - ' -SQLPage empowers SQL-savvy individuals to create dynamic websites without complex programming. - - - If you are looking to quickly build something simple yet dynamic, SQLPage is for you. - - If you want to customize how every pixel of your website looks, SQLPage is not for you. - -Compared to other low-code platforms, SQLPage focuses on SQL-driven development, more lightweight performance, and total openness. -Where other platforms try to lock you in, SQLPage makes it trivial to switch to something else when your application grows.' as description_md, - 4 as columns; -SELECT 'Business Analyst' as title, - 'Replace static dashboards with dynamic websites' as description, - 'Business analysts can leverage SQLPage to create interactive and real-time data visualizations, replacing traditional static dashboards and enabling more dynamic and insightful reporting.' as footer, - 'green' as color, - 'chart-arrows-vertical' as icon; -SELECT 'Data Scientist' as title, - 'Prototype and share data-driven experiments and analysis' as description, - 'Data scientists can utilize SQLPage to quickly prototype and share their data-driven experiments and analysis by creating interactive web applications directly from SQL queries, enabling collaboration and faster iterations.' as footer, - 'purple' as color, - 'square-root-2' as icon; -SELECT 'Marketer' as title, - 'Create dynamic landing pages and personalized campaigns' as description, - 'Marketers can leverage SQLPage to create dynamic landing pages and personalized campaigns by fetching and displaying data from databases, enabling targeted messaging and customized user experiences.' as footer, - 'orange' as color, - 'message-circle-dollar' as icon; -SELECT 'Engineer' as title, - 'Build internal tools and admin panels with ease' as description, - 'Engineers can use SQLPage to build internal tools and admin panels, utilizing their SQL skills to create custom interfaces and workflows, streamlining processes and improving productivity.' as footer, - 'blue' as color, - 'settings' as icon; -SELECT 'Product Manager' as title, - 'Create interactive prototypes and mockups' as description, - 'Product managers can leverage SQLPage to create interactive prototypes and mockups, allowing stakeholders to experience and provide feedback on website functionalities before development, improving product design and user experience.' as footer, - 'red' as color, - 'cube-send' as icon; -SELECT 'Educator' as title, - 'Develop interactive learning materials and exercises' as description, - 'Educators can utilize SQLPage to develop interactive learning materials and exercises, leveraging SQLPage components to present data and engage students in a dynamic online learning environment.' as footer, - 'yellow' as color, - 'school' as icon; -SELECT 'Researcher' as title, - 'Create data-driven websites to share findings and insights' as description, - 'Researchers can use SQLPage to create data-driven websites, making complex information more accessible and interactive for the audience, facilitating knowledge dissemination and engagement.' as footer, - 'cyan' as color, - 'flask-2' as icon; -SELECT 'Startup Founder' as title, - 'Quickly build a Minimum Viable Product' as description, - 'Startup founders can quickly build a Minimum Viable Product (MVP) using their SQL expertise with SQLPage, creating a functional website with database integration to validate their business idea and gather user feedback.' as footer, - 'pink' as color, - 'rocket' as icon; +select 'redirect' as component, '/' as link; diff --git a/examples/official-site/llms.txt.sql b/examples/official-site/llms.txt.sql index a1f5cda56..359dbe285 100644 --- a/examples/official-site/llms.txt.sql +++ b/examples/official-site/llms.txt.sql @@ -3,6 +3,30 @@ select 'text/markdown; charset=utf-8' as "Content-Type", 'inline; filename="llms.txt"' as "Content-Disposition"; +with parameter_sections as ( + select kind, entry, section_order, '#### ' || title || char(10, 10) || group_concat( + format('- `%s` (%s)%s: %s', name, type, case when not optional then ' **REQUIRED**' else '' end, + replace(trim(description_md, char(13, 10)), char(10), char(10) || ' ')), + char(10) order by position, name + ) as contents + from reference_parameter + group by kind, entry, section_order, title +), parameters as ( + select kind, entry, group_concat(contents, char(10, 10) order by section_order) as contents + from parameter_sections group by kind, entry +), entries as ( + select e.kind, e.name, + '### [' || case e.kind when 'function' then 'sqlpage.' || e.name || '()' else e.name end || '](' || e.link || ')' || + coalesce(char(10, 10) || 'Since SQLPage ' || e.introduced_in_version || '.', '') || + coalesce(char(10, 10) || 'Returns `' || e.return_type || '`.', '') || + -- Quote the original Markdown so its headings and code fences stay inside the entry. + char(10, 10) || '> ' || replace(trim(e.description_md, char(13, 10)), char(10), char(10) || '> ') || + coalesce(char(10, 10) || p.contents, '') as contents + from reference_entry as e left join parameters as p on p.kind = e.kind and p.entry = e.name +), chapters as ( + select kind, group_concat(contents, char(10, 10) order by name) as contents + from entries group by kind +) select 'shell-empty' as component, '# SQLPage @@ -24,107 +48,17 @@ Key features: ## Core Documentation -- [Components reference](/documentation.sql): List of all ' || ( - select - count(*) - from - component - ) || ' built-in UI components with parameters and examples +- [Components reference](/components.sql): List of all ' || (select count(*) from component) || ' built-in UI components with parameters and examples - [Functions reference](/functions.sql): SQLPage built-in functions for handling requests, encoding data, and more - [Configuration guide](https://github.com/sqlpage/SQLPage/blob/main/configuration.md): Complete list of configuration options in sqlpage.json ## Components -' || ( - select - group_concat ( - '### [' || c.name || '](/component.sql?component=' || c.name || ') - -' || c.description || ' - -' || ( - select - case when exists ( - select - 1 - from - parameter - where - component = c.name - and top_level - ) then '#### Top-level parameters - -' || group_concat ( - '- `' || name || '` (' || type || ')' || case when not optional then ' **REQUIRED**' else '' end || ': ' || description, - char(10) - ) - else - '' - end - from - parameter - where - component = c.name - and top_level - ) || ' - -' || ( - select - case when exists ( - select - 1 - from - parameter - where - component = c.name - and not top_level - ) then '#### Row-level parameters - -' || group_concat ( - '- `' || name || '` (' || type || ')' || case when not optional then ' **REQUIRED**' else '' end || ': ' || description, - char(10) - ) - else - '' - end - from - parameter - where - component = c.name - and not top_level - ) || ' - -', - '' - ) - from - component c - order by - c.name - ) || ' +' || (select contents from chapters where kind = 'component') || ' ## Functions -' || ( - select - group_concat ( - '### [sqlpage.' || name || '()](/functions.sql?function=' || name || ') -' || replace ( - replace ( - description_md, - char(10) || '#', - char(10) || '###' - ), - ' ', - ' ' - ), - char(10) - ) - from - sqlpage_functions - order by - name - ) || ' +' || (select contents from chapters where kind = 'function') || ' ## Examples @@ -142,4 +76,4 @@ Key features: - [Docker deployment](https://github.com/sqlpage/SQLPage#with-docker): Running SQLPage in containers - [Systemd service](https://github.com/sqlpage/SQLPage/blob/main/sqlpage.service): Production deployment setup - [Repository structure](https://github.com/sqlpage/SQLPage/blob/main/CONTRIBUTING.md): Project organization and contribution guide -' as html; \ No newline at end of file +' as html; diff --git a/examples/official-site/performance.sql b/examples/official-site/performance.sql index 332f6e3b6..12a81e96c 100644 --- a/examples/official-site/performance.sql +++ b/examples/official-site/performance.sql @@ -2,10 +2,7 @@ select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", '; rel="canonical"' as "Link"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'SQLPage applications are fast' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'SQLPage applications are fast' as title; select 'hero' as component, 'Performance in SQLPage' as title, @@ -14,8 +11,6 @@ select 'hero' as component, select 'text' as component, ' -# Performance of SQLPage applications - In SQLPage, the website author *declaratively* specifies the contents and behavior of the website using SQL queries, as opposed to writing imperative code in a backend programming language like Java, Ruby, Python, or PHP. @@ -91,12 +86,8 @@ interaction. Performance is a key feature of SQLPage. Its architecture allows you to build fast websites without having to implement advanced optimizations yourself. -## Ready to get started? - -[Build your fast, secure, and beautiful website](/your-first-sql-website) with SQLPage today! - -## Already a SQLPage developer ? +## Tutorials and performance tuning -Have a look at our [performance guide](/blog?post=Performance+Guide) to learn the best practices to leverage -all the features that will make your site faster. +- [Build your first SQLPage website](/your-first-sql-website/). +- [Tune queries and database connections in an existing application](/blog?post=Performance+Guide). ' as contents_md; diff --git a/examples/official-site/pricing.sql b/examples/official-site/pricing.sql index 0a52fa78d..994998d77 100644 --- a/examples/official-site/pricing.sql +++ b/examples/official-site/pricing.sql @@ -73,7 +73,5 @@ SELECT 'ENTREPRISE PLAN' as title, 'bubble-plus' as icon, 'red' as color; -SELECT 'text' as component, -'' as title, -'## **Ready to Get Started?** -[Sign Up Now](https://datapage.app) and start building your SQLPage app with Datapage.app today!' as contents_md; +select 'text' as component, + '[Create a DataPage account](https://datapage.app)' as contents_md; diff --git a/examples/official-site/safety.sql b/examples/official-site/safety.sql index a9af1f140..2ba06a7fc 100644 --- a/examples/official-site/safety.sql +++ b/examples/official-site/safety.sql @@ -2,10 +2,7 @@ select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", '; rel="canonical"' as "Link"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'Security in SQLPage: SSO, protection against SQLi, XSS, CSRF, and more' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Security in SQLPage: SSO, protection against SQLi, XSS, CSRF, and more' as title; select 'hero' as component, 'SQLPage''s security guarantees' as title, diff --git a/examples/official-site/search.sql b/examples/official-site/search.sql index 2f5232a8c..02bf50085 100644 --- a/examples/official-site/search.sql +++ b/examples/official-site/search.sql @@ -1,117 +1,36 @@ set search = nullif(trim($search), ''); --- Check for exact matches and redirect if found -set redirect = CASE - WHEN EXISTS (SELECT 1 FROM component WHERE name = $search) THEN sqlpage.link('/component.sql', json_object('component', $search)) - WHEN EXISTS (SELECT 1 FROM sqlpage_functions WHERE name = $search) THEN sqlpage.link('/functions.sql', json_object('function', $search)) -END -SELECT 'redirect' as component, $redirect as link WHERE $redirect IS NOT NULL; +-- An unqualified name shared by a component and a function opens the component. +select 'redirect' as component, link from reference_entry +where name = lower($search) or (kind = 'function' and lower($search) in ( + name || '()', 'sqlpage.' || name, 'sqlpage.' || name || '()' +)) +order by kind limit 1; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', coalesce($search || ' | ', '') || 'SQLPage documentation search' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, coalesce($search || ' | ', '') || 'SQLPage documentation search' as title; -SELECT 'form' as component, - 'GET' as method, - true as auto_submit, - 'Search documentation' as title; +select 'title' as component, 'Search documentation' as contents, 1 as level; -SELECT 'text' as type, - 'search' as name, - '' as label, - true as autofocus, - 'Search for components, parameters, functions...' as placeholder, - $search as value; +select 'form' as component, 'GET' as method, 'Search' as validate; +select 'search' as type, 'search' as name, 'Search the documentation' as label, + 'Tutorials, components, functions…' as placeholder, true as autofocus, $search as value; -set escaped_search = '"' || replace($search, '"', '""') || '"'; +-- Treat the input as a literal phrase in SQLite's full-text query syntax. +set escaped_search = '"' || replace(coalesce($search, ''), '"', '""') || '"'; -SELECT 'text' as component, - CASE - WHEN $search IS NULL THEN 'Enter a search term above to find documentation about components, parameters, functions, and blog posts.' - WHEN NOT EXISTS ( - SELECT 1 FROM documentation_fts - WHERE documentation_fts = $escaped_search - ) THEN 'No results found for "' || $search || '".' - ELSE NULL - END as contents; +select 'list' as component, 'Search results' as title, 'No results' as empty_title, + 'No documentation matched “' || $search || '”.' as empty_description +where $search is not null; -SELECT 'list' as component, - 'Search Results' as title, - 'No results found for "' || $search || '".' as empty_description -WHERE $search IS NOT NULL; - -WITH search_results AS ( - SELECT - COALESCE( - component_name || ' component: parameter ' || parameter_name - , component_name || ' component' || IF(component_example_description IS NULL, '', ' example') - , 'blog: ' || blog_title - , 'sqlpage.' || function_name || '(...' || function_parameter_name || '...)' - , 'sqlpage.' || function_name || '(...)' - ) as title, - COALESCE( - component_description, - parameter_description, - blog_description, - function_parameter_description, - function_description, - component_example_description - ) as description, - CASE - WHEN component_name IS NOT NULL THEN - json_object( - 'page', '/component.sql', - 'parameters', json_object('component', component_name) - ) - WHEN parameter_name IS NOT NULL THEN - json_object( - 'page', '/component.sql', - 'parameters', json_object('component', ( - SELECT component - FROM parameter - WHERE name = parameter_name - LIMIT 1 - )) - ) - WHEN blog_title IS NOT NULL THEN - json_object( - 'page', '/blog.sql', - 'parameters', json_object('post', blog_title) - ) - WHEN function_name IS NOT NULL THEN - json_object( - 'page', '/functions.sql', - 'parameters', json_object('function', function_name) - ) - WHEN function_parameter_name IS NOT NULL THEN - json_object( - 'page', '/functions.sql', - 'parameters', json_object('function', ( - SELECT function - FROM sqlpage_function_parameters - WHERE name = function_parameter_name - LIMIT 1 - )) - ) - END as link_data, - rank - FROM documentation_fts - WHERE $search IS NOT NULL - AND documentation_fts = $escaped_search +with matches as ( + select title, trim(description, char(13) || char(10) || ' ') as summary, page, parameters, fragment, rank, + row_number() over (partition by page, parameters order by rank, rowid) as position + from documentation_fts + where documentation_fts match $escaped_search ) -SELECT - max(title) as title, - max(description) as description, - sqlpage.link(link_data->>'page', link_data->'parameters') as link -FROM search_results -GROUP BY link_data -ORDER BY - rank, - CASE - WHEN title LIKE 'component:%' THEN 1 - WHEN title LIKE 'parameter:%' THEN 2 - WHEN title LIKE 'blog:%' THEN 3 - WHEN title LIKE 'function:%' THEN 4 - END, - description; +select title, + ltrim(substr(summary, 1, instr(summary || char(10), char(10)) - 1), '# ') as description, + sqlpage.link(page, parameters, fragment) as link +from matches +where position = 1 +order by rank, title; diff --git a/examples/official-site/sqlpage/docs-catalog.sql b/examples/official-site/sqlpage/docs-catalog.sql new file mode 100644 index 000000000..90f4381d6 --- /dev/null +++ b/examples/official-site/sqlpage/docs-catalog.sql @@ -0,0 +1,61 @@ +set options = sqlpage.variables('set'); +set kind = $options->>'kind'; +set query = trim(coalesce($options->>'q', '')); +set search = lower(case when $kind = 'function' and lower($query) like 'sqlpage.%' + then substr($query, 9) else $query end); +set action = case $kind when 'component' then '/components.sql' else '/functions.sql' end; +set search_url = $action || case when $query = '' then '' else '?q=' || sqlpage.url_encode($query) end; + +-- Keep the counts for every category when showing only the selected category's rows. +set groups = ( + with candidates as ( + select *, + instr(lower(name || coalesce('(' || arguments || ')', '') || char(10) || + replace(name, '_', ' ') || char(10) || coalesce(summary, '')), $search) > 0 + or ($kind = 'function' and $search in ( + name || '()', name || '(' || replace(replace(arguments, '[', ''), ']', '') || ')' + )) as matches + from reference_entry where kind = $kind + ), categories as ( + select category_id, category_title, category_order, + json_group_array(json_object( + 'name', name, 'icon', icon, 'summary', summary, 'link', link, + 'arguments', arguments, 'example_count', example_count + ) order by name) filter (where matches) as entries + from candidates + group by category_id, category_title, category_order + ) + select json_group_array(json_object( + 'id', category_id, 'title', category_title, + 'count', json_array_length(entries), 'entries', json(entries) + ) order by category_order) + from categories +); +set category = coalesce(( + select value->>'id' from json_each($groups) where value->>'id' = $options->>'category' +), ''); + +select 'docs-catalog' as component, $kind as kind, $kind || 's' as plural, + $query as query, $category as category, $action as action, + $action || '#catalog' as clear_link, $search_url || '#catalog' as all_link, + max(value->>'title') filter (where value->>'id' = $category) as category_title, + coalesce(sum(value->>'count'), 0) as all_count, + coalesce(sum(value->>'count') filter (where $category = '' or value->>'id' = $category), 0) as matched, + json_group_array(json_object( + 'id', value->>'id', 'title', value->>'title', 'count', value->>'count', + 'active', value->>'id' = $category, + 'link', $search_url || case when $query = '' then '?' else '&' end + || 'category=' || (value->>'id') || '#catalog' + ) order by key) as categories, + json(case when $kind = 'component' then ( + select json_group_array(json_object('name', name, 'link', link) + order by case name when 'table' then 1 when 'form' then 2 else 3 end) + from reference_entry where kind = 'component' and name in ('table', 'form', 'chart') + ) end) as picks, + case when $kind = 'function' then sqlpage.url_encode('hello world') end as encoded_example +from json_each($groups); + +select value->>'id' as id, value->>'title' as title, json(value->'entries') as entries +from json_each($groups) +where value->>'count' > 0 and ($category = '' or value->>'id' = $category) +order by key; diff --git a/examples/official-site/sqlpage/docs-intro-example.sql b/examples/official-site/sqlpage/docs-intro-example.sql new file mode 100644 index 000000000..8bd8b2d9b --- /dev/null +++ b/examples/official-site/sqlpage/docs-intro-example.sql @@ -0,0 +1,3 @@ +select 'list' as component, 'Reading list' as title; +select 'The list component' as title, + '/component.sql?component=list' as link; diff --git a/examples/official-site/sqlpage/docs-reference.sql b/examples/official-site/sqlpage/docs-reference.sql new file mode 100644 index 000000000..4f2094bd9 --- /dev/null +++ b/examples/official-site/sqlpage/docs-reference.sql @@ -0,0 +1,40 @@ +-- Render the common parts of a component or function reference from its catalog entry. +set options = sqlpage.variables('set'); +set kind = $options->>'kind'; +set name = $options->>'name'; +set section = case $kind when 'component' then 'Components' else 'Functions' end; + +set outline = ( + select json_group_array(json_object('title', title, 'link', '#' || id) order by position) + from ( + select 0 as position, 'Overview' as title, kind as id from reference_entry where kind = $kind and name = $name + union all + select distinct section_order, title, section from reference_parameter where kind = $kind and entry = $name + union all + select 3, 'Examples', 'examples' from reference_entry where kind = $kind and name = $name and example_count > 0 + ) +); + +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', case $kind when 'function' then 'sqlpage.' || $name else $name end || ' - SQLPage Documentation', + 'section', $section, 'current', $name, 'outline', $outline +)) as properties; + +select 'docs-reference-heading' as component, kind as id, + case kind when 'component' then 'Component reference' else 'Function reference' end as section, + '/' || lower($section) || '.sql' as link, + case kind when 'component' then 'The ' || name || ' component' + else 'sqlpage.' || name || '(' || arguments || ')' end as title, + icon, introduced_in_version as version, return_type, + case when example_count > 0 then '#examples' end as jump_link, 'View examples' as jump_text +from reference_entry where kind = $kind and name = $name; + +select 'text' as component, true as article, description_md as contents_md +from reference_entry where kind = $kind and name = $name; + +select 'docs-parameters' as component; +select section as id, title, introduction, json_group_array(json_object( + 'name', name, 'type', type, 'required', not optional, 'description_md', description_md, 'anchor', anchor +) order by position, name) as parameters +from reference_parameter where kind = $kind and entry = $name +group by section_order, section, title, introduction order by section_order; diff --git a/examples/official-site/sqlpage/docs-shell.sql b/examples/official-site/sqlpage/docs-shell.sql new file mode 100644 index 000000000..51ccedd67 --- /dev/null +++ b/examples/official-site/sqlpage/docs-shell.sql @@ -0,0 +1,24 @@ +set options = sqlpage.variables('set'); +set section = $options->>'section'; +set kind = case $section when 'Components' then 'component' when 'Functions' then 'function' end; +set catalog = $kind is not null and $options->>'current' is null; + +select 'shell-docs' as component, + $options->>'title' as title, + $options->>'description' as description, + $section as section, + cast($catalog as integer) as catalog, + coalesce($kind || 's', 'guides') as topic_label, + '/' || $kind || 's.sql' as catalog_link, + $options->>'current' as current_item, + nullif($options->>'outline', '[]') as outline, + case + when $catalog then null + when $kind is not null then ( + select json_group_array(json_object('title', name, 'link', link) order by name) + from reference_entry where kind = $kind + ) + else ( + select json_group_array(json_object('title', title, 'link', link) order by sort_order) from guide + ) + end as topics; diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 53d879b1f..ff7917b34 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -29,6 +29,32 @@ CREATE TABLE example( FOREIGN KEY (component) REFERENCES component(name) ON DELETE CASCADE ); +-- The reference shows the SQL and renders the same stored component rows. +-- Arrays with several items become repeated column aliases, as in handwritten SQLPage files. +CREATE VIEW example_with_source AS +SELECT example.rowid AS example_id, + row_number() OVER (PARTITION BY component ORDER BY example.rowid) AS example_number, + example.*, + (SELECT group_concat('select' || char(10) || ( + WITH fields AS ( + SELECT field.key AS name, coalesce(item.type, field.type) AS type, + CASE WHEN item.key IS NULL THEN field.value ELSE item.value END AS value + FROM json_each(statement.value) AS field + LEFT JOIN json_each( + CASE WHEN field.type = 'array' AND json_array_length(field.value) > 1 THEN field.value END + ) AS item ON true + ) + SELECT group_concat(' ' || CASE type + WHEN 'true' THEN 'TRUE' + WHEN 'false' THEN 'FALSE' + WHEN 'array' THEN 'JSON(' || quote(value) || ')' + WHEN 'object' THEN 'JSON(' || quote(value) || ')' + ELSE quote(value) + END || format(' as "%w"', name), ',' || char(10)) + FROM fields + ) || ';', char(10) || char(10)) FROM json_each(example.properties) AS statement) AS source +FROM example; + INSERT INTO component(name, icon, description) VALUES ('list', 'list', 'A vertical list of items. Each item can be clickable and link to another page.'); INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'list', * FROM (VALUES @@ -217,19 +243,19 @@ INSERT INTO example(component, description, properties) VALUES INSERT INTO component(name, icon, description) VALUES ('form', 'cursor-text', ' -# Building forms in SQL +## Building forms in SQL The form component will display a series of input fields of various types, that can be filled in by the user. When the user submits the form, the data is posted to an SQL file specified in the `action` property. -## Handle Data with SQL +### Handling submitted values The receiving SQL page will be able to handle the data, and insert it into the database, use it to perform a search, format it, update existing data, etc. A value in a field named "x" will be available as `:x` in the SQL query of the target page. -## Examples +### Form projects - [A multi-step form](https://github.com/sqlpage/SQLPage/tree/main/examples/forms-with-multiple-steps), guiding the user through a process without overwhelming them with a large form. - [File upload form](https://github.com/sqlpage/SQLPage/tree/main/examples/image%20gallery%20with%20user%20uploads), letting users upload images to a gallery. @@ -1116,7 +1142,7 @@ Numbers can be displayed ), ( 'table', - '# Dynamic column names in a table + '#### Dynamic column names in a table In all the previous examples, the column names were hardcoded in the SQL query. This makes it very easy to quickly visualize the results of a query as a table, @@ -1521,10 +1547,9 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S INSERT INTO example(component, description, properties) VALUES ('shell', ' -This example contains the values used for the shell of the page you are currently viewing. +This example configures a dark shell with menus linking to pages on this site. -The `menu_item` property is used both in its simple string form, to generate a link named "functions" that points to "functions.sql", -and in its object form, to generate a dropdown menu named "Community" with links to the blog, the github repository, and the issues page. +Each `menu_item` object defines a link or a dropdown. The "Community" menu links to the blog, issue tracker, discussions, and source code. The object form can be used directly only on database engines that have a native JSON type. On other engines (such as SQLite), you can use the [`dynamic`](?component=dynamic#component) component to generate the same result. @@ -1575,13 +1600,7 @@ You see the [page layouts demo](./examples/layouts.sql) for a live example of th "font_size": 19, "image": "/assets/icon.webp", "favicon": "/favicon.ico", - "javascript": [ - "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/highlight.min.js", - "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/languages/sql.min.js", - "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/languages/handlebars.min.js", - "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11/build/languages/json.min.js", - "/assets/highlightjs-launch.js" - ], + "javascript_module": "/assets/highlightjs-launch.js", "css": "/assets/highlightjs-and-tabler-theme.css", "footer": "[Built with SQLPage](https://github.com/sqlpage/SQLPage/tree/main/examples/official-site)" }]')), diff --git a/examples/official-site/sqlpage/migrations/02_hero_component.sql b/examples/official-site/sqlpage/migrations/02_hero_component.sql index f7e45d63e..bee6a8d90 100644 --- a/examples/official-site/sqlpage/migrations/02_hero_component.sql +++ b/examples/official-site/sqlpage/migrations/02_hero_component.sql @@ -164,7 +164,7 @@ VALUES "component":"hero", "title": "SQLPage", "description_md": "Documentation for the *SQLPage* low-code web application framework.", - "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Lac_de_Zoug.jpg/640px-Lac_de_Zoug.jpg", + "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Lac_de_Zoug.jpg/1280px-Lac_de_Zoug.jpg", "link": "/documentation.sql", "link_text": "Read Documentation !"},' || '{"title": "Fast", "description": "Pages load instantly, even on slow mobile networks.", "icon": "car", "color": "red", "link": "/"},' || '{"title": "Beautiful", "description": "Uses pre-defined components that look professional.", "icon": "eye", "color": "green", "link": "/"},' || '{"title": "Easy", "description_md": "You can teach yourself enough SQL to use [**SQLPage**](https://sql-page.com) in a weekend.", "icon": "sofa", "color": "blue", "link": "/"}' || ']' ) @@ -178,7 +178,7 @@ VALUES "title": "Databases", "reverse": true, "description_md": "# “The goal is to turn data into information, and information into insight.”", - "poster": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Lac_de_Zoug.jpg/640px-Lac_de_Zoug.jpg", + "poster": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Lac_de_Zoug.jpg/1280px-Lac_de_Zoug.jpg", "video": "/sqlpage_introduction_video.mp4" }]') ); \ No newline at end of file diff --git a/examples/official-site/sqlpage/migrations/07_authentication.sql b/examples/official-site/sqlpage/migrations/07_authentication.sql index c759dee8b..ca44e9c48 100644 --- a/examples/official-site/sqlpage/migrations/07_authentication.sql +++ b/examples/official-site/sqlpage/migrations/07_authentication.sql @@ -120,10 +120,10 @@ but it is not very flexible nor user-friendly, because the browser will show an unstyled popup asking for the username and password. For more advanced authentication, you can store user information and user sessions in your database. -You can then use the [`form`](components.sql?component=form#component) component to create a custom login form. +You can then use the [`form`](/component.sql?component=form#component) component to create a custom login form. When the user submits the form, you check if the password is correct using the `authentication` component. You then store a unique string of numbers and letters (a session token) both in the user''s browser -using the [`cookie`](components.sql?component=cookie#component) component and in your database. +using the [`cookie`](/component.sql?component=cookie#component) component and in your database. Then, in all the pages that require authentication, you check if the cookie is present and matches the session token in your database. You can check if the user has sent the correct password in a form, and if not, redirect them to a login page. diff --git a/examples/official-site/sqlpage/migrations/18_button.sql b/examples/official-site/sqlpage/migrations/18_button.sql index 6ddb39a48..94104ca1b 100644 --- a/examples/official-site/sqlpage/migrations/18_button.sql +++ b/examples/official-site/sqlpage/migrations/18_button.sql @@ -2,7 +2,7 @@ -- Component Definition INSERT INTO component(name, icon, description, introduced_in_version) VALUES - ('button', 'hand-click', 'A versatile button component do display one or multiple button links of different styles.', '0.14.0'); + ('button', 'hand-click', 'Displays one or more buttons that follow links, download files, or submit a form.', '0.14.0'); -- Inserting parameter information for the button component INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'button', * FROM (VALUES diff --git a/examples/official-site/sqlpage/migrations/23_uploaded_file_functions.sql b/examples/official-site/sqlpage/migrations/23_uploaded_file_functions.sql index 30fcb2e86..f97ce0ea0 100644 --- a/examples/official-site/sqlpage/migrations/23_uploaded_file_functions.sql +++ b/examples/official-site/sqlpage/migrations/23_uploaded_file_functions.sql @@ -168,15 +168,6 @@ VALUES ( 'name', 'Name of the file input field in the form.', 'TEXT' -), -( - 'uploaded_file_path', - 2, - 'allowed_mime_type', - 'Makes the function return NULL if the uploaded file is not of the specified MIME type. - If omitted, any MIME type is allowed. - This makes it possible to restrict the function to only accept certain file types.', - 'TEXT' ), ( 'uploaded_file_mime_type', diff --git a/examples/official-site/sqlpage/migrations/34_carousel.sql b/examples/official-site/sqlpage/migrations/34_carousel.sql index 6736ccffe..2de411174 100644 --- a/examples/official-site/sqlpage/migrations/34_carousel.sql +++ b/examples/official-site/sqlpage/migrations/34_carousel.sql @@ -142,7 +142,7 @@ VALUES ( JSON( '[ {"component":"carousel","name":"cats1","title":"Famous Database Animals"}, - {"image":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Elefantes_africanos_de_sabana_%28Loxodonta_africana%29%2C_Elephant_Sands%2C_Botsuana%2C_2018-07-28%2C_DD_114-117_PAN.jpg/2560px-Elefantes_africanos_de_sabana_%28Loxodonta_africana%29%2C_Elephant_Sands%2C_Botsuana%2C_2018-07-28%2C_DD_114-117_PAN.jpg"}, + {"image":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Elefantes_africanos_de_sabana_%28Loxodonta_africana%29%2C_Elephant_Sands%2C_Botsuana%2C_2018-07-28%2C_DD_114-117_PAN.jpg/1280px-Elefantes_africanos_de_sabana_%28Loxodonta_africana%29%2C_Elephant_Sands%2C_Botsuana%2C_2018-07-28%2C_DD_114-117_PAN.jpg"}, {"image":"https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Penguin_Island_panorama_with_ferry_and_dolphins_in_foreground%2C_March_2023_06.jpg/1280px-Penguin_Island_panorama_with_ferry_and_dolphins_in_foreground%2C_March_2023_06.jpg"} ]' ) @@ -152,9 +152,9 @@ VALUES ( 'An advanced example of carousel with controls', JSON( '[ - {"component":"carousel","title":"SQL web apps","width":6, "center":true,"controls":true,"auto":true}, + {"component":"carousel","title":"SQL web apps","width":10, "center":true,"controls":true,"auto":true}, {"image":"/sqlpage_cover_image.webp","title":"SQLPage is modern","description":"Built by engineers who have built so many web applications the old way, they decided they just wouldn''t anymore.", "height": 512}, {"image":"/sqlpage_illustration_alien.webp","title":"SQLPage is easy", "description":"SQLPage connects to your database, then it turns your SQL queries into nice websites.", "height": 512} ]' ) - ); \ No newline at end of file + ); diff --git a/examples/official-site/sqlpage/migrations/40_fetch.sql b/examples/official-site/sqlpage/migrations/40_fetch.sql index f56020b3b..0118eaa49 100644 --- a/examples/official-site/sqlpage/migrations/40_fetch.sql +++ b/examples/official-site/sqlpage/migrations/40_fetch.sql @@ -10,9 +10,9 @@ VALUES ( 'transfer-vertical', 'Sends an HTTP request and returns the results as a string. -### Example +## HTTP request examples -#### Simple GET query +### Simple GET query In this example, we use an API call to find the latitude and longitude of a place the user searched for, and we display it on a map. @@ -30,7 +30,7 @@ select $user_search as title, CAST($api_results->>0->>''lon'' AS FLOAT) as longitude; ``` -#### POST query with a body +### POST query with a body In this example, we use the complex form of the function to make an authenticated POST request, with custom request headers and a custom request body. @@ -61,7 +61,7 @@ select ``` -#### Authenticated request using Basic Auth +### Authenticated request using Basic Auth Here''s how to make a request to an API that requires [HTTP Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication): @@ -77,7 +77,7 @@ set api_results = sqlpage.fetch($request); > This will add the `Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQK` header to the request, > where `bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQK` is the base64 encoding of the string `my_username:my_password`. -# JSON parameter format +## JSON parameter format The fetch function accepts either a URL string, or a JSON object with the following parameters: - `url`: The URL to fetch. Required. @@ -89,7 +89,7 @@ The fetch function accepts either a URL string, or a JSON object with the follow - `password`: Optional password for HTTP Basic Authentication. Only used if username is provided. Introduced in version 0.33.0. - `response_encoding`: Optional charset to use for decoding the response body. Defaults to `utf8`, or `base64` if the response contains binary data. All [standard web encodings](https://encoding.spec.whatwg.org/#concept-encoding-get) are supported, plus `hex`, `base64`, and `base64url`. Introduced in version 0.37.0. -# Error handling and reading response headers +## Error handling and reading response headers If the request fails, this function throws an error, that will be displayed to the user. The response headers are not available for inspection. diff --git a/examples/official-site/sqlpage/migrations/43_request_method.sql b/examples/official-site/sqlpage/migrations/43_request_method.sql index ec6323862..e5868b6d8 100644 --- a/examples/official-site/sqlpage/migrations/43_request_method.sql +++ b/examples/official-site/sqlpage/migrations/43_request_method.sql @@ -12,7 +12,7 @@ VALUES 'http-get', 'Returns the HTTP request method (GET, POST, etc.) used to access the page. -# HTTP request methods +## HTTP request methods HTTP request methods (also known as verbs) are used to indicate the desired action to be performed on the identified resource. The most common methods are: - **GET**: retrieve information from the server. This is the default method used by browsers when you click on a link. @@ -21,11 +21,11 @@ HTTP request methods (also known as verbs) are used to indicate the desired acti - **DELETE**: remove the target resource. - **PATCH**, **HEAD**, **OPTIONS**, **CONNECT**, **TRACE**: less common methods that are used in specific situations. -# Example +## Require a PUT request ```sql select ''redirect'' as component, - ''/error?msg=expected+a+PUT+request'' as link, + ''/error?msg=expected+a+PUT+request'' as link where sqlpage.request_method() != ''PUT''; insert into my_table (column1, column2) values (:value1, :value2); diff --git a/examples/official-site/sqlpage/migrations/45_blog_archeology.sql b/examples/official-site/sqlpage/migrations/45_blog_archeology.sql index 14211059f..413dbdac3 100644 --- a/examples/official-site/sqlpage/migrations/45_blog_archeology.sql +++ b/examples/official-site/sqlpage/migrations/45_blog_archeology.sql @@ -15,7 +15,7 @@ VALUES Archaeology has, since its beginnings, focused on cataloging, structuring and archiving data from excavations. In the field, it has long relied on creating forms, manually collecting information on paper, and hand drawing, transcribed during study phases onto digital media. It is only recently that some archaeologists have launched the movement of "all-digital" excavation. I propose to tell here the story of the digitization of archaeology, which, as you will see, relies in part on free software. -# What is an excavation site? +## Archaeological excavation in France French archaeology is divided into two main branches: preventive archaeology, which intervenes during construction projects, and programmed archaeology, conducted on sites chosen to address research issues. Supervised by the Regional Archaeological Services of the Ministry of Culture, these activities are carried out by different organizations: public and private operators for preventive archaeology, and associations, CNRS or universities for programmed archaeology. The latter often mobilizes volunteers, especially students, offering them complementary practical training. diff --git a/examples/official-site/sqlpage/migrations/46_html.sql b/examples/official-site/sqlpage/migrations/46_html.sql index 272882b93..58168c0d4 100644 --- a/examples/official-site/sqlpage/migrations/46_html.sql +++ b/examples/official-site/sqlpage/migrations/46_html.sql @@ -74,7 +74,7 @@ VALUES 'Include multiple html snippets as row-level parameters. Again, be careful what you include in the HTML content. If the data comes from a user, it can be manipulated to include malicious code.', JSON ( '[{"component":"html", "html":"
"}, - {"html":"
10%
"}, + {"html":"
20%
"}, {"html":"
80%
"}, {"html":"
"} ]' diff --git a/examples/official-site/sqlpage/migrations/54_blog_bompard.sql b/examples/official-site/sqlpage/migrations/54_blog_bompard.sql index 4fc445739..5fd16cd45 100644 --- a/examples/official-site/sqlpage/migrations/54_blog_bompard.sql +++ b/examples/official-site/sqlpage/migrations/54_blog_bompard.sql @@ -9,7 +9,7 @@ VALUES ' # How I Built And Deployed An Exhaustive Performance Monitoring Tool For a 100M€/year Company Using SQL Queries Only -### What is SQLPage ? +### Building web applications in SQL > [SQLPage](http://sql-page.com) allows anyone with SQL skills to build and deploy digital tools (websites, data applications, dashboards, user forms…) using only **SQL queries**. Official website: [https://sql-page.com/](https://sql-page.com/) @@ -19,7 +19,7 @@ The execution of the project is straightforward: simply run a single executable Finally, it’s open source with an MIT license. -### Why SQLPage became a game-changer for me, as a Head of Data +### Choosing SQLPage for my data team As a Head of Data at a mid-size company, I understand the challenge of juggling multiple tools — often expensive and proprietary — alongside a variety of dashboards. Building an **all-in-one**, **user-friendly**, **mobile-compatible** platform for data monitoring and visualization that serves everyone, from C-level executives to store managers, is no small feat. @@ -56,7 +56,7 @@ Here are some pages I built using only SQL queries, allowing everyone in the com *Examples of views built with SQLPage to provide a 360° tool for the company. -### How Does It Work ? +### Populating a chart from a query The process in SQLPage follows a simple pattern: @@ -101,7 +101,7 @@ That’s it! Each component comes with customizable parameters, allowing you to The ability to perform CRUD operations and interact directly with databases is a game changer compared to traditional BI tools. You can try it yourself by clicking “add” in the column “COMMENT THIS YEAR” [https://demo-test.datapage.app/lets_see_some_graphs.sql](https://demo-test.datapage.app/lets_see_some_graphs.sql) -### What About GenAI ? +### Generating SQL queries with AI I couldn’t write an article about data in 2024 without mentioning GenAI. The great news is that SQLPage, relying solely on SQL queries, is naturally GenAI-friendly. In fact, I rarely write SQL queries myself anymore — I let GenAI handle that. My workflow in SQLPage now becomes: @@ -113,11 +113,11 @@ I couldn’t write an article about data in 2024 without mentioning GenAI. The g *Example of Generated SQL to display a specific format of numbers.* -### How to Host Your SQLPage Application +### Hosting the application Once my app was ready, I could have chosen to host it myself on any server for a few euros a month, but I opted for SQLPage’s official hosting service, DataPage ([https://datapage.app/](https://beta.datapage.app/)), which is fully managed and very convenient. My app was hosted at _domainname.datapage.app._ The service includes a Postgres database, allowing you to either store your data on the server or connect directly to your existing database (Microsoft SQL Server, SQLite, Postgres, MySQL, etc). -### What Difficulties Can Be Encountered With SQLPage +### Maintaining complex SQL queries While SQLPage simplifies the process of building digital tools, it does come with some challenges. diff --git a/examples/official-site/sqlpage/migrations/55_request_body.sql b/examples/official-site/sqlpage/migrations/55_request_body.sql index d8dd1c94b..423ef6a27 100644 --- a/examples/official-site/sqlpage/migrations/55_request_body.sql +++ b/examples/official-site/sqlpage/migrations/55_request_body.sql @@ -88,11 +88,11 @@ VALUES ( 'photo-up', 'Returns the raw request body encoded in base64. This is useful when receiving binary data or when you need to handle non-text content in your API endpoints. -### What is Base64? +## Base64 encoding Base64 is a way to encode binary data (like images or files) into text that can be safely stored and transmitted. This function automatically converts the incoming request body into this format. -### Example: Handling Binary Data in an API +## Receiving binary data in an API This example shows how to receive and process an image uploaded directly in the request body: diff --git a/examples/official-site/sqlpage/migrations/61_oidc_functions.sql b/examples/official-site/sqlpage/migrations/61_oidc_functions.sql index 71d1d8490..197e68a9c 100644 --- a/examples/official-site/sqlpage/migrations/61_oidc_functions.sql +++ b/examples/official-site/sqlpage/migrations/61_oidc_functions.sql @@ -10,9 +10,7 @@ VALUES 'user_info_token', '0.35.0', 'key', - '# Accessing information about the current user, when logged in with SSO - -This function can be used only when you have [configured Single Sign-On with an OIDC provider](/sso). + 'This function can be used only when you have [configured Single Sign-On with an OIDC provider](/sso). ## The ID Token @@ -24,7 +22,7 @@ You can then use [your database''s JSON functions](/blog.sql?post=JSON+in+SQL%3A If you need to access a specific claim, it is easier and more performant to use the [`sqlpage.user_info()`](?function=user_info) function instead. -### Example: Displaying User Information +## Displaying user claims ```sql select ''list'' as component; @@ -38,7 +36,7 @@ This sqlite-specific example will show all the information available about the c - `email`: The user''s email address - `picture`: A URL to the user''s profile picture -### Security Notes +## Security notes - The ID token is automatically verified by SQLPage to ensure it hasn''t been tampered with. - The token is only available to authenticated users: if no user is logged in or sso is not configured, this function returns NULL @@ -59,15 +57,13 @@ VALUES 'user_info', '0.34.0', 'user', - '# Accessing Specific User Information - -The `sqlpage.user_info` function is a convenient way to access specific pieces of information about the currently logged-in user. + 'The `sqlpage.user_info` function is a convenient way to access specific pieces of information about the currently logged-in user. When you [configure Single Sign-On](/sso), your OIDC provider will issue an [ID token](https://openid.net/specs/openid-connect-core-1_0.html#IDToken) for the user, which contains *claims*, with information about the user. Calling `sqlpage.user_info(claim_name)` lets you access these claims directly from SQL. -## How to Use +## Read a claim The function takes one parameter: the name of the *claim* (the piece of information you want to retrieve). @@ -183,9 +179,7 @@ VALUES 'oidc_logout_url', '0.41.0', 'logout', - '# Secure OIDC Logout - -The `sqlpage.oidc_logout_url` function generates a secure logout URL for users authenticated via [OIDC Single Sign-On](/sso). + 'The `sqlpage.oidc_logout_url` function generates a secure logout URL for users authenticated via [OIDC Single Sign-On](/sso). When a user visits this URL, SQLPage will: 1. Remove the authentication cookie @@ -202,7 +196,7 @@ This function provides protection against **Cross-Site Request Forgery (CSRF)** This means that malicious websites cannot trick your users into logging out by simply including an image or link to your logout URL. -## How to Use +## Add a logout button ```sql select ''button'' as component; diff --git a/examples/official-site/sqlpage/migrations/64_blog_routing.sql b/examples/official-site/sqlpage/migrations/64_blog_routing.sql index ebdcdcea6..3467dc7fa 100644 --- a/examples/official-site/sqlpage/migrations/64_blog_routing.sql +++ b/examples/official-site/sqlpage/migrations/64_blog_routing.sql @@ -12,7 +12,7 @@ No complex configuration is needed. Just create files and they become accessible This guide explains how SQLPage resolves URLs, handles different file types, and manages 404 errors so you can structure your application effectively. -## How SQLPage Routes Requests +## Request routing order ### 1. Site Prefix Handling @@ -52,7 +52,7 @@ products/ └── categories.sql # Product categories (/products/categories) ``` -**How it works**: +**Request paths** - `/products/` → Executes `products/index.sql` (product listing) - `/products/123` → No `123.sql` file exists, so executes `products/404.sql` - `/products/laptop` → No `laptop.sql` file exists, so executes `products/404.sql` diff --git a/examples/official-site/sqlpage/migrations/65_download.sql b/examples/official-site/sqlpage/migrations/65_download.sql index 61c005a3f..a05b49ab8 100644 --- a/examples/official-site/sqlpage/migrations/65_download.sql +++ b/examples/official-site/sqlpage/migrations/65_download.sql @@ -11,14 +11,16 @@ Instead of showing a web page, it sends the file''s bytes as the whole response, so it should be used **at the very top of your SQL page** (before the shell or any other page contents). It is an error to use this component after another component that would display content. -How it works in simple terms: +## Sending a file + - You provide the file content using a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). A data URL is just a text string that contains both the file type and the actual data. - Optionally, you provide a "filename" so the browser shows a proper Save As name. If you do not provide a filename, many browsers will try to display the file inline (for example images or JSON), depending on the content type. -- You link to the page that uses the download component from another page, using the [button](/components?component=button) component for example. +- You link to the page that uses the download component from another page, using the [button](/component.sql?component=button) component for example. + +## Data URL format -What is a data URL? - It looks like this: `data:[content-type][;base64],DATA` - Examples: - Plain text (URL-encoded): `data:text/plain,Hello%20world` diff --git a/examples/official-site/sqlpage/migrations/66_log_component.sql b/examples/official-site/sqlpage/migrations/66_log_component.sql index 7109ad285..3a2cb083b 100644 --- a/examples/official-site/sqlpage/migrations/66_log_component.sql +++ b/examples/official-site/sqlpage/migrations/66_log_component.sql @@ -3,7 +3,7 @@ INSERT INTO component(name, icon, introduced_in_version, description) VALUES When a page runs, it prints your message to the terminal/console (standard error). Use it to track what happens and troubleshoot issues. -### Where do the messages appear? +## Reading log messages - Running from a terminal (Linux, macOS, or Windows PowerShell/Command Prompt): they show up in the window. - Docker: run `docker logs `. diff --git a/examples/official-site/sqlpage/migrations/67_hmac_function.sql b/examples/official-site/sqlpage/migrations/67_hmac_function.sql index e667f03f6..86ebda476 100644 --- a/examples/official-site/sqlpage/migrations/67_hmac_function.sql +++ b/examples/official-site/sqlpage/migrations/67_hmac_function.sql @@ -14,7 +14,7 @@ VALUES 'Creates a unique "signature" for some data using a secret key. This signature proves that the data hasn''t been tampered with and comes from someone who knows the secret. -### What is HMAC used for? +## HMAC use cases [**HMAC**](https://en.wikipedia.org/wiki/HMAC) (Hash-based Message Authentication Code) is commonly used to: - **Verify webhooks**: Use HMAC to ensure only a given external service can call a given endpoint in your application. @@ -24,7 +24,7 @@ Used for instance by [Stripe](https://docs.stripe.com/webhooks?verify=verify-man - **Generate secure tokens**: Create temporary access codes for downloads or password resets - **Protect data**: Ensure data hasn''t been modified during transmission -### How to use it +## Signing data The `sqlpage.hmac` function takes three inputs: 1. **Your data** - The text you want to sign (like a message or request body) diff --git a/examples/official-site/sqlpage/migrations/68_login.sql b/examples/official-site/sqlpage/migrations/68_login.sql index a545105dd..12a6d4867 100644 --- a/examples/official-site/sqlpage/migrations/68_login.sql +++ b/examples/official-site/sqlpage/migrations/68_login.sql @@ -24,6 +24,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S ('error_message_md','A markdown error message to display above the form, typically shown after a failed login attempt.','TEXT',TRUE,TRUE), ('username','Label and placeholder for the user account identifier text field.','TEXT',TRUE,FALSE), ('password','Label and placeholder for the password field.','TEXT',TRUE,FALSE), + ('autofocus','Focus the username field when the page opens. Defaults to true. Set to false when the form is one part of a larger page.','BOOLEAN',TRUE,TRUE), ('username_icon','Icon to display on the left side of the input field, on the same line.','ICON',TRUE,TRUE), ('password_icon','Icon to display on the left side of the input field, on the same line.','ICON',TRUE,TRUE), ('image','The URL of an centered image displayed before the title.','URL',TRUE,TRUE), @@ -60,6 +61,7 @@ There, you will have access to the variables: "title": "Please login to your account", "username": "Username", "password": "Password", + "autofocus": false, "username_icon": "user", "password_icon": "lock", "forgot_password_text": "Forgot your password?", @@ -71,4 +73,4 @@ There, you will have access to the variables: ]' ) ), - ('login', 'Most basic login form', JSON('[{"component": "login"}]')); + ('login', 'Basic login form', JSON('[{"component": "login", "username": "Username", "password": "Password", "autofocus": false}]')); diff --git a/examples/official-site/sqlpage/migrations/69_blog_performance_guide.sql b/examples/official-site/sqlpage/migrations/69_blog_performance_guide.sql index 6dcdf1119..c9f369d49 100644 --- a/examples/official-site/sqlpage/migrations/69_blog_performance_guide.sql +++ b/examples/official-site/sqlpage/migrations/69_blog_performance_guide.sql @@ -183,9 +183,9 @@ So, if you have to execute a slow query, put it as far down in the page as possi #### No heavy computation before the shell -Every user-facing page in a SQLPage site has a [shell](/components?component=shell). +Every user-facing page in a SQLPage site has a [shell](/component.sql?component=shell). -The first queries in any sql file (all the ones that come before the [shell](/components?component=shell)) +The first queries in any sql file (all the ones that come before the [shell](/component.sql?component=shell)) are executed before any data has been sent to the user''s browser. During that time, the user will see a blank screen. So, ensure your shell comes as early as possible, and does not require any heavy computation. diff --git a/examples/official-site/sqlpage/migrations/73_blog_tracing.sql b/examples/official-site/sqlpage/migrations/73_blog_tracing.sql index fda9d9e37..ef4b63d7f 100644 --- a/examples/official-site/sqlpage/migrations/73_blog_tracing.sql +++ b/examples/official-site/sqlpage/migrations/73_blog_tracing.sql @@ -19,7 +19,7 @@ SQLPage now supports [OpenTelemetry](https://opentelemetry.io/), the standard wa If you want a ready-to-run demo, see the [OpenTelemetry + Grafana example](https://github.com/sqlpage/SQLPage/tree/main/examples/telemetry), which this article is based on. -## What tracing gives you +## Tracing a request across services With tracing enabled, one HTTP request becomes a tree of timed operations called spans. In a typical SQLPage app, you will see something like: @@ -39,7 +39,7 @@ This is immediately useful for: Tracing is especially helpful in SQLPage because one request often maps cleanly to one SQL file. That makes traces easy to interpret even when you are not used to application performance tooling. -## The easiest way to try it +## Run the example stack The simplest way to explore tracing is to run [the example shipped with SQLPage](https://github.com/sqlpage/SQLPage/tree/main/examples/telemetry). @@ -86,7 +86,7 @@ The `OTEL_SERVICE_NAME` variable controls how the service appears in your tracin If `OTEL_EXPORTER_OTLP_ENDPOINT` is not set, SQLPage falls back to normal logging and tracing stays disabled. -## What you will see in the trace +## SQLPage spans The most useful spans emitted by SQLPage are: @@ -153,7 +153,7 @@ The example uses Grafana Tempo and Loki, but SQLPage is not tied to a single bac In small setups, SQLPage can often send traces directly to the backend. In larger deployments, placing an OpenTelemetry collector in the middle is usually better because it centralizes routing, batching, and authentication. -## When to enable tracing +## Production tracing use cases Tracing is particularly valuable when: diff --git a/examples/official-site/sqlpage/migrations/75_send_mail.sql b/examples/official-site/sqlpage/migrations/75_send_mail.sql index 76f5a27a0..01d6281c0 100644 --- a/examples/official-site/sqlpage/migrations/75_send_mail.sql +++ b/examples/official-site/sqlpage/migrations/75_send_mail.sql @@ -62,7 +62,7 @@ select ''alert'' as component, json_extract($result, ''$.error'') as description; ``` -### Where to find the SMTP settings +### SMTP provider settings Search the help pages or administration panel of the service that sends email for you. Look for **SMTP**, **outgoing mail server**, **SMTP submission**, **SMTP relay**, or **send from an app or device**. diff --git a/examples/official-site/sqlpage/migrations/81_guide_directory.sql b/examples/official-site/sqlpage/migrations/81_guide_directory.sql new file mode 100644 index 000000000..0a8687df1 --- /dev/null +++ b/examples/official-site/sqlpage/migrations/81_guide_directory.sql @@ -0,0 +1,15 @@ +CREATE TABLE guide ( + sort_order INTEGER PRIMARY KEY, + title TEXT NOT NULL, + link TEXT NOT NULL UNIQUE, + description TEXT NOT NULL +); + +INSERT INTO guide (sort_order, title, link, description) VALUES + (1, 'Your first website', '/your-first-sql-website/', 'Install SQLPage and build a website from a SQL file.'), + (2, 'SQL and variables', '/extensions-to-sql.sql', 'Read request parameters, set variables, and call SQLPage functions.'), + (3, 'Custom components', '/custom_components.sql', 'Render your own HTML with Handlebars templates.'), + (4, 'Database migrations', '/your-first-sql-website/migrations.sql', 'Create and update your database schema with versioned SQL files.'), + (5, 'Custom URLs', '/your-first-sql-website/custom_urls.sql', 'Give your pages readable URLs and route requests to SQL files.'), + (6, 'Reverse proxy', '/your-first-sql-website/nginx.sql', 'Serve your site with Nginx and HTTPS.'), + (7, 'Managed hosting', '/your-first-sql-website/hosted.sql', 'Try SQLPage online or publish your website with DataPage.'); diff --git a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql new file mode 100644 index 000000000..3f5be829d --- /dev/null +++ b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql @@ -0,0 +1,184 @@ +-- Short catalog descriptions help readers choose a page before opening its full reference. +CREATE TABLE reference_category ( + id TEXT PRIMARY KEY, + title TEXT NOT NULL, + sort_order INTEGER NOT NULL +); + +INSERT INTO reference_category (id, title, sort_order) VALUES + ('display-data', 'Display data', 1), + ('forms-and-feedback', 'Forms and feedback', 2), + ('navigation', 'Navigation', 3), + ('page-layout', 'Page layout and content', 4), + ('http-responses', 'HTTP responses', 5), + ('server-logic', 'Server logic', 6), + ('request-data', 'Request data', 1), + ('links-and-routing', 'Links and routing', 2), + ('files-and-uploads', 'Files and uploads', 3), + ('identity-and-security', 'Identity and security', 4), + ('external-services', 'External services', 5), + ('server-and-runtime', 'Server and runtime', 6); + +ALTER TABLE component ADD COLUMN catalog_category TEXT REFERENCES reference_category(id); +ALTER TABLE component ADD COLUMN catalog_summary TEXT; +ALTER TABLE sqlpage_functions ADD COLUMN catalog_category TEXT REFERENCES reference_category(id); +ALTER TABLE sqlpage_functions ADD COLUMN catalog_summary TEXT; +ALTER TABLE sqlpage_function_parameters ADD COLUMN optional BOOLEAN NOT NULL DEFAULT FALSE; + +UPDATE sqlpage_function_parameters SET optional = TRUE WHERE ("function", name) IN ( + ('exec', 'arguments...'), + ('hmac', 'algorithm'), + ('link', 'parameters'), ('link', 'fragment'), + ('oidc_logout_url', 'redirect_uri'), + ('persist_uploaded_file', 'destination_folder'), ('persist_uploaded_file', 'allowed_extensions'), ('persist_uploaded_file', 'mode'), + ('persist_uploaded_files', 'destination_folder'), ('persist_uploaded_files', 'allowed_extensions'), ('persist_uploaded_files', 'mode'), + ('run_sql', 'parameters'), + ('set_variable', 'value'), + ('variables', 'method') +); + +WITH copy(name, category, summary) AS (VALUES + ('big_number', 'display-data', 'Highlight a metric with a trend or progress indicator.'), + ('card', 'display-data', 'Arrange records in cards with images, links, or embedded content.'), + ('carousel', 'display-data', 'Show a slideshow of images with optional captions and controls.'), + ('chart', 'display-data', 'Plot query results as line, area, bar, or pie charts.'), + ('datagrid', 'display-data', 'Lay out labeled values in a compact grid.'), + ('list', 'display-data', 'Present rows as a vertical list with optional links and icons.'), + ('map', 'display-data', 'Plot locations and geographic shapes on an interactive map.'), + ('table', 'display-data', 'Turn query results into a sortable, searchable table.'), + ('timeline', 'display-data', 'Arrange events along a vertical timeline.'), + ('tracking', 'display-data', 'Show a sequence of activity or status changes as colored segments.'), + + ('alert', 'forms-and-feedback', 'Draw attention to a message with a color and an icon.'), + ('button', 'forms-and-feedback', 'Follow a link, download a file, or submit a form.'), + ('empty_state', 'forms-and-feedback', 'Explain an empty view and offer the reader a next step.'), + ('form', 'forms-and-feedback', 'Collect input with text fields, file uploads, and other controls.'), + ('login', 'forms-and-feedback', 'Display a sign-in form for a username and password.'), + ('modal', 'forms-and-feedback', 'Open a dialog over the page for details, forms, or media.'), + ('toast', 'forms-and-feedback', 'Show a brief notification above the page.'), + + ('breadcrumb', 'navigation', 'Link the current page to its parent pages.'), + ('facet', 'navigation', 'Let readers choose filters for a dataset.'), + ('pagination', 'navigation', 'Link to other pages of a query result.'), + ('status_bar', 'navigation', 'Show status messages and links in a horizontal bar.'), + ('steps', 'navigation', 'Mark progress through the stages of a task.'), + ('tab', 'navigation', 'Switch between related pages using labeled tabs.'), + + ('code', 'page-layout', 'Display source code with syntax highlighting.'), + ('columns', 'page-layout', 'Compare plans, features, or options in side-by-side cards.'), + ('divider', 'page-layout', 'Separate sections with a horizontal rule.'), + ('foldable', 'page-layout', 'Let readers expand individual sections to see their contents.'), + ('hero', 'page-layout', 'Introduce a page with a headline, media, and a call to action.'), + ('html', 'page-layout', 'Insert your own HTML markup into the page.'), + ('shell', 'page-layout', 'Set the page layout, navigation, branding, and footer.'), + ('text', 'page-layout', 'Write paragraphs using plain text or Markdown.'), + ('title', 'page-layout', 'Add a heading and choose its level.'), + + ('cookie', 'http-responses', 'Set a cookie in the visitor''s browser.'), + ('csv', 'http-responses', 'Export query rows as a downloadable CSV file.'), + ('download', 'http-responses', 'Send a file directly to the visitor.'), + ('http_header', 'http-responses', 'Set response headers for caching, content types, and more.'), + ('json', 'http-responses', 'Return query results as JSON for an API.'), + ('redirect', 'http-responses', 'Send the visitor to another URL.'), + ('rss', 'http-responses', 'Publish an RSS feed from query results.'), + ('status_code', 'http-responses', 'Set the HTTP status code returned by a page.'), + + ('authentication', 'server-logic', 'Restrict access by checking a password against a stored hash.'), + ('debug', 'server-logic', 'Inspect the values passed to a component as JSON.'), + ('dynamic', 'server-logic', 'Render SQLPage components described by JSON data.'), + ('log', 'server-logic', 'Write a message to the SQLPage server log.') +) +UPDATE component SET (catalog_category, catalog_summary) = (copy.category, copy.summary) +FROM copy WHERE component.name = copy.name; + +WITH copy(name, category, summary) AS (VALUES + ('client_ip', 'request-data', 'Get the IP address of the client making the request.'), + ('cookie', 'request-data', 'Read a named cookie from the incoming request.'), + ('header', 'request-data', 'Read the value of one HTTP request header.'), + ('headers', 'request-data', 'Read all HTTP request headers as a JSON object.'), + ('path', 'request-data', 'Get the URL path of the current request.'), + ('protocol', 'request-data', 'Identify whether the request used HTTP or HTTPS.'), + ('request_body', 'request-data', 'Read the raw request body as text.'), + ('request_body_base64', 'request-data', 'Read a binary request body as a Base64 string.'), + ('request_method', 'request-data', 'Get the HTTP method, such as GET or POST.'), + ('variables', 'request-data', 'Read request or page variables as a JSON object.'), + + ('link', 'links-and-routing', 'Build a page URL with optional query parameters and a fragment.'), + ('regex_match', 'links-and-routing', 'Match text against a regular expression and extract capture groups.'), + ('set_variable', 'links-and-routing', 'Build a link to this page with a query parameter changed or removed.'), + ('url_encode', 'links-and-routing', 'Encode text for use in a URL.'), + + ('persist_uploaded_file', 'files-and-uploads', 'Save an uploaded file and return its path.'), + ('persist_uploaded_files', 'files-and-uploads', 'Save multiple uploads from one field and return their file details.'), + ('read_file_as_data_url', 'files-and-uploads', 'Read a file as a data URL for embedding in a page.'), + ('read_file_as_text', 'files-and-uploads', 'Read the text of a UTF-8 file from the web root.'), + ('uploaded_file_mime_type', 'files-and-uploads', 'Read the media type supplied by the browser for an uploaded file.'), + ('uploaded_file_name', 'files-and-uploads', 'Read the original filename supplied by the browser.'), + ('uploaded_file_path', 'files-and-uploads', 'Get the temporary path of an uploaded file.'), + + ('basic_auth_password', 'identity-and-security', 'Read the password sent with HTTP Basic authentication.'), + ('basic_auth_username', 'identity-and-security', 'Read the username sent with HTTP Basic authentication.'), + ('hash_password', 'identity-and-security', 'Hash a password with Argon2id for storage.'), + ('hmac', 'identity-and-security', 'Sign data with a shared secret using HMAC.'), + ('oidc_logout_url', 'identity-and-security', 'Build a sign-out URL for an OpenID Connect session.'), + ('random_string', 'identity-and-security', 'Generate a cryptographically secure random string.'), + ('user_info', 'identity-and-security', 'Read a named claim for the signed-in user.'), + ('user_info_token', 'identity-and-security', 'Read all claims from the user''s OpenID Connect ID token.'), + + ('fetch', 'external-services', 'Send an HTTP request and read the response body.'), + ('fetch_with_meta', 'external-services', 'Send an HTTP request and read its status, headers, and body.'), + ('send_mail', 'external-services', 'Send email with optional attachments through an SMTP server.'), + + ('configuration_directory', 'server-and-runtime', 'Locate the directory for SQLPage configuration and templates.'), + ('current_working_directory', 'server-and-runtime', 'Get the working directory of the SQLPage server process.'), + ('environment_variable', 'server-and-runtime', 'Read a named environment variable from the server.'), + ('exec', 'server-and-runtime', 'Run a program on the server and capture its output.'), + ('run_sql', 'server-and-runtime', 'Run another SQLPage file and return its rows as JSON.'), + ('version', 'server-and-runtime', 'Read the version of SQLPage serving the page.'), + ('web_root', 'server-and-runtime', 'Locate the directory that holds the site''s public files.') +) +UPDATE sqlpage_functions SET (catalog_category, catalog_summary) = (copy.category, copy.summary) +FROM copy WHERE sqlpage_functions.name = copy.name; + +-- The catalog, topic navigation, and reference pages use the same entries and links. +CREATE VIEW reference_entry AS +WITH entries AS ( + SELECT 'component' AS kind, name, icon, catalog_category, catalog_summary, + description AS description_md, introduced_in_version, NULL AS return_type, + '/component.sql?component=' || name AS link, + (SELECT count(*) FROM example WHERE example.component = component.name) AS example_count, + NULL AS arguments + FROM component + UNION ALL + SELECT 'function', name, icon, catalog_category, catalog_summary, + description_md, introduced_in_version, return_type, '/functions.sql?function=' || name, NULL, + coalesce((SELECT group_concat(CASE WHEN optional THEN '[' || name || ']' ELSE name END, ', ' ORDER BY "index") + FROM sqlpage_function_parameters WHERE "function" = f.name), '') + FROM sqlpage_functions AS f +) +SELECT kind, name, icon, link, description_md, introduced_in_version, return_type, example_count, arguments, + coalesce(category.id, 'other') AS category_id, + coalesce(category.title, 'Other') AS category_title, + coalesce(category.sort_order, 99) AS category_order, + coalesce(catalog_summary, substr(trim(description_md, char(10) || ' #'), 1, + instr(trim(description_md, char(10) || ' #') || char(10), char(10)) - 1)) AS summary +FROM entries +LEFT JOIN reference_category AS category ON category.id = entries.catalog_category; + +-- The section is part of the anchor: a component can accept the same name at both levels. +CREATE VIEW reference_parameter AS +WITH fields AS ( + SELECT 'component' AS kind, component AS entry, + CASE WHEN top_level THEN 'top-level-parameters' ELSE 'row-level-parameters' END AS section, + name, type, optional, coalesce(description_md, description) AS description_md, optional AS position + FROM parameter + UNION ALL + SELECT 'function', "function", 'parameters', name, type, optional, description_md, "index" + FROM sqlpage_function_parameters +), sections(section, title, introduction, section_order) AS (VALUES + ('top-level-parameters', 'Top-level parameters', 'Set these in the SELECT that names the component.', 1), + ('row-level-parameters', 'Row-level parameters', 'Return these columns in the rows that follow the component.', 2), + ('parameters', 'Parameters', NULL, 1) +) +SELECT fields.*, title, introduction, section_order, section || '-' || name AS anchor +FROM fields JOIN sections USING (section); diff --git a/examples/official-site/sqlpage/migrations/999_fts_search_index.sql b/examples/official-site/sqlpage/migrations/999_fts_search_index.sql index 225ff4299..ee0ba09e8 100644 --- a/examples/official-site/sqlpage/migrations/999_fts_search_index.sql +++ b/examples/official-site/sqlpage/migrations/999_fts_search_index.sql @@ -1,32 +1,25 @@ CREATE VIRTUAL TABLE documentation_fts USING fts5( - component_name, - component_description, - parameter_name, - parameter_description, - blog_title, - blog_description, - function_name, - function_description, - function_parameter_name, - function_parameter_description, - component_example_description, - component_example_json + title, description, example_source, + page UNINDEXED, parameters UNINDEXED, fragment UNINDEXED ); -INSERT INTO documentation_fts(component_name, component_description) -SELECT name, description FROM component; +INSERT INTO documentation_fts(title, description, page) +SELECT title, description, link FROM guide +UNION ALL +SELECT CASE kind WHEN 'component' THEN name || ' component' ELSE 'sqlpage.' || name || '()' END, + description_md, link FROM reference_entry; -INSERT INTO documentation_fts(component_name, parameter_name, parameter_description) -SELECT component, name, description FROM parameter; +INSERT INTO documentation_fts(title, description, page, fragment) +SELECT CASE p.kind WHEN 'component' THEN p.entry || ' component: ' || p.name + ELSE 'sqlpage.' || p.entry || '(' || p.name || ')' END, + p.description_md, e.link, p.anchor +FROM reference_parameter AS p +JOIN reference_entry AS e ON e.kind = p.kind AND e.name = p.entry; -INSERT INTO documentation_fts(blog_title, blog_description) -SELECT title, description FROM blog_posts; +INSERT INTO documentation_fts(title, description, example_source, page, fragment) +SELECT component || ' component example', description, properties, e.link, 'example-' || example_number +FROM example_with_source AS x +JOIN reference_entry AS e ON e.kind = 'component' AND e.name = x.component; -INSERT INTO documentation_fts(function_name, function_description) -SELECT name, description_md FROM sqlpage_functions; - -INSERT INTO documentation_fts(function_name, function_parameter_name, function_parameter_description) -SELECT function, name, description_md FROM sqlpage_function_parameters; - -INSERT INTO documentation_fts(component_name, component_example_description, component_example_json) -SELECT component, description, properties FROM example; \ No newline at end of file +INSERT INTO documentation_fts(title, description, page, parameters) +SELECT title, description, '/blog.sql', json_object('post', title) FROM blog_posts; diff --git a/examples/official-site/sqlpage/templates/docs-catalog.handlebars b/examples/official-site/sqlpage/templates/docs-catalog.handlebars new file mode 100644 index 000000000..7ba25fd53 --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-catalog.handlebars @@ -0,0 +1,128 @@ +
+
+ {{icon_img "arrow-left" 16}} Documentation + {{#if (eq kind "component")}} +

Components

+

Choose what your SQL renders. Explore the parameters and live examples for each component.

+ {{else}} +

Functions

+

Call sqlpage.* to read requests, work with files, and reach external services. Brackets mark optional arguments.

+ {{/if}} +
+ {{#if picks}} + + {{/if}} + {{#if (eq kind "function")}} +
+
+ {{icon_img "code" 16}} SQL + View function {{icon_img "arrow-right" 14}} +
+ select sqlpage.url_encode('hello world'); +
Result {{encoded_example}}
+
+ {{/if}} +
+ +
+ +
+
+ + {{matched}} {{#if (eq matched 1)}}{{kind}}{{else}}{{plural}}{{/if}} + {{#if (and matched (or query category))}}Clear filters{{/if}} +
+ {{#unless matched}} +
+ {{icon_img "search-off" 28}} +

No matching {{plural}}

+ {{#if (and category all_count)}} +

See matches in other categories or try another name.

+ {{else}} +

Try another name or a broader search.

+ {{/if}} + Clear filters {{icon_img "arrow-right" 16}} +
+ {{/unless}} + {{#each_row}} +
+

{{title}}

+ +
+ {{/each_row}} +
+
diff --git a/examples/official-site/sqlpage/templates/docs-example.handlebars b/examples/official-site/sqlpage/templates/docs-example.handlebars new file mode 100644 index 000000000..ae9a9439e --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-example.handlebars @@ -0,0 +1,28 @@ +{{!-- For a live preview, send end_result after the last native component. --}} +{{#if end_result}} + + + + +{{else}} +
+

{{#if title}}{{title}}{{else}}Example {{number}}{{/if}}

+ {{#if description_md}}
{{{markdown description_md}}}
{{/if}} + {{#if preview}}
{{/if}} + {{#if source}} +
+
+ {{icon_img "file-code" 18}} index.sql + +
+
{{source}}
+
+ {{/if}} + {{#if preview}} +
+

{{icon_img "player-play" 16}} Result

+
+ {{else}} +
+ {{/if}} +{{/if}} diff --git a/examples/official-site/sqlpage/templates/docs-intro.handlebars b/examples/official-site/sqlpage/templates/docs-intro.handlebars new file mode 100644 index 000000000..474ea842e --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-intro.handlebars @@ -0,0 +1,10 @@ +
+
+ {{#if version}}SQLPage v{{version}}{{/if}} +

{{title}}

+

{{description}}

+ {{#if link}}{{link_text}}{{/if}} +
+ {{#if image}}{{/if}} +
+{{#each_row}}{{/each_row}} diff --git a/examples/official-site/sqlpage/templates/docs-links.handlebars b/examples/official-site/sqlpage/templates/docs-links.handlebars new file mode 100644 index 000000000..5df261238 --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-links.handlebars @@ -0,0 +1,18 @@ + diff --git a/examples/official-site/sqlpage/templates/docs-parameters.handlebars b/examples/official-site/sqlpage/templates/docs-parameters.handlebars new file mode 100644 index 000000000..f704d0ecb --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-parameters.handlebars @@ -0,0 +1,21 @@ +{{#each_row}} +
+

{{title}}

+ {{#if introduction}}

{{introduction}}

{{/if}} +
+ {{#each (to_array parameters)}} +
+
{{name}} + + {{#if (eq type "COLOR")}}{{type}} + {{else if (eq type "ICON")}}{{type}} + {{else}}{{type}}{{/if}} + {{#if required}}Required{{/if}} + +
+
{{{markdown description_md}}}
+
+ {{/each}} +
+
+{{/each_row}} diff --git a/examples/official-site/sqlpage/templates/docs-reference-heading.handlebars b/examples/official-site/sqlpage/templates/docs-reference-heading.handlebars new file mode 100644 index 000000000..32f39b1db --- /dev/null +++ b/examples/official-site/sqlpage/templates/docs-reference-heading.handlebars @@ -0,0 +1,8 @@ +
+ {{icon_img icon 18}} {{section}} +

{{title}}

+ {{#if description}}

{{description}}

{{/if}} + {{#if version}}Since SQLPage {{version}}{{/if}} + {{#if return_type}}Returns {{return_type}}{{/if}} + {{#if jump_link}}{{jump_text}}{{/if}} +
diff --git a/examples/official-site/sqlpage/templates/landing-page.handlebars b/examples/official-site/sqlpage/templates/landing-page.handlebars index 03a740aa7..0808cb7dc 100644 --- a/examples/official-site/sqlpage/templates/landing-page.handlebars +++ b/examples/official-site/sqlpage/templates/landing-page.handlebars @@ -85,6 +85,7 @@ SQLPage -
{{demo_source}}
+
+
{{demo_source}}

Explore the table component {{icon_img "arrow-up-right"}} @@ -240,7 +234,7 @@
-

-- What do you have to maintain?

+

-- Application layers to maintain

@@ -349,9 +343,9 @@
{{> landing-wave}}
-

-- one refunds tool, six ways to build it, on day 100

+

-- maintenance after 100 days

-

Low Effort.
Low Drama.

+

Refund app,
six ways.

Building got cheap.
Owning what got built is still expensive.

@@ -401,7 +395,7 @@
{{/comparison-card}} - {{#> comparison-card id="compare-spreadsheet" title="Spreadsheet" caption="Excel, Google Sheets" verdict="Great until the data drifts." aside="-- which one is real?" glyph="table"}} + {{#> comparison-card id="compare-spreadsheet" title="Spreadsheet" caption="Excel, Google Sheets" verdict="Great until the data drifts." aside="-- conflicting copies" glyph="table"}} @@ -525,9 +519,11 @@
SQLPage diff --git a/examples/official-site/sqlpage/templates/shell-docs.handlebars b/examples/official-site/sqlpage/templates/shell-docs.handlebars new file mode 100644 index 000000000..a7988882a --- /dev/null +++ b/examples/official-site/sqlpage/templates/shell-docs.handlebars @@ -0,0 +1,117 @@ + + + + + + {{default title "SQLPage documentation"}} + + + + + + + + + + + {{#if catalog}} + + + {{#if (eq section "Components")}}{{/if}} + {{else if (or (eq section "Components") (eq section "Functions"))}} + + {{else if (any (eq section "Guides") (eq section "Documentation") (eq section "Examples"))}} + + {{/if}} + + + + {{#if (or (eq section "Documentation") (and (eq section "Components") current_item))}} + + {{/if}} + + + + Skip to content +
+
+ + +
+ + {{icon_img "brand-github" 20}} +
+
+
+ +
+ {{#if topics}} +
+ + {{topic_label}} {{icon_img "chevron-down" 14}} + + +
+ {{/if}} + {{#if outline}} +
+ On this page {{icon_img "chevron-down" 14}} + +
+ {{/if}} +
+ {{~#each_row~}}{{~/each_row~}} +
+
+ + + + + diff --git a/examples/official-site/sso/index.sql b/examples/official-site/sso/index.sql index c352d9e66..a03574c9d 100644 --- a/examples/official-site/sso/index.sql +++ b/examples/official-site/sso/index.sql @@ -2,6 +2,6 @@ select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", '; rel="canonical"' as "Link"; -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Single sign-on - SQLPage' as title; select 'text' as component, sqlpage.read_file_as_text('sso/single_sign_on.md') as contents_md, true as article; \ No newline at end of file diff --git a/examples/official-site/test.hurl b/examples/official-site/test.hurl index b8bd42ec5..6a82b994d 100644 --- a/examples/official-site/test.hurl +++ b/examples/official-site/test.hurl @@ -15,8 +15,14 @@ GET http://localhost:8080/documentation.sql HTTP 200 [Asserts] body contains "SQLPage v" -body contains "components" -body contains "shell" +xpath "string(//main//a[normalize-space()='Components']/@href)" == "/components.sql" +xpath "string(//main//a[normalize-space()='Functions']/@href)" == "/functions.sql" +body not contains "An error occurred" + +GET http://localhost:8080/components.sql +HTTP 200 +[Asserts] +xpath "string(//main//a[.//h3/span='shell']/@href)" == "/component.sql?component=shell" body not contains "An error occurred" GET http://localhost:8080/component.sql?component=form @@ -26,6 +32,11 @@ body contains "The form component" body contains "Building forms in SQL" body not contains "An error occurred" +GET http://localhost:8080/functions.sql?q=variables +HTTP 200 +[Asserts] +xpath "normalize-space(//main//a[@href='/functions.sql?function=variables']/h3)" == "variables([method])" + GET http://localhost:8080/functions.sql?function=url_encode HTTP 200 [Asserts] @@ -33,11 +44,61 @@ body contains "sqlpage.url_encode" body contains "Parameters" body not contains "An error occurred" +GET http://localhost:8080/llms.txt +HTTP 200 +[Asserts] +header "Content-Type" == "text/markdown; charset=utf-8" +body contains "### [sqlpage.send_mail()](/functions.sql?function=send_mail)" +body contains "- `message` (JSON) **REQUIRED**: A JSON object containing the email to send." +body contains "> ## Building forms in SQL" +body contains "> ##### `reusable.sql`" +body contains "> ```sql\n> " + GET http://localhost:8080/search.sql?search=form HTTP 302 [Asserts] header "Location" == "/component.sql?component=form" +GET http://localhost:8080/search.sql?search=SQLPage.cookie() +HTTP 302 +[Asserts] +header "Location" == "/functions.sql?function=cookie" + +GET http://localhost:8080/search.sql?search=empty_description +HTTP 200 +[Asserts] +xpath "//main//a[@href='/component.sql?component=list#top-level-parameters-empty_description']" count == 1 + +GET http://localhost:8080/component.sql?component=list +HTTP 200 +[Asserts] +xpath "//*[@id='top-level-parameters-empty_description']//dt//a[@href='#top-level-parameters-empty_description']" count == 1 +xpath "//*[@id='row-level-parameters-title']" count == 1 +xpath "//*[@id='top-level-parameters-title']" count == 1 + +GET http://localhost:8080/search.sql?search=migrations +HTTP 200 +[Asserts] +xpath "//main//a[@href='/your-first-sql-website/migrations.sql']" count == 1 +body not contains "An error occurred" + +GET http://localhost:8080/your-first-sql-website/ +HTTP 200 +[Asserts] +xpath "//main//h1" count == 1 +xpath "//*[@id='connect-to-a-custom-database']" count == 1 + +GET http://localhost:8080/examples/tabs/?db=postgres +HTTP 302 +[Asserts] +header "Location" == "/examples/?db=postgres#projects" + +GET http://localhost:8080/examples/?db=postgres +HTTP 200 +[Asserts] +body contains "Developer UI" +body not contains "Roundest Pokemon" + GET http://localhost:8080/not-a-real-doc-page HTTP 404 [Asserts] diff --git a/examples/official-site/visual-identity.sql b/examples/official-site/visual-identity.sql index 7010d8e15..997ee47e0 100644 --- a/examples/official-site/visual-identity.sql +++ b/examples/official-site/visual-identity.sql @@ -1,10 +1,6 @@ select 'http_header' as component, 'public, max-age=600, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'Visual Identity - SQLPage', - 'css', '/assets/highlightjs-and-tabler-theme.css', - 'theme', 'dark' -)) as properties FROM example WHERE component = 'shell' LIMIT 1; +select 'shell-docs' as component, 'Visual Identity - SQLPage' as title; select 'text' as component, 'SQLPage visual identity' as title, ' SQLPage turns data into useful applications. Its identity pairs the round geometry of **Outfit** with the landing sculpture: three stacked metal sections, two luminous bands, and a detached jewel. diff --git a/examples/official-site/your-first-sql-website/custom_urls.sql b/examples/official-site/your-first-sql-website/custom_urls.sql index 53e2dab7f..8b8413d32 100644 --- a/examples/official-site/your-first-sql-website/custom_urls.sql +++ b/examples/official-site/your-first-sql-website/custom_urls.sql @@ -1,7 +1,10 @@ select 'http_header' as component, 'public, max-age=300, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control"; -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Custom URLs | SQLPage', + 'section', 'Guides', 'current', 'Custom URLs' +)) as properties; select 'hero' as component, 'Custom URLs' as title, @@ -9,8 +12,6 @@ select 'hero' as component, 'not_found.jpg' as image; select 'text' as component, ' -# Handling custom URLs - By default, SQLPage serves the file that matches the URL requested by the client. If your users enter `https://example.com/about`, SQLPage will serve the file `about/index.sql` in your project. If you create a file named `about.sql`, SQLPage will serve it when the user requests either `https://example.com/about.sql` or `https://example.com/about` (since v0.33, the `.sql` suffix is optional). @@ -53,4 +54,4 @@ where name = $name; ``` Now, when a user requests `example.com/blog/my-trip-to-rome`, SQLPage will serve the content of the blog post with name `my-trip-to-rome` from the `blog_posts` table. -' as contents_md; \ No newline at end of file +' as contents_md; diff --git a/examples/official-site/your-first-sql-website/hosted.sql b/examples/official-site/your-first-sql-website/hosted.sql index b16830a1d..623460ae4 100644 --- a/examples/official-site/your-first-sql-website/hosted.sql +++ b/examples/official-site/your-first-sql-website/hosted.sql @@ -1,28 +1,22 @@ -select 'shell' as component, - 'SQLPage: get started!' as title, - 'database' as icon, - '/' as link, - 'en-US' as lang, - 'Hosted SQLPage: set-up a SQLPage website in three clicks.' as description, - 'documentation' as menu_item, - '/assets/brand/brand.css' as css; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Hosted SQLPage', + 'description', 'Set up a SQLPage website online with managed hosting.', + 'section', 'Guides', 'current', 'Managed hosting' +)) as properties; -SELECT 'hero' as component, +select 'docs-intro' as component, 'Hosted SQLPage' as title, - 'Work In Progress: We are working on a cloud version of SQLPage - that will enable you to effortlessly set up your website online without the need to download any software or configure your own server.' as description, - 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/94/Baustelle_H%C3%B6lzla_6066312.jpg/1024px-Baustelle_H%C3%B6lzla_6066312.jpg' as image, - 'https://forms.gle/z1qmuCwdNT5Am7gp6' as link, - 'Get notified when we are ready' as link_text; + 'Publish a SQLPage website with DataPage without installing software or configuring a server.' as description, + '/assets/landing/assets/scene-first-frame.webp' as image, + 'https://datapage.app' as link, + 'Host your website' as link_text; SELECT 'text' as component, - 'Try SQLPage online today' as title, - ' -If you want to fiddle around with SQLPage without installing anything on your computer, you can still try it out online today. + '## Run SQLPage in your browser -Repl.it is an online development environment that allows you to run SQLPage in your browser. +Replit is an online development environment that lets you run SQLPage without a local installation. Try [the SQLPage repl](https://replit.com/@pimaj62145/SQLPage). Click *Use template* to create your own editable copy of the demo website, then click *Run* to see the result. On the left side you can edit the SQLPage code, on the right side you can see the result. -' as contents_md; \ No newline at end of file +' as contents_md; diff --git a/examples/official-site/your-first-sql-website/index.sql b/examples/official-site/your-first-sql-website/index.sql index 85c68cca8..f44d78ea4 100644 --- a/examples/official-site/your-first-sql-website/index.sql +++ b/examples/official-site/your-first-sql-website/index.sql @@ -11,12 +11,21 @@ set os = COALESCE($os, case else 'any' end); --- Fetch the page title and header from the database -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'SQL to Website - Tutorial', - 'description', 'Convert your SQL database into a website in minutes. In this 5-minute guide, we will create a simple website from scratch, and learn the basics of SQLPage.' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Your first SQL website | SQLPage', + 'description', 'Create a SQLPage website from scratch, connect a database and build an interactive form.', + 'section', 'Guides', 'current', 'Your first website', + 'outline', '[ + {"title":"Overview","link":"#overview"}, + {"title":"Install SQLPage","link":"#download"}, + {"title":"Build the website","link":"#tutorial"}, + {"title":"Connect a database","link":"#connect-to-a-custom-database"}, + {"title":"Handle form input","link":"#forms"}, + {"title":"Deploy your website","link":"#deploy"}, + {"title":"Related reference","link":"#reference"}, + {"title":"Online and video options","link":"#alternatives"} + ]' +)) as properties; SET req = '{ "url": "https://api.github.com/repos/sqlpage/SQLPage/releases/latest", @@ -25,11 +34,10 @@ SET req = '{ SET api_results = sqlpage.fetch_with_meta($req); SET sqlpage_version = COALESCE(json_extract($api_results, '$.json_body.tag_name'), ''); -SELECT 'hero' as component, +SELECT 'docs-intro' as component, + true as photograph, 'Your first SQL Website' as title, - '[SQLPage](/) is a free tool for building data-driven apps quickly. - -Let''s create a simple website with a database from scratch, to learn SQLPage basics.' as description_md, + 'Create a website from scratch. Connect a database, display its rows, and let visitors add a record through a form.' as description, case $os when 'linux' then 'get_started_linux.webp' when 'macos' then 'get_started_macos.webp' @@ -49,24 +57,7 @@ Let''s create a simple website with a database from scratch, to learn SQLPage ba ELSE CONCAT('Download SQLPage ', $sqlpage_version) END AS link_text; -SELECT 'alert' as component, - 'Afraid of the setup ? Do it the easy way !' as title, - 'mood-happy' as icon, - 'teal' as color, - 'You don’t want to install anything on your computer ? - You can use a preconfigured SQLPage hosted on our servers, and get your app online in minutes, without **ever having to configure a server** yourself.' as description_md, - 'https://datapage.app' AS link, - 'Host your app on our servers' as link_text; -select 'https://editor.datapage.app' as link, 'Try SQLPage from your browser' as title, 'teal' as color; - -SELECT 'alert' as component, - 'Do you prefer videos ?' as title, - 'brand-youtube' as icon, - 'purple' as color, - 'We made videos to introduce you to SQLPage. You can watch them on YouTube. The videos cover everything from the underlying technology to the philosophy behind SQLPage to the actual steps to create your first website.' as description_md, - 'https://www.youtube.com/watch?v=9NJgH_-zXjY' AS link, - 'Watch the introduction video' as link_text; -select 'https://www.youtube.com/watch?v=6D5D10v18b0&list=PLTue_qIAHxActQnLn_tHWZUNXziZTeraB' as link, 'Tutorial video series' as title; +select 'text' as component, 'You can also [try SQLPage in your browser](https://editor.datapage.app) or [watch the video tutorial](#alternatives).' as contents_md; select 'text' as component, sqlpage.read_file_as_text( @@ -81,7 +72,19 @@ select 'text' as component, true as article, 'download' as id; +-- This checked-in article has HTML heading IDs for direct links from the landing page. select 'text' as component, - sqlpage.read_file_as_text('your-first-sql-website/tutorial.md') as contents_md, - true as article, - 'tutorial' as id; + sqlpage.read_file_as_text('your-first-sql-website/tutorial.md') as unsafe_contents_md, + true as article, + 'tutorial' as id; + +select 'docs-links' as component, 'Component and function reference' as title, 'reference' as id; +select 'Form and field options' as title, 'forms' as icon, '/component.sql?component=form' as link, + 'Add input types, validation and submit buttons to the form you built.' as description; +select 'Read request variables' as title, 'variable' as icon, '/functions.sql?function=variables' as link, + 'Read the URL and form values sent to a page with sqlpage.variables().' as description; + +select 'title' as component, 'Online and video options' as contents, 2 as level, 'alternatives' as id; +select 'text' as component, ' +- [Try SQLPage in your browser](https://editor.datapage.app) or [host your app with DataPage](https://datapage.app). +- [Watch the introduction](https://www.youtube.com/watch?v=9NJgH_-zXjY) or [follow the tutorial video series](https://www.youtube.com/watch?v=6D5D10v18b0&list=PLTue_qIAHxActQnLn_tHWZUNXziZTeraB).' as contents_md; diff --git a/examples/official-site/your-first-sql-website/migrations.md b/examples/official-site/your-first-sql-website/migrations.md index 7d1822c19..4ddc79b13 100644 --- a/examples/official-site/your-first-sql-website/migrations.md +++ b/examples/official-site/your-first-sql-website/migrations.md @@ -2,17 +2,17 @@ Maintaining a structured and evolving database is crucial for web app development. Rarely do we get a schema 100% correct on day one. New insights about the shape of the application are discovered over time, or business needs themselves evolve. In the world of databases, we can evolve schemas using migration files. These files are just more SQL that append or amend layers of development. Think of this process like sedimentary rock layers. Each migration adds a layer, and together, these layers create a complete, functional structure along with a visible trail of historical changes. -## What Makes up a SQL Migration File? +## Migration files SQL migrations are incremental changes to a database. These changes can include creating tables, adding columns, modifying data types, or even inserting or updating records. Each migration is a distinct script that applies a specific change. -### Use Caution! +### Back up your database Since migration files change the database, they can have unintended consequences if not thought through carefully. For instance, you may accidentally delete a column that is still being used by your application or remove records that are still needed. > ⚠️ Be thoughtful, double-check your work, and **always back up your data before running a migration**. -### Order Matters +### Migration order **It's important that migrations are distinct ordered files** as SQLPage uses the sequence of migration files to build the database over time: `0001_initial_setup.sql`, `0002_my_first_change.sql`, `0003_my_next_change`, etc. diff --git a/examples/official-site/your-first-sql-website/migrations.sql b/examples/official-site/your-first-sql-website/migrations.sql index 61f0761ca..3800c5c44 100644 --- a/examples/official-site/your-first-sql-website/migrations.sql +++ b/examples/official-site/your-first-sql-website/migrations.sql @@ -2,11 +2,11 @@ select 'http_header' as component, 'public, max-age=300, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control", '; rel="canonical"' as "Link"; -select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object( - 'title', 'SQLPage migrations', - 'description', 'Manage your database schema with SQLPage using migrations.' -)) as properties -FROM example WHERE component = 'shell' LIMIT 1; +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Database migrations | SQLPage', + 'description', 'Manage your database schema with SQLPage using migrations.', + 'section', 'Guides', 'current', 'Database migrations' +)) as properties; -- Article by Matthew Larkin select 'text' as component, diff --git a/examples/official-site/your-first-sql-website/nginx.md b/examples/official-site/your-first-sql-website/nginx.md index 9e156135f..59235958b 100644 --- a/examples/official-site/your-first-sql-website/nginx.md +++ b/examples/official-site/your-first-sql-website/nginx.md @@ -4,9 +4,7 @@ Hosting SQLPage behind a reverse proxy can help with security, scalability, and In this guide, we will guide you step-by-step on how to host SQLPage behind a reverse proxy using [NGINX](https://www.nginx.com/). -## Why host SQLPage behind a Reverse Proxy ? - -Here are some reasons why you might want to host SQLPage behind a reverse proxy: +## Reverse proxy features - **customize your application's URLs**, removing `.sql` extensions and changing URL parameters - **protect against attacks** such as denial-of-service (DoS) by rate limiting incoming requests @@ -119,7 +117,7 @@ server { This configuration uses the `rewrite` directive to rewrite URLs of the form `/products/$id` to `/products.sql?id=$id`. The `^/products/([^/]+)$` pattern matches URLs that start with `/products/` and captures the dynamic parameter `$id` using parentheses. The `last` flag indicates that this rewrite rule should be the last one to be applied; if the pattern matches, the rewritten URL is passed to the next location block, in this case, the proxy_pass directive. -**How it Works** +**Request routing** When a request is made to `/products/123`, the rewrite rule is triggered, and the URL is rewritten to `/products.sql?id=123`. The `proxy_pass` directive then forwards the rewritten URL to the SQLPage instance, which processes the request and returns the response. @@ -344,7 +342,7 @@ server { } ``` -# Example NGINX configuration for SQLPage +## Complete NGINX configuration You can find a fully working example of an NGINX configuration for SQLPage illustrating all the features described in this guide diff --git a/examples/official-site/your-first-sql-website/nginx.sql b/examples/official-site/your-first-sql-website/nginx.sql index bd2d6b6b2..cb9b04e4e 100644 --- a/examples/official-site/your-first-sql-website/nginx.sql +++ b/examples/official-site/your-first-sql-website/nginx.sql @@ -1,5 +1,8 @@ select 'http_header' as component, 'public, max-age=300, stale-while-revalidate=3600, stale-if-error=86400' as "Cache-Control"; -select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1; -select 'text' as component, sqlpage.read_file_as_text('your-first-sql-website/nginx.md') as contents_md; \ No newline at end of file +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-shell.sql', json_object( + 'title', 'Reverse proxy | SQLPage', + 'section', 'Guides', 'current', 'Reverse proxy' +)) as properties; +select 'text' as component, true as article, sqlpage.read_file_as_text('your-first-sql-website/nginx.md') as contents_md; diff --git a/examples/official-site/your-first-sql-website/tutorial-install-any.md b/examples/official-site/your-first-sql-website/tutorial-install-any.md index d91533b2a..e1086812a 100644 --- a/examples/official-site/your-first-sql-website/tutorial-install-any.md +++ b/examples/official-site/your-first-sql-website/tutorial-install-any.md @@ -1,4 +1,4 @@ -# Download SQLPage +## Download SQLPage SQLPage is a small single-file program that will execute the SQL files you write, diff --git a/examples/official-site/your-first-sql-website/tutorial-install-macos.md b/examples/official-site/your-first-sql-website/tutorial-install-macos.md index 973c21a9b..ddd64511f 100644 --- a/examples/official-site/your-first-sql-website/tutorial-install-macos.md +++ b/examples/official-site/your-first-sql-website/tutorial-install-macos.md @@ -1,10 +1,10 @@ -# Install SQLPage on macOS +## Install SQLPage on macOS For a quick start on an Apple silicon Mac (M-series), download SQLPage below. If you already use [Homebrew](https://brew.sh/) or want easier updates, use the Homebrew instructions instead. On an Intel Mac, use Homebrew. -## Download SQLPage for Apple silicon +### Download SQLPage for Apple silicon [Download SQLPage for Apple silicon](https://github.com/sqlpage/SQLPage/releases/latest/download/sqlpage-macos.tgz). Open the downloaded archive to extract it. Keep `sqlpage.bin` and the `sqlpage` folder together in your website folder. @@ -19,7 +19,7 @@ To update later, download the latest version and replace `sqlpage.bin`. Keep you Starting with SQLPage v0.47.0, this download is for Apple silicon only. On an Intel Mac, use Homebrew below. -## Install with Homebrew +### Install with Homebrew If you do not already have Homebrew, open Terminal and install it: diff --git a/examples/official-site/your-first-sql-website/tutorial-install-windows.md b/examples/official-site/your-first-sql-website/tutorial-install-windows.md index 19767d6f1..954c4729a 100644 --- a/examples/official-site/your-first-sql-website/tutorial-install-windows.md +++ b/examples/official-site/your-first-sql-website/tutorial-install-windows.md @@ -1,4 +1,4 @@ -# Download the SQLPage executable for Windows +## Download the SQLPage executable for Windows SQLPage offers a small executable file (`sqlpage.exe`) that will take requests to your website, execute the SQL files you write, and render the database responses as nice web pages. diff --git a/examples/official-site/your-first-sql-website/tutorial.md b/examples/official-site/your-first-sql-website/tutorial.md index 761dfaa3b..c0681107c 100644 --- a/examples/official-site/your-first-sql-website/tutorial.md +++ b/examples/official-site/your-first-sql-website/tutorial.md @@ -1,4 +1,4 @@ -# Building your website locally +## Building your website locally Create a folder on your computer where you will store all contents related to your sql website. In the rest of this tutorial, we will call this folder the **root folder** of your website. @@ -15,7 +15,7 @@ You can open your website locally by visiting [`http://localhost:8080`](http://l SQLPage should have automatically created a folder called `sqlpage` with a SQLite database file named `sqlpage.db`. This is your website's default database - don't worry, we'll learn how to connect to other databases like PostgreSQL, MySQL, or SQL Server later! -# Your website's first SQL file +## Your website's first SQL file In the root folder of your SQLPage website, create a new SQL file called `index.sql`. Open it in a text editor that supports SQL syntax highlighting (I recommend [VSCode](https://code.visualstudio.com/)). @@ -39,9 +39,9 @@ SELECT 'Hello' AS title, The first line of the file defines the component that will be used to display the data, and properties of that component. In this case, we use the [`list` component](/component.sql?component=list) to display a list of items. The second line defines the data that will populate the component. -All the components you can use and their properties are documented in [SQLPage's online documentation](https://sql-page.com/documentation.sql). +All the components you can use and their properties are documented in [SQLPage's online documentation](/components.sql). -# Your database schema +## Your database schema > If you already have a database populated with data, > or if you intend to use other tools to manage your database structure, @@ -69,7 +69,7 @@ learn how to maintain your database schema in the long term. > **Note**: The migration system is not supported on Microsoft SQL Server databases. > If you are using a SQL Server database, you should create your tables using a different tool, such as _SQL Server Management Studio_. -# Connect to a custom database +

Connect to a custom database

By default, SQLPage uses a [SQLite](https://www.sqlite.org/about.html) database stored in a file named `sqlpage.db` in the `sqlpage` configuration folder. @@ -102,7 +102,7 @@ For more information about the properties that can be set in sqlpage.json, see [ ![screenshot for the full sql website folder organisation](full-website.png) -# Use parameterized SQL queries to let users interact with your database +

Use parameterized SQL queries to let users interact with your database

### Displaying a form @@ -113,7 +113,7 @@ SELECT 'form' AS component, 'Add a user' AS title; SELECT 'Username' as name, TRUE as required; ``` -The first SELECT statement opens the [`form` component](https://sql-page.com/component.sql?component=form). +The first SELECT statement opens the [`form` component](/component.sql?component=form). The second SELECT statement adds a field to the form. Since we do not specify a `type`, it will be a text field. The label displayed above the field will be the same as its name by default. ### Handling form submission @@ -174,7 +174,7 @@ Here is a screenshot of the final result: To go further, have a look at [the examples](../examples/). -# Deploy your SQLPage website online +

Deploy your SQLPage website online

### Using DataPage.app To deploy your SQLPage website online, the easiest way is to use [DataPage.app](https://datapage.app), @@ -193,10 +193,10 @@ If you prefer to host your website yourself, you can use a cloud provider or a V - Optionally, setup a TLS certificate to enable HTTPS - Configure connection to a cloud database or a database running on your server in [`sqlpage.json`](https://github.com/sqlpage/SQLPage/blob/main/configuration.md#configuring-sqlpage) -# Go further +## Go further - Check out [learnsqlpage.com](https://learnsqlpage.com) by Nick Antonaccio for an in-depth tutorial with many examples -- Read the [SQLPage documentation](/documentation.sql) to learn about all the components available in SQLPage +- Read the [component reference](/components.sql) to learn about all the components available in SQLPage - Read about [SQLPage's extensions to SQL](/extensions-to-sql) for a specification of the SQL syntax you can use in SQLPage, the data types used when exchanging data with the browser and with the database, a clear explanation of how *SQLPage variables* and *SQLPage functions* work. - Join the [SQLPage community](https://github.com/sqlpage/SQLPage/discussions) to ask questions and share your projects - If you like videos better, check this series that shows how to build and deploy your app from scratch [SQLPage on Youtube](https://www.youtube.com/playlist?list=PLTue_qIAHxAf9fEjBY2CN0N_5XOiffOk_) diff --git a/sqlpage/templates/login.handlebars b/sqlpage/templates/login.handlebars index 46014bfc5..3bb4a975f 100644 --- a/sqlpage/templates/login.handlebars +++ b/sqlpage/templates/login.handlebars @@ -31,23 +31,23 @@
{{/if}} - +
{{icon_img (default username_icon 'user-circle')}} - +
-