@uniweb/unipress 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -64,15 +64,16 @@ separates create-time templates from runtime foundations.
64
64
  - `templates/` directory; `package.json`'s `files:` array now ships
65
65
  `documents/`.
66
66
 
67
- ### Caveat
68
-
69
- Catalog entries currently point at the **local registry**
70
- (`http://localhost:4001/registry/packages/<ns>/<name>/<ver>/foundation.js`).
71
- Scaffolded documents will fail to fetch the foundation unless the
72
- foundations are published locally via `uniweb publish --local` against
73
- a running unicloud, OR the user passes `--foundation <path>` explicitly.
74
- A follow-up release switches the catalog URLs to the production
75
- registry once `@uniweb/book` and `@uniweb/data` publish there.
67
+ ### Caveat (resolved in a follow-up release)
68
+
69
+ Catalog entries in 0.2.0 pointed at a local registry
70
+ (`http://localhost:4001/...`), so scaffolded documents required the
71
+ user to run a registry locally or to pass `--foundation <path>`
72
+ explicitly. A subsequent release switches the catalog URLs to GitHub
73
+ Pages (`https://uniweb.github.io/unipress/foundations/...`); the
74
+ foundations are deployed there by `.github/workflows/deploy-foundations.yml`
75
+ on every push to main, and `unipress create + compile` works end-to-end
76
+ from a fresh npm install.
76
77
 
77
78
  ## 0.1.0 (unreleased)
78
79
 
package/README.md CHANGED
@@ -26,9 +26,11 @@ Equations work in the standard LaTeX style — `$E = mc^2$` for inline, `$$...$$
26
26
 
27
27
  **For authors.** unipress is a tool. Pick a template, write markdown, compile. The template knows the conventions for its kind of document — typography, structure, the bits that make a book look like a book and a directory look like a directory. You handle the content; the template handles everything else.
28
28
 
29
- **For developers.** unipress is an engine. A *foundation* is a component system that declares what section types exist (`type: Chapter`, `type: Bibliography`), where data comes from (`data:` declarations), and what output formats it can emit (`outputs: { docx, xlsx, pdf, custom-format }`). Authors write markdown against your vocabulary; unipress runs your foundation against their content. Same content directory, multiple outputs your foundation chooses to support — typeset book, accessible EPUB, regulatory report, structured data feed. The same foundation can also drive a [Uniweb](https://uniweb.io) website, so the work is never single-purpose.
29
+ **For developers.** unipress is an engine. A *foundation* you write declares what section types exist (`type: Chapter`, `type: Bibliography`), where their data comes from (markdown content, file-based or API-backed collections, [Loom](https://github.com/uniweb/loom) expressions templating against hierarchical data), and what output formats it can emit (`outputs: { docx, xlsx, pdf, custom-format }`). Authors mix prose with structured records and computed values in the same document; unipress runs your foundation against their content and produces whatever your foundation declares — typeset book, accessible EPUB, regulatory report, structured data feed. The same foundation can also drive a [Uniweb](https://uniweb.io) website, so the work is never single-purpose.
30
30
 
31
- Foundations consume [`@uniweb/press`](https://github.com/uniweb/press) for the bytes-emitting work. Press is the output layer (Word, Excel, Typst today; more formats shipping); the foundation is your vocabulary.
31
+ Foundations consume [@uniweb/press](https://github.com/uniweb/press) for the bytes-emitting work. Press is the output layer (Word, Excel, Typst today; more formats shipping); the foundation is your vocabulary.
32
+
33
+ → For the deeper pitch — mixed prose-and-data, Loom templating, custom output adapters — see [docs/for-developers.md](./docs/for-developers.md).
32
34
 
33
35
  ## Install
34
36
 
@@ -52,7 +54,7 @@ Five built-in templates ship with the binary. Run `unipress list-templates` for
52
54
  | `data-report` | `@uniweb/data` | xlsx, docx | Aggregate metrics across structured records |
53
55
  | `directory` | `@uniweb/data` | xlsx, docx | Flat records listing with a filterable surface |
54
56
 
55
- Per-template guides: [`docs/templates/`](./docs/templates/).
57
+ Per-template guides: [docs/templates/](./docs/templates/).
56
58
 
57
59
  More templates land as more foundations ship — `cv`, `resume`, `paper`, `thesis` are on the roadmap for upcoming releases.
58
60
 
@@ -200,12 +202,12 @@ unipress is **pre-1.0**. The CLI is stable enough to write real documents with
200
202
 
201
203
  ## Troubleshooting
202
204
 
203
- See [`docs/troubleshooting.md`](./docs/troubleshooting.md) for common errors and fixes — every named error class maps to a cause and a concrete next step.
205
+ See [docs/troubleshooting.md](./docs/troubleshooting.md) for common errors and fixes — every named error class maps to a cause and a concrete next step.
204
206
 
205
207
  ## See also
206
208
 
207
- - [`@uniweb/press`](https://github.com/uniweb/press) — the output layer foundations consume to produce Word/Excel/Typst/EPUB. Foundation authors interact with it directly.
208
- - [`@uniweb/build`](https://github.com/uniweb/build) — the framework's content-collection pipeline. unipress consumes the sharp-free `/content` entry.
209
+ - [@uniweb/press](https://github.com/uniweb/press) — the output layer foundations consume to produce Word/Excel/Typst/EPUB. Foundation authors interact with it directly.
210
+ - [@uniweb/build](https://github.com/uniweb/build) — the framework's content-collection pipeline. unipress consumes the sharp-free `/content` entry.
209
211
  - [Uniweb](https://uniweb.io) — the larger framework. Foundations originate here; unipress brings them to the command line.
210
212
 
211
213
  ## License
package/RELEASING.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Notes for cutting a release tag (`unipress@<version>`). The release workflow at `.github/workflows/release.yml` watches for tag pushes matching that pattern, builds three binaries (darwin-arm64, linux-x64, windows-x64), and creates a GitHub Release with the binaries and SHA-256 sidecars attached.
4
4
 
5
- This file mostly exists to flag one thing the release workflow currently can't handle on its own.
5
+ A separate workflow at `.github/workflows/deploy-foundations.yml` builds and deploys the bundled foundations (`foundations/<name>/`) to the unipress repo's GitHub Pages site under `https://uniweb.github.io/unipress/foundations/<name>/<version>/`. It runs on every push to main, accumulating versions on the `gh-pages` branch — older versions stay reachable indefinitely. No tag needed; foundation deployment is decoupled from the binary-release tag cadence.
6
+
7
+ This file mostly exists to flag one thing the binary-release workflow currently can't handle on its own.
6
8
 
7
9
  ---
8
10
 
@@ -0,0 +1,113 @@
1
+ # unipress for developers
2
+
3
+ The developer-track companion to the README. Read this if you're considering writing a foundation that compiles to documents — or to documents *and* websites from the same source.
4
+
5
+ ## What you actually get
6
+
7
+ A foundation is a [Uniweb](https://uniweb.io) component system. unipress is the **headless runtime** for it: run `unipress compile <dir>` and the same foundation that drives a Uniweb website produces a downloadable file from a content directory.
8
+
9
+ That means everything the framework does for websites, you can do for documents. The visual editor goes away; the compile pipeline stays.
10
+
11
+ ## Section types are the vocabulary
12
+
13
+ A foundation declares **section types** — addressable React components that content authors reference by name from markdown frontmatter:
14
+
15
+ ```markdown
16
+ ---
17
+ type: Chapter
18
+ title: "Chapter One"
19
+ ---
20
+
21
+ Prose body here.
22
+ ```
23
+
24
+ The foundation decides what `Chapter` means: its layout, its typography, what data it expects, how it renders across each output format the foundation declares. Authors don't think in components — they think in *kinds of section*. The component is the foundation developer's responsibility; the content is the author's.
25
+
26
+ ## Mix prose with structured data
27
+
28
+ A document is rarely just prose. Foundations declare data inputs; authors fill them in. The data can come from any of these surfaces:
29
+
30
+ - **Markdown content** — the prose body of each `.md` file, parsed into a structured tree (title, paragraphs, items, links, images, code blocks).
31
+ - **Frontmatter params** — declared in each section's YAML frontmatter, typed by the foundation's `meta.js`.
32
+ - **File-based collections** — `collections/publications.json`, `collections/team.yml`, or markdown frontmatter swept into a list at build time. Compile to one `/data/<name>.json` per collection.
33
+ - **API-backed collections** — declare a fetcher in `document.yml`; the build pipeline resolves it at compile time. The foundation reads `content.data` and renders.
34
+ - **Computed values via [Loom](https://github.com/uniweb/loom)** — Loom is an expression language for instantiating templates against hierarchical data. Pull a publications list from a collection, format each entry with a Loom expression, and the result lands typeset in your output.
35
+
36
+ All of these flow through the same foundation pipeline — same primitives whether the data came from a YAML file, a JSON dump, or an API endpoint.
37
+
38
+ ### Academic writing: bibliographies and citations
39
+
40
+ For scholarly work specifically, [`citestyle`](https://github.com/uniweb/csl) handles the formatting layer Loom is too general for. CSL-based, lightweight, used directly from foundations: pick from APA, MLA, Chicago author-date, IEEE, Vancouver, Harvard at the section level (`style: chicago-author-date`); citestyle dynamically loads only the styles you reference and formats every entry to spec — the author ordering, journal abbreviations, punctuation, and conventions academic readers expect.
41
+
42
+ The combination is the powerful part. Loom interpolates ("In {section.title}, we describe…"); citestyle formats bibliographic entries (a complete back-matter `Bibliography`, or inline `[Author Year]` citation marks). A thesis, monograph, or annual research report uses both: Loom for dynamic prose and per-section metadata, citestyle for every bibliographic touch in the document.
43
+
44
+ Working example: the `data-report` template ships a `PublicationsList` section backed by YAML bib data in `collections/members/*.yml`, with per-section style selection. Run `unipress create my-report --template data-report` to see it. Bibliography support in long-form prose templates (`book`, `monograph`, future `thesis`/`paper`) lands across upcoming releases.
45
+
46
+ ## Outputs are foundation-declared
47
+
48
+ ```js
49
+ // foundation/src/foundation.js
50
+ export default {
51
+ outputs: {
52
+ pdf: { extension: 'pdf', via: 'typst', getOptions: buildTypstOptions },
53
+ epub: { extension: 'epub', getOptions: buildEpubOptions },
54
+ docx: { getOptions: buildDocxOptions },
55
+ 'tax-form-2024': { getOptions: buildTaxFormOptions }, // your own adapter
56
+ },
57
+ }
58
+ ```
59
+
60
+ Each entry says: which Press adapter handles the format (`via:`), which file extension to default to (`extension:`), and how to assemble adapter-specific options from the website's resolved content (`getOptions(website, hostHints)`).
61
+
62
+ Press ships adapters for Word, Excel, Typst (PDF), and HTML-shaped output. For a format Press doesn't ship — a CSV feed, a domain-specific XML, a one-of-a-kind regulatory submission — write a custom adapter using [`@uniweb/press/ir`](https://github.com/uniweb/press) and declare it on the foundation. unipress dispatches by name; nothing in unipress itself needs to know about your format.
63
+
64
+ ## Same foundation, two runtimes
65
+
66
+ `unipress compile` is one consumer. The Uniweb website pipeline (`uniweb dev`, `uniweb build`) is the other. Same foundation, same content shape, same data declarations — different runtime.
67
+
68
+ That's the structural payoff: the work of defining section types, theming, and rendering isn't single-purpose. A "regulatory report" foundation can drive both an HTML site that stakeholders browse and a PDF/XLSX/DOCX bundle filed quarterly. A "research output" foundation can drive a public-facing journal site and a print-ready PDF for archival. Authoring once produces every modality.
69
+
70
+ ## A worked example
71
+
72
+ A research-group annual-report foundation (`@yourorg/annual-report`) might ship:
73
+
74
+ - **Section types**: `Cover`, `ExecutiveSummary`, `Members`, `PublicationsList`, `FundingTable`, `Charts`, `Appendix`, `Bibliography`.
75
+ - **Data**: a `publications.yml` collection (file-based) with full bibliographic fields per paper; a `funding.json` collection with grant data; an API-backed `metrics:` collection pulling live citation counts.
76
+ - **citestyle for bibliographic precision**: pick a style at the section level (`style: chicago-author-date`) and citestyle formats every entry to spec — author ordering, journal abbreviations, the punctuation that marks the difference between a draft and a polished publication.
77
+ - **Loom templates**: dynamic prose elsewhere — running headers (`{book.title} — Chapter {n}`), section subtitles, the table-of-contents introductions. Loom and citestyle cooperate: citestyle owns bibliographic formatting; Loom owns everything else.
78
+ - **Outputs**: `pdf` (typeset for the dean's office), `xlsx` (one sheet per data block, for finance), `docx` (for collaborators who don't open PDFs), `pagedjs` (HTML for the public site).
79
+
80
+ A content author writes:
81
+
82
+ ```markdown
83
+ ---
84
+ type: PublicationsList
85
+ title: "Publications"
86
+ data: publications
87
+ filter:
88
+ year: 2024
89
+ ---
90
+
91
+ The group published 47 papers in 2024, a 30% increase over 2023.
92
+ ```
93
+
94
+ `unipress compile annual-2024 --format pdf` walks the content through the foundation, resolves Loom expressions over the filtered collection, runs the typst adapter, ships a typeset PDF. `unipress compile annual-2024 --format xlsx` produces a workbook with one sheet per data section. The same source directory; two file types, both honest.
95
+
96
+ ## Where to go from here
97
+
98
+ - **Foundation contract** — the `outputs:` map, `meta.js` section-type discovery, the `getOptions(website, hostHints)` signature: see [foundation configuration](https://github.com/uniweb/docs/blob/main/reference/foundation-config.md).
99
+ - **Data fetching** — collections, fetchers, predicates, where-objects, deferred fields: see the [data fetching reference](https://github.com/uniweb/docs/blob/main/reference/data-fetching.md).
100
+ - **Loom** — expression language for instantiating templates against hierarchical data: [`@uniweb/loom`](https://github.com/uniweb/loom).
101
+ - **citestyle** — CSL-based citation and bibliography formatter. Domain-specific complement to Loom: Loom interpolates, citestyle formats academic-style references: [`citestyle`](https://github.com/uniweb/csl).
102
+ - **Press (the output layer)** — [`@uniweb/press`](https://github.com/uniweb/press) docs cover the registration pattern foundations consume, the IR layer for custom adapters, and per-adapter notes (docx invariants, typst conventions, the EPUB pipeline).
103
+ - **Building a foundation from scratch** — [Uniweb framework docs](https://github.com/uniweb/docs) cover the full authoring story; everything written for sites applies to documents.
104
+
105
+ ## A few things worth knowing upfront
106
+
107
+ **Documents are static at compile time.** unipress produces bytes; once the file is on disk, it doesn't change. "Dynamic data" in a document means *the data backing the document can vary between compiles* (re-run `unipress compile` after the API has new data; get a new PDF). It does not mean the PDF live-updates while someone reads it. That's website territory.
108
+
109
+ **Foundations stay environment-agnostic.** unipress runs in Node; the Uniweb editor runs in the browser. Foundations should not branch on `typeof window` or do their own asset I/O. The compile pipeline supplies a `loadAsset(src)` helper that hosts implement appropriately for their runtime; foundations just call it. The book foundation in this repo is the reference example.
110
+
111
+ **Compile failures are debuggable.** `unipress compile <dir> --verbose` streams every step; `unipress inspect <dir>` dumps the parsed content tree as JSON before the foundation runs (useful when output looks wrong and you want to know whether the input was right). Press emits structured warnings when an adapter receives unexpected shapes.
112
+
113
+ **Pre-1.0.** The contract is settling but not frozen. The foundation `outputs:` map, the `meta.js` discovery model, the `compileDocument` API, the section-type vocabulary — all stable enough to build against, with breaking changes possible (and documented in the CHANGELOG) before 1.0.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/unipress",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Compile a content directory into a document (PDF, EPUB, Paged.js HTML, Typst source bundle, DOCX, XLSX) using a Uniweb foundation. Five built-in templates: book, monograph, report, data-report, directory.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -49,11 +49,11 @@
49
49
  "prompts": "^2.4.2",
50
50
  "react": "^18.0.0 || ^19.0.0",
51
51
  "react-dom": "^18.0.0 || ^19.0.0",
52
- "@uniweb/content-reader": "1.1.5",
53
- "@uniweb/semantic-parser": "1.1.11",
52
+ "@uniweb/build": "0.11.2",
54
53
  "@uniweb/runtime": "0.8.4",
55
54
  "@uniweb/core": "0.7.3",
56
- "@uniweb/build": "0.11.2"
55
+ "@uniweb/content-reader": "1.1.5",
56
+ "@uniweb/semantic-parser": "1.1.11"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "echo \"no tests yet\" && exit 0",
@@ -41,7 +41,17 @@ const PATH_PATTERN = /^(\.\.?[\/\\]|[\/\\]|[A-Za-z]:[\/\\])/
41
41
  // Version is anything semver-shaped — exact match isn't enforced here; the
42
42
  // registry decides what's valid.
43
43
  const REGISTRY_REF_PATTERN = /^@([a-z0-9][a-z0-9._-]*)\/([a-z0-9][a-z0-9._-]*)@([0-9a-z][0-9a-z.\-+]*)$/i
44
- const DEFAULT_REGISTRY_BASE = 'https://site-router.uniweb-edge.workers.dev'
44
+
45
+ // unipress's bundled foundations are distributed as static artifacts on
46
+ // the unipress repo's GitHub Pages site. URL pattern:
47
+ //
48
+ // https://uniweb.github.io/unipress/foundations/<name>/<version>/foundation.js
49
+ //
50
+ // The namespace portion of a registry ref is implicit — every foundation
51
+ // served from this base is under @uniweb/. Set UNIWEB_REGISTRY_URL to
52
+ // override (e.g., for testing against a local http.server during foundation
53
+ // development, or for users with a private alternative).
54
+ const DEFAULT_REGISTRY_BASE = 'https://uniweb.github.io/unipress'
45
55
  const DEFAULT_BUILT_ENTRY = 'dist/foundation.js'
46
56
 
47
57
  function getRegistryBase() {
@@ -49,8 +59,15 @@ function getRegistryBase() {
49
59
  return raw.replace(/\/$/, '')
50
60
  }
51
61
 
62
+ // Build the URL for a registry ref. The namespace is preserved in the
63
+ // returned URL only when the base wants it; for the GH Pages distribution
64
+ // the namespace is implicit and the path is <base>/foundations/<name>/<ver>/.
65
+ // If a custom UNIWEB_REGISTRY_URL needs the namespace in the path, it can
66
+ // hold a path prefix that resolves accordingly (e.g., set
67
+ // `UNIWEB_REGISTRY_URL=https://my.host/by-ns/uniweb` and live without the
68
+ // per-namespace split, or maintain a redirect rule on that host).
52
69
  function buildRegistryUrl(namespace, name, version) {
53
- return `${getRegistryBase()}/registry/packages/${namespace}/${name}/${version}/foundation.js`
70
+ return `${getRegistryBase()}/foundations/${name}/${version}/foundation.js`
54
71
  }
55
72
 
56
73
  export async function resolveFoundationRef(ref, { anchorDir, onProgress = () => {} } = {}) {
@@ -10,6 +10,25 @@
10
10
  * different `book.structure:` defaults, and different sample chapters.
11
11
  *
12
12
  * ─────────────────────────────────────────────────────────────────────────
13
+ * Distribution
14
+ * ─────────────────────────────────────────────────────────────────────────
15
+ *
16
+ * Foundations are deployed as static artifacts to the unipress repo's
17
+ * GitHub Pages site. URL pattern:
18
+ *
19
+ * https://uniweb.github.io/unipress/foundations/<name>/<version>/foundation.js
20
+ *
21
+ * On every push to main, `.github/workflows/deploy-foundations.yml`
22
+ * builds each `foundations/<name>/` and layers the resulting `dist/` into
23
+ * the gh-pages branch under `foundations/<name>/<version>/`. Versions
24
+ * accumulate; older versions stay reachable indefinitely.
25
+ *
26
+ * GH Pages serves `Access-Control-Allow-Origin: *` on static files, so
27
+ * cross-origin imports work for browser hosts (Uniweb editor preview).
28
+ * The unipress CLI fetches the URL directly and caches at
29
+ * `~/.cache/unipress/foundations/...`.
30
+ *
31
+ * ─────────────────────────────────────────────────────────────────────────
13
32
  * Resolution path
14
33
  * ─────────────────────────────────────────────────────────────────────────
15
34
  *
@@ -17,15 +36,15 @@
17
36
  * 1. catalog lookup (this file) → entry.foundation.ref + entry.scaffold.
18
37
  * 2. scaffold copies templates-data.js[entry.scaffold] into my-doc/. The
19
38
  * bundled document.yml has `foundation: <entry.foundation.ref>` (the
20
- * registry-ref form, e.g., '@uniweb/book@0.1.0' — rewritten from the
39
+ * registry-ref form, e.g., '@uniweb/book@0.1.1' — rewritten from the
21
40
  * committed dev path-ref by scripts/generate-templates-data.js).
22
41
  *
23
42
  * `unipress compile my-doc`:
24
- * 1. document.yml `foundation: '@uniweb/book@0.1.0'` is parsed as a
43
+ * 1. document.yml `foundation: '@uniweb/book@0.1.1'` is parsed as a
25
44
  * registry ref by foundation-loader.js.
26
45
  * 2. The loader constructs a URL from the registry base
27
- * (UNIWEB_REGISTRY_URL or the production default at
28
- * site-router.uniweb-edge.workers.dev) → fetches + caches.
46
+ * (UNIWEB_REGISTRY_URL env override or the default GH Pages base) →
47
+ * fetches + caches.
29
48
  *
30
49
  * ─────────────────────────────────────────────────────────────────────────
31
50
  * source.url
@@ -33,14 +52,9 @@
33
52
  *
34
53
  * Each entry's `foundation.source.url` is the human-meaningful "where this
35
54
  * foundation lives" pointer shown in `list-templates` output and post-create
36
- * messages. It does NOT drive resolution under the registry-ref-in-document.yml
37
- * modelfoundation-loader builds its own URL from the ref + base. The
38
- * URL is included for transparency.
39
- *
40
- * v0.2 entries pin local-registry URLs (http://localhost:4001/...) so
41
- * foundation devs running `uniweb publish --local` can verify resolution
42
- * end-to-end. TF8 of the unipress-foundations-and-templates plan switches
43
- * these to the production registry once the foundations publish there.
55
+ * messages. It mirrors the URL the loader builds at compile time, but does
56
+ * not itself drive resolution the loader builds its own URL from
57
+ * `foundation.ref` + the configured base.
44
58
  *
45
59
  * ─────────────────────────────────────────────────────────────────────────
46
60
  * Storage format
@@ -51,20 +65,20 @@
51
65
  * runtime reads.
52
66
  */
53
67
 
54
- const LOCAL_REGISTRY_BASE = 'http://localhost:4001/registry/packages'
68
+ const PUBLIC_FOUNDATIONS_BASE = 'https://uniweb.github.io/unipress/foundations'
55
69
 
56
- function localUrl(namespace, name, version) {
57
- return `${LOCAL_REGISTRY_BASE}/${namespace}/${name}/${version}/foundation.js`
70
+ function publicUrl(name, version) {
71
+ return `${PUBLIC_FOUNDATIONS_BASE}/${name}/${version}/foundation.js`
58
72
  }
59
73
 
60
74
  const BOOK_FOUNDATION = {
61
- ref: '@uniweb/book@0.1.0',
62
- source: { url: localUrl('uniweb', 'book', '0.1.0') },
75
+ ref: '@uniweb/book@0.1.1',
76
+ source: { url: publicUrl('book', '0.1.1') },
63
77
  }
64
78
 
65
79
  const DATA_FOUNDATION = {
66
80
  ref: '@uniweb/data@0.1.0',
67
- source: { url: localUrl('uniweb', 'data', '0.1.0') },
81
+ source: { url: publicUrl('data', '0.1.0') },
68
82
  }
69
83
 
70
84
  export const FOUNDATIONS = [