bearminion 1.19.0 → 1.21.0
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 +28 -0
- package/README.md +4 -2
- package/dist/astro.d.ts +23 -7
- package/dist/astro.js +221 -94
- package/dist/cli.js +903 -4
- package/dist/content-types-POybRzMX.js +504 -0
- package/dist/content.d.ts +24 -3
- package/dist/content.js +83 -6
- package/dist/{editor-context-DzRwKENi.d.ts → editor-context-BwQzdSow.d.ts} +76 -7
- package/dist/{github-store-D3LEUhcM.js → github-store-4-Y4ERBF.js} +513 -200
- package/dist/{github-store-DsLCe5MR.d.ts → github-store-BVQY4d-Q.d.ts} +1 -1
- package/dist/hosted-astro.js +6 -3
- package/dist/{hosted-middleware-CedN9WNM.js → hosted-middleware-D6cd62SL.js} +3 -2
- package/dist/hosted-overlay.js +1 -1
- package/dist/hosted.d.ts +22 -4
- package/dist/hosted.js +79 -11
- package/dist/index.d.ts +4 -41
- package/dist/index.js +6 -5
- package/dist/{migrate-b408EaLp.js → migrate-Cm30puW8.js} +2 -2
- package/dist/{page-wlcQJAA-.js → page-CcC5RRMj.js} +1 -1
- package/dist/{page-BGSTL63-.d.ts → page-aWKWqoh4.d.ts} +184 -44
- package/dist/{request-guards-BcSUj8Gc.js → request-guards-6WtQV3-a.js} +1 -1
- package/dist/{collections-BbL4_4jt.js → routing-BWuJlNud.js} +245 -57
- package/dist/routing-DimIRnjk.d.ts +133 -0
- package/dist/{theme-BvqJ8UnS.js → theme-DVMi1524.js} +1 -1
- package/dist/ui/mount.js +625 -271
- package/package.json +1 -1
- package/registry/default/files/src/components/organisms/EntryList.astro +83 -0
- package/registry/default/files/src/components/organisms/Pagination.astro +56 -0
- package/registry/default/files/src/components/sections/contact/definition.ts +6 -2
- package/registry/default/files/src/components/sections/faq/definition.ts +2 -2
- package/registry/default/files/src/components/sections/media/Media.astro +2 -2
- package/registry/default/files/src/components/sections/media/MediaPlayer.astro +2 -2
- package/registry/default/files/src/components/sections/pricing/definition.ts +16 -1
- package/registry/default/files/src/components/sections/shared.ts +3 -0
- package/registry/default/files/src/components/sections/stats/definition.ts +6 -1
- package/registry/default/files/src/components/sections/testimonials/definition.ts +13 -1
- package/registry/default/files/src/components/sections/text-image/definition.ts +1 -1
- package/registry/default/files/src/content.config.ts +21 -0
- package/registry/default/files/src/env.d.ts +2 -0
- package/registry/default/files/src/lib/content.ts +81 -0
- package/registry/default/files/src/lib/editing.ts +6 -0
- package/registry/default/files/src/lib/sitemap.ts +48 -0
- package/registry/default/files/src/pages/[...slug].astro +32 -13
- package/registry/default/registry.json +76 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# bearminion
|
|
2
2
|
|
|
3
|
+
## 1.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4cc33c5: Content types: declare a blog, a news list or a fixed page in the content model, and get entries with their own fields, a sort order, a paginated listing page and lists in the editor. Guide: [Content types](https://docs.bearminion.com/content-types/). A site that declares no types builds the same HTML as before with the files it has.
|
|
8
|
+
|
|
9
|
+
- **The home page is a fixed page.** "Home page" is gone from the page form, and so are `POST /pages/:slug/set-home` and `previousHomeSlug` in `POST /save`. No page can be renamed to `index`. Nothing in your content changes: `content/pages/index.json` is still the home page. To change what visitors see first, edit the home page's sections. If you really want another page's content there, swap the two files in git and set each file's `slug`.
|
|
10
|
+
- **Content types in the editor API.** `types: defineTypes({ blog: multi({ path: '/blog/{slug}', fields, sort, listing }), about: single({ path: '/about' }) })` in the content model declares the site's own types next to the built-in home page, 404 page and `pages`. New routes: `GET /types`, `/types/:id/entries` (list, create, read, save, rename, delete), `/types/:id/listing` and `/types/:id/document`. `/pages` works as before. Deleting an image or video now also checks entries, listing pages and singles, and a page cannot take a slug that is the address of a type.
|
|
11
|
+
- **Migrations are told the type.** A `ContentMigration` receives the content type's id as a third argument. Existing migrations need no change.
|
|
12
|
+
- **Routing for types.** `siteRoutes(model, content)` lists every address of the site with what it shows (pages, singles, entries, and each listing page with its entries and pagination), `findRoute` picks one, and the hosted editor's `content.getRoute(pathname)` answers the same for one address from the repository. `loadContent()` also returns `entries`, `listings` and `singles`, and `contentCollections()` returns the extra collections under `types`. A site without `types` gets what it got before: two collections, the same pages.
|
|
13
|
+
- **The starter publishes declared types.** `src/pages/[...slug].astro` draws pages, entries, singles and listing pages from one route list, with two new components for a listing: `EntryList.astro` (a card per entry: title, and `date`, `excerpt` and `cover` when the type has fields by those names) and `Pagination.astro`. Listing page 2 and later is at `/blog/page/2`, has its own title and canonical address, and is in the sitemap. An entry whose `draft` field is on shows in `astro dev` and is left out of a build. A site without types builds the same HTML as before.
|
|
14
|
+
- **A build says when the site's files are too old for its types.** A site that declares a type but still has the route file from before content types fails `astro build` with the list of addresses that were not written and the fix (`npx bearminion add type --files-only`); `astro dev` warns. A site that declares no types is never checked.
|
|
15
|
+
- **`npx bearminion add type --files-only`** updates the files of a site made before 1.21 to the ones that publish content types: the page route, the collections, the content readers and the two listing components. Files you did not change are replaced, files you changed stop the command, and your `astro.config.ts` and content model are never edited. Only a site that declares a type needs it.
|
|
16
|
+
- **Content types in the editor.** Each declared type has its own list under Pages, in its sort order, with a New entry form; a title is enough to create an entry, and a required date starts as today. An entry opens at its own address. Its fields (date, excerpt, cover, a switch, a choice, a list) are edited in a Fields group drawn from the type's schema, and the section picker offers only the sections the type allows. Listing pages and singles are listed and edited like pages, with a fixed address. Links to entries are offered in the link picker and checked like links to pages. Drafts, undo and saved versions are kept per document.
|
|
17
|
+
- **`npx bearminion add type`** declares a content type. In a terminal it asks for the id, many entries or one page, the address, the fields (text, paragraph, date, number, switch, choice, image, list), a listing page and the order; scripts and assistants pass `--kind`, `--path`, `--label`, `--field name:kind`, `--sort` and `--listing` instead. Each type is its own file in `src/lib/types/`, gathered by `src/lib/types/index.ts` and passed to the content model as `types: siteTypes`, so a second and third type are a new file and one line each. It checks the type as `astro dev` would, and that no page or other type has its address, before writing anything, and it updates the site's own files first, like `--files-only`. **`npx bearminion add blog`** is `add type` with the blog answered: posts at `/blog/<slug>` with a date, an excerpt, a cover and a draft switch, newest first, listed at `/blog`. A new site starts with pages only.
|
|
18
|
+
- **A new site starts lean.** It has nine sections: Hero, Steps, Gallery, Features, Text, Text + Image, Media, FAQ and Call to action. Logo strip, Stats, Testimonials and Pricing are one `npx bearminion add <name>` away. The Contact section is not in a new site, because its form needs a handler and host glue to send anything: **`npx bearminion add form`** now adds the section along with them when the site has none. The sample pages link to `mailto:hello@example.com` where they linked to the Contact section. Existing sites keep every section they have.
|
|
19
|
+
|
|
20
|
+
## 1.20.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- c6dad44: The hosted editor has live preview, and its guide is a page of its own.
|
|
25
|
+
|
|
26
|
+
- **Live preview online.** A section just added, a layout switched and header or footer changes are now redrawn at once in the hosted editor, as in `astro dev`. Before, the preview endpoints answered 501 there and such changes showed only after Save and a reload. `bearminionHostedEditor` wires the theme's `src/lib/render-preview.ts` by itself (new option `previewModule`, a path or `false`); outside Astro, pass it as `editor.handle(request, { preview })`. Sites already on the hosted editor get it by updating `bearminion` and redeploying the editor project.
|
|
27
|
+
- **`signIn: 'optional'` no longer answers 500 to visitors.** The starter's `[...slug].astro` reads the build's content when a server build has no props. Existing sites: `npx bearminion@latest add hosted` updates the file.
|
|
28
|
+
- **Docs.** New page [Edit online](https://docs.bearminion.com/hosted-editor/): what the hosted editor is, who may edit (whoever may push to the repository), the setup in five steps, pull request mode, and its limits.
|
|
29
|
+
- **No longer experimental on Vercel.** The hosted editor and `githubStore` are tested end to end on real Vercel deployments with a real GitHub App. Cloudflare Workers has run only in the local Workers runtime and stays experimental.
|
|
30
|
+
|
|
3
31
|
## 1.19.0
|
|
4
32
|
|
|
5
33
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -34,12 +34,14 @@ It asks for the site's name and web address. Open the address `npm run dev` prin
|
|
|
34
34
|
## What you can change
|
|
35
35
|
|
|
36
36
|
- **Text** right on the page, with bold, italic, code, links and lists
|
|
37
|
-
- **Sections**: fourteen ready-made types, each with two or three layouts, added from a visual picker
|
|
37
|
+
- **Sections**: fourteen ready-made types, each with two or three layouts, added from a visual picker. A new site has nine; `npx bearminion add` brings the rest
|
|
38
38
|
- **Pages, menus and footer**, with titles and descriptions for search and sharing
|
|
39
39
|
- **Images**: upload, choose how they fill their frame and which part stays in view
|
|
40
40
|
- **Colors**: pick three, and the editor builds a full light and dark palette that stays readable
|
|
41
41
|
|
|
42
|
-
Content is plain JSON in your project, validated on every save and kept in your git history. The editor
|
|
42
|
+
Content is plain JSON in your project, validated on every save and kept in your git history. The editor runs during `astro dev`; the published site is static HTML with nothing from the editor in it.
|
|
43
|
+
|
|
44
|
+
**Editing online is opt-in.** `npx bearminion add hosted` sets up a second deployment where people sign in with GitHub and edit in the browser. Whoever may push to the repository may edit, and every save is a commit under their name. See [Edit online](https://docs.bearminion.com/hosted-editor/).
|
|
43
45
|
|
|
44
46
|
<p align="center">
|
|
45
47
|
<img src="https://raw.githubusercontent.com/langehelp-software/bearminion/main/.github/assets/design.png" alt="The Design tab: color mode, brand, neutral and link colors, and a preview of every section tone in light and dark mode" width="100%" />
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-
|
|
3
|
-
import {
|
|
1
|
+
import { C as ContentStore, T as UploadStore, n as ImageConvertOptions, t as EditorContext, w as StoreOperation, x as CollectionOptions } from "./editor-context-BwQzdSow.js";
|
|
2
|
+
import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-BVQY4d-Q.js";
|
|
3
|
+
import { C as ContentType, D as ListingDocument, Nt as SiteDefinition, Pt as SiteOf, T as Entry, U as SectionOf, d as SectionRegistry, n as PageRules, t as Page, u as ContentModel, v as ContentMigrator } from "./page-aWKWqoh4.js";
|
|
4
4
|
import { AstroIntegration } from "astro";
|
|
5
5
|
//#region src/store.d.ts
|
|
6
6
|
interface FileStoreOptions {
|
|
@@ -38,8 +38,7 @@ interface BearminionOptions extends ContentModel {
|
|
|
38
38
|
/**
|
|
39
39
|
* Which page operations the editor allows: `{ rename: false, delete: false }` for a site whose addresses must not
|
|
40
40
|
* change (they carry search ranking or are the target of redirects). Both default to true. A locked operation is
|
|
41
|
-
* refused by the API as well as hidden in the editor.
|
|
42
|
-
* because that moves the old home page to a new address.
|
|
41
|
+
* refused by the API as well as hidden in the editor.
|
|
43
42
|
*/
|
|
44
43
|
pages?: Partial<PageRules>;
|
|
45
44
|
/**
|
|
@@ -88,7 +87,8 @@ interface BearminionIntegration extends AstroIntegration {
|
|
|
88
87
|
/**
|
|
89
88
|
* Dev-only Astro integration. `astro build`, `astro preview`, and `astro sync`
|
|
90
89
|
* return before any plugin, route, or script is registered. `astro:server:setup`
|
|
91
|
-
* runs only while `astro dev` is serving.
|
|
90
|
+
* runs only while `astro dev` is serving. A build adds nothing to the site either; it only checks, once the pages
|
|
91
|
+
* are written, that every declared content type got its pages.
|
|
92
92
|
*/
|
|
93
93
|
export declare function bearminion(options: BearminionOptions): BearminionIntegration;
|
|
94
94
|
//#endregion
|
|
@@ -105,7 +105,14 @@ interface LoadOptions {
|
|
|
105
105
|
}
|
|
106
106
|
interface LoadedContent<TModel extends ContentModel = ContentModel> {
|
|
107
107
|
site: SiteOf<TModel['site']>;
|
|
108
|
+
/** Everything in `pages/`: the home page (`index`), the 404 page and the pages. */
|
|
108
109
|
pages: Page<SectionOf<TModel['sections']>>[];
|
|
110
|
+
/** The entries of each type the model declares, by type id, in file name order. Empty for a model with no types. */
|
|
111
|
+
entries: Record<string, Entry[]>;
|
|
112
|
+
/** The listing page document of each type that has one saved, by type id. */
|
|
113
|
+
listings: Record<string, ListingDocument>;
|
|
114
|
+
/** The document of each declared single that has been saved, by type id. */
|
|
115
|
+
singles: Record<string, Entry>;
|
|
109
116
|
}
|
|
110
117
|
/**
|
|
111
118
|
* Load `site.json` and `pages/*.json` from a content directory.
|
|
@@ -118,7 +125,9 @@ export declare function loadSite<TDefinition extends SiteDefinition>(contentDir:
|
|
|
118
125
|
* Validate every `contentDir/pages/*.json` file.
|
|
119
126
|
* Pages are returned in filename order. Slugs must be unique.
|
|
120
127
|
*/
|
|
121
|
-
export declare function loadPages<TRegistry extends SectionRegistry>(contentDir: string, registry: TRegistry, { migrator, tolerateOrphans }?: LoadOptions
|
|
128
|
+
export declare function loadPages<TRegistry extends SectionRegistry>(contentDir: string, registry: TRegistry, { migrator, tolerateOrphans, typeOf }?: LoadOptions & {
|
|
129
|
+
typeOf?: (slug: string) => ContentType;
|
|
130
|
+
}): Page<SectionOf<TRegistry>>[];
|
|
122
131
|
//#endregion
|
|
123
132
|
//#region src/hosted-integration.d.ts
|
|
124
133
|
interface HostedEditorIntegrationOptions {
|
|
@@ -129,6 +138,13 @@ interface HostedEditorIntegrationOptions {
|
|
|
129
138
|
module: string;
|
|
130
139
|
/** `required` (default): the whole deployment is the editor, so visitors are sent to sign in. See `createHostedMiddleware`. */
|
|
131
140
|
signIn?: 'required' | 'optional';
|
|
141
|
+
/**
|
|
142
|
+
* The theme's preview renderer, relative to the project root: the module that default-exports `defineThemePreview`.
|
|
143
|
+
* Default `src/lib/render-preview.ts` when the file exists. It is what lets the editor redraw a draft as it changes
|
|
144
|
+
* (a section just added, a layout switched, the header and footer). `false` leaves it out: such changes then show
|
|
145
|
+
* after Save and a reload.
|
|
146
|
+
*/
|
|
147
|
+
previewModule?: string | false;
|
|
132
148
|
}
|
|
133
149
|
/**
|
|
134
150
|
* Turns an Astro project into the hosted editor: server rendering, the sign-in middleware, and pages that draw from the
|
package/dist/astro.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as defaultTheme } from "./theme-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { A as ContentValidationError, C as loadThemePreview, c as siteRoutes, g as resolveCollections, k as ContentReadError, s as normalizePath, x as PreviewUnavailableError } from "./routing-BWuJlNud.js";
|
|
2
|
+
import { t as defaultTheme } from "./theme-DVMi1524.js";
|
|
3
|
+
import { i as createTolerantPageSchema, o as resolvePageRules, r as createPageSchema } from "./page-CcC5RRMj.js";
|
|
4
|
+
import { D as StoreKeyError, E as StoreError, i as LISTING_MIGRATION_TYPE, l as createEntrySchema, r as LISTING_FILE, u as createListingSchema, w as parseKey, y as resolveTypes } from "./content-types-POybRzMX.js";
|
|
5
|
+
import { a as DEFAULT_UPLOADS_DIR, i as DEFAULT_CONTENT_DIR, n as createMigrator, o as DEFAULT_VIDEOS_DIR, t as SCHEMA_VERSION_KEY } from "./migrate-Cm30puW8.js";
|
|
5
6
|
import { i as resolveMaxImageBytes, n as formatBytes, r as resolveConvert } from "./upload-rules-Cao9uY5K.js";
|
|
6
|
-
import { n as isLocalRequest, t as JSON_BODY_LIMIT } from "./request-guards-
|
|
7
|
+
import { n as isLocalRequest, t as JSON_BODY_LIMIT } from "./request-guards-6WtQV3-a.js";
|
|
7
8
|
import { i as resolveInside, n as isInside, r as resolveDir, t as asDirectory } from "./security-CBiOYdVE.js";
|
|
8
9
|
import { a as resolveFormsConfig, n as formFile, r as formsAreLive, t as createFormsMiddleware } from "./forms-dev-CzUHR7oS.js";
|
|
9
|
-
import { a as isHistoryId, c as imageBodyLimit, d as stableStringify, i as historyId, l as IMAGE_EXTENSION, n as missingImageSvg, o as COMMIT_MESSAGE_LIMIT, p as videoBodyLimit, r as handleEditorRequest, s as GitError, t as githubStore, u as uploadStem } from "./github-store-
|
|
10
|
+
import { a as isHistoryId, c as imageBodyLimit, d as stableStringify, i as historyId, l as IMAGE_EXTENSION, n as missingImageSvg, o as COMMIT_MESSAGE_LIMIT, p as videoBodyLimit, r as handleEditorRequest, s as GitError, t as githubStore, u as uploadStem } from "./github-store-4-Y4ERBF.js";
|
|
10
11
|
import { S as isAssetPath } from "./draft-store-DBEfw_Gq.js";
|
|
11
12
|
import { n as contentReloadPlugin, r as dropEarlyReloadAfterSave } from "./reload-BzVw721A.js";
|
|
12
13
|
import { i as syncSections, r as staleSectionsMessage } from "./sections-manifest-CO9QfJPG.js";
|
|
@@ -453,7 +454,9 @@ function idToIso(id) {
|
|
|
453
454
|
return `${id.slice(0, 4)}-${id.slice(4, 6)}-${id.slice(6, 8)}T${id.slice(9, 11)}:${id.slice(11, 13)}:${id.slice(13, 15)}.${id.slice(15, 18)}Z`;
|
|
454
455
|
}
|
|
455
456
|
function directory(context, scope, slug) {
|
|
456
|
-
|
|
457
|
+
if (scope === "site") return path.join(context.root, HISTORY_DIR, "site");
|
|
458
|
+
if (scope === "entry") return path.join(context.root, HISTORY_DIR, "types", ...slug.split("/"));
|
|
459
|
+
return path.join(context.root, HISTORY_DIR, "pages", slug);
|
|
457
460
|
}
|
|
458
461
|
async function ids(dir) {
|
|
459
462
|
try {
|
|
@@ -526,6 +529,7 @@ function resolveEditorContext(options, rootInput) {
|
|
|
526
529
|
const contentDir = resolveDir(root, options?.contentDir, DEFAULT_CONTENT_DIR);
|
|
527
530
|
const uploadsDir = resolveDir(root, options?.uploadsDir, DEFAULT_UPLOADS_DIR);
|
|
528
531
|
const videosDir = resolveDir(root, options?.videosDir, DEFAULT_VIDEOS_DIR);
|
|
532
|
+
const pageRules = resolvePageRules(options?.pages);
|
|
529
533
|
const context = {
|
|
530
534
|
root,
|
|
531
535
|
contentDir,
|
|
@@ -533,9 +537,10 @@ function resolveEditorContext(options, rootInput) {
|
|
|
533
537
|
videosDir,
|
|
534
538
|
maxVideoBytes: options?.maxVideoBytes ?? 52428800,
|
|
535
539
|
maxImageBytes: resolveMaxImageBytes(options?.maxImageBytes),
|
|
536
|
-
pageRules
|
|
540
|
+
pageRules,
|
|
537
541
|
imageConvert: resolveConvert(options?.imageConvert),
|
|
538
542
|
sections: options.sections,
|
|
543
|
+
types: resolveTypes(options, pageRules),
|
|
539
544
|
site: options.site,
|
|
540
545
|
theme: options.theme ?? defaultTheme,
|
|
541
546
|
store: options.store ?? createFileStore({
|
|
@@ -744,13 +749,190 @@ function stripTrailingSlash(pathname) {
|
|
|
744
749
|
return pathname;
|
|
745
750
|
}
|
|
746
751
|
//#endregion
|
|
752
|
+
//#region src/load.ts
|
|
753
|
+
/**
|
|
754
|
+
* Load `site.json` and `pages/*.json` from a content directory.
|
|
755
|
+
* Throws {@link ContentReadError} or {@link ContentValidationError} with the file path.
|
|
756
|
+
*/
|
|
757
|
+
function loadContent(contentDir, model, options = {}) {
|
|
758
|
+
const migrator = createMigrator(model);
|
|
759
|
+
const types = resolveTypes(model);
|
|
760
|
+
const tolerateOrphans = options.tolerateOrphans === true;
|
|
761
|
+
const entries = {};
|
|
762
|
+
const listings = {};
|
|
763
|
+
const singles = {};
|
|
764
|
+
for (const type of types.multi) {
|
|
765
|
+
if (type === types.pages) continue;
|
|
766
|
+
const dir = path.join(contentDir, type.dir);
|
|
767
|
+
const schema = createEntrySchema(model.sections, type, { tolerateOrphans });
|
|
768
|
+
const files = jsonFiles(dir, { missing: "empty" }).filter((name) => !name.startsWith("_"));
|
|
769
|
+
entries[type.id] = uniqueSlugs(dir, files, files.map((name) => parseFile(path.join(dir, name), schema, migrator, "page", type.id)));
|
|
770
|
+
const listingFile = path.join(dir, LISTING_FILE);
|
|
771
|
+
if (type.listing && fs.existsSync(listingFile)) listings[type.id] = parseFile(listingFile, createListingSchema(model.sections, { tolerateOrphans }), migrator, "page", LISTING_MIGRATION_TYPE);
|
|
772
|
+
}
|
|
773
|
+
for (const type of types.singles) {
|
|
774
|
+
const file = path.join(contentDir, type.key);
|
|
775
|
+
if (type.builtIn || !fs.existsSync(file)) continue;
|
|
776
|
+
singles[type.id] = parseFile(file, createEntrySchema(model.sections, type, { tolerateOrphans }), migrator, "page", type.id);
|
|
777
|
+
}
|
|
778
|
+
return {
|
|
779
|
+
site: loadSite(contentDir, model.site, { migrator }),
|
|
780
|
+
pages: loadPages(contentDir, model.sections, {
|
|
781
|
+
migrator,
|
|
782
|
+
...options,
|
|
783
|
+
typeOf: (slug) => slug === types.home.slug ? types.home : slug === types.notFound.slug ? types.notFound : types.pages
|
|
784
|
+
}),
|
|
785
|
+
entries,
|
|
786
|
+
listings,
|
|
787
|
+
singles
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
/** Names of the `.json` files directly inside `dir`, sorted. */
|
|
791
|
+
function jsonFiles(dir, options) {
|
|
792
|
+
let entries;
|
|
793
|
+
try {
|
|
794
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
795
|
+
} catch (error) {
|
|
796
|
+
if (isErrno(error) && error.code === "ENOENT") {
|
|
797
|
+
if (options.missing === "empty") return [];
|
|
798
|
+
throw new ContentReadError(dir, `Pages directory not found: ${dir}`);
|
|
799
|
+
}
|
|
800
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
801
|
+
throw new ContentReadError(dir, `Unable to read pages directory ${dir}: ${message}`);
|
|
802
|
+
}
|
|
803
|
+
return entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
804
|
+
}
|
|
805
|
+
function uniqueSlugs(dir, files, documents) {
|
|
806
|
+
const seen = /* @__PURE__ */ new Map();
|
|
807
|
+
for (const [index, document] of documents.entries()) {
|
|
808
|
+
const filePath = path.join(dir, files[index] ?? "");
|
|
809
|
+
const previous = seen.get(document.slug);
|
|
810
|
+
if (previous !== void 0) throw new ContentValidationError(filePath, [{
|
|
811
|
+
path: ["slug"],
|
|
812
|
+
message: `Duplicate slug "${document.slug}" (also defined in ${previous})`
|
|
813
|
+
}]);
|
|
814
|
+
seen.set(document.slug, filePath);
|
|
815
|
+
}
|
|
816
|
+
return documents;
|
|
817
|
+
}
|
|
818
|
+
/** Validate and return `contentDir/site.json`. */
|
|
819
|
+
function loadSite(contentDir, site, { migrator = createMigrator() } = {}) {
|
|
820
|
+
return parseFile(path.join(contentDir, "site.json"), site.schema, migrator, "site");
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Validate every `contentDir/pages/*.json` file.
|
|
824
|
+
* Pages are returned in filename order. Slugs must be unique.
|
|
825
|
+
*/
|
|
826
|
+
function loadPages(contentDir, registry, { migrator = createMigrator(), tolerateOrphans = false, typeOf } = {}) {
|
|
827
|
+
const pagesDir = path.join(contentDir, "pages");
|
|
828
|
+
const files = jsonFiles(pagesDir, { missing: "throw" });
|
|
829
|
+
const pageSchema = tolerateOrphans ? createTolerantPageSchema(registry) : createPageSchema(registry);
|
|
830
|
+
return uniqueSlugs(pagesDir, files, files.map((name) => {
|
|
831
|
+
const filePath = path.join(pagesDir, name);
|
|
832
|
+
if (!typeOf) return parseFile(filePath, pageSchema, migrator, "page");
|
|
833
|
+
const raw = readJsonFile(filePath);
|
|
834
|
+
const type = typeOf(typeof raw === "object" && raw !== null && "slug" in raw && typeof raw.slug === "string" ? raw.slug : "");
|
|
835
|
+
return parseFile(filePath, createEntrySchema(registry, type, { tolerateOrphans }), migrator, "page", type.id);
|
|
836
|
+
}));
|
|
837
|
+
}
|
|
838
|
+
function parseFile(filePath, schema, migrator, kind, type) {
|
|
839
|
+
const upgraded = migrator.upgrade(readJsonFile(filePath), kind, type);
|
|
840
|
+
if (!upgraded.ok) throw new ContentValidationError(filePath, [{
|
|
841
|
+
path: [SCHEMA_VERSION_KEY],
|
|
842
|
+
message: upgraded.message
|
|
843
|
+
}]);
|
|
844
|
+
const result = schema.safeParse(upgraded.value);
|
|
845
|
+
if (!result.success) throw new ContentValidationError(filePath, toIssues(result.error.issues));
|
|
846
|
+
return result.data;
|
|
847
|
+
}
|
|
848
|
+
function readJsonFile(filePath) {
|
|
849
|
+
let raw;
|
|
850
|
+
try {
|
|
851
|
+
raw = fs.readFileSync(filePath, "utf8");
|
|
852
|
+
} catch (error) {
|
|
853
|
+
if (isErrno(error) && error.code === "ENOENT") throw new ContentReadError(filePath, `Content file not found: ${filePath}`);
|
|
854
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
855
|
+
throw new ContentReadError(filePath, `Unable to read ${filePath}: ${message}`);
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
return JSON.parse(raw);
|
|
859
|
+
} catch (error) {
|
|
860
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
861
|
+
throw new ContentReadError(filePath, `Invalid JSON in ${filePath}: ${message}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function toIssues(issues) {
|
|
865
|
+
return issues.map((issue) => ({
|
|
866
|
+
path: [...issue.path],
|
|
867
|
+
message: issue.message
|
|
868
|
+
}));
|
|
869
|
+
}
|
|
870
|
+
function isErrno(error) {
|
|
871
|
+
return error instanceof Error && "code" in error;
|
|
872
|
+
}
|
|
873
|
+
//#endregion
|
|
874
|
+
//#region src/route-check.ts
|
|
875
|
+
const TYPES_UPGRADE_DOCS = "https://docs.bearminion.com/content-types/#upgrading-from-120";
|
|
876
|
+
const ROUTE_FILE = "src/pages/[...slug].astro";
|
|
877
|
+
/** True when the model declares something beyond the built-in home page, 404 page and pages. */
|
|
878
|
+
function declaresTypes(model) {
|
|
879
|
+
const types = resolveTypes(model);
|
|
880
|
+
return types.multi.length > 1 || types.singles.some((type) => !type.builtIn);
|
|
881
|
+
}
|
|
882
|
+
/** `blog/first/`, `/blog/first/index.html` and `blog/first.html` are all the address `/blog/first`. */
|
|
883
|
+
function emittedPath(pathname) {
|
|
884
|
+
const trimmed = pathname.replace(/(^|\/)index\.html$/, "").replace(/\.html$/, "");
|
|
885
|
+
return normalizePath(`/${trimmed.replace(/^\/+/, "")}`);
|
|
886
|
+
}
|
|
887
|
+
/**
|
|
888
|
+
* The addresses of declared types, singles and listings that the build should have written and did not. `emitted` is
|
|
889
|
+
* the `pathname` of every page Astro built. Empty for a model that declares nothing of its own.
|
|
890
|
+
*/
|
|
891
|
+
function missingRoutes(model, contentDir, emitted) {
|
|
892
|
+
if (!declaresTypes(model)) return [];
|
|
893
|
+
const types = resolveTypes(model);
|
|
894
|
+
const builtIn = /* @__PURE__ */ new Set([
|
|
895
|
+
types.home.id,
|
|
896
|
+
types.notFound.id,
|
|
897
|
+
types.pages.id
|
|
898
|
+
]);
|
|
899
|
+
const content = loadContent(contentDir, model);
|
|
900
|
+
const lang = content.site.lang;
|
|
901
|
+
const built = new Set(emitted.map(emittedPath));
|
|
902
|
+
return siteRoutes(model, content, typeof lang === "string" ? { locale: lang } : {}).filter((route) => !builtIn.has(route.type)).map((route) => route.path).filter((routePath) => !built.has(routePath));
|
|
903
|
+
}
|
|
904
|
+
function missingRoutesMessage(missing) {
|
|
905
|
+
return `The content model declares content types, but the build wrote no page for: ${missing.slice(0, 10).join(", ")}${missing.length > 10 ? ` and ${missing.length - 10} more` : ""}. ${ROUTE_FILE} is the starter's file from before content types and knows only pages. Update the site's files with \`npx bearminion add type --files-only\`, then build again. ${TYPES_UPGRADE_DOCS}`;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Why the route file of the project at `root` cannot serve declared types, or undefined when it can, when the model
|
|
909
|
+
* declares none, or when the site has its own routes. For `astro dev`, where pages are drawn one request at a time
|
|
910
|
+
* and there is no list of built pages to compare.
|
|
911
|
+
*/
|
|
912
|
+
function staleRouteFile(model, root) {
|
|
913
|
+
if (!declaresTypes(model)) return void 0;
|
|
914
|
+
const file = path.join(root, ROUTE_FILE);
|
|
915
|
+
let source;
|
|
916
|
+
try {
|
|
917
|
+
if (!existsSync(file)) return void 0;
|
|
918
|
+
source = readFileSync(file, "utf8");
|
|
919
|
+
} catch {
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (source.includes("getRoute")) return void 0;
|
|
923
|
+
return `The content model declares content types, but ${ROUTE_FILE} is the starter's file from before content types: entries, singles and listing pages will answer 404. Update the site's files with \`npx bearminion add type --files-only\`. ${TYPES_UPGRADE_DOCS}`;
|
|
924
|
+
}
|
|
925
|
+
//#endregion
|
|
747
926
|
//#region src/integration.ts
|
|
748
927
|
/**
|
|
749
928
|
* Dev-only Astro integration. `astro build`, `astro preview`, and `astro sync`
|
|
750
929
|
* return before any plugin, route, or script is registered. `astro:server:setup`
|
|
751
|
-
* runs only while `astro dev` is serving.
|
|
930
|
+
* runs only while `astro dev` is serving. A build adds nothing to the site either; it only checks, once the pages
|
|
931
|
+
* are written, that every declared content type got its pages.
|
|
752
932
|
*/
|
|
753
933
|
function bearminion(options) {
|
|
934
|
+
/** Set once the config is final: the project root, and whether every page is written at build time. */
|
|
935
|
+
let project;
|
|
754
936
|
return {
|
|
755
937
|
name: "bearminion",
|
|
756
938
|
hooks: {
|
|
@@ -763,6 +945,8 @@ function bearminion(options) {
|
|
|
763
945
|
}
|
|
764
946
|
}
|
|
765
947
|
if (command !== "dev") return;
|
|
948
|
+
const stale = staleRouteFile(options, rootPath(config.root));
|
|
949
|
+
if (stale) logger.warn(stale);
|
|
766
950
|
const context = resolveEditorContext(options, rootInput(config.root));
|
|
767
951
|
updateConfig({ vite: {
|
|
768
952
|
server: { watch: { ignored: [
|
|
@@ -774,6 +958,17 @@ function bearminion(options) {
|
|
|
774
958
|
} });
|
|
775
959
|
injectScript("page", "import \"virtual:bearminion-editor\"");
|
|
776
960
|
},
|
|
961
|
+
"astro:config:done"({ config }) {
|
|
962
|
+
project = {
|
|
963
|
+
root: rootPath(config.root),
|
|
964
|
+
static: config.output === "static"
|
|
965
|
+
};
|
|
966
|
+
},
|
|
967
|
+
"astro:build:done"({ pages }) {
|
|
968
|
+
if (!project?.static) return;
|
|
969
|
+
const missing = missingRoutes(options, resolveDir(project.root, options.contentDir, DEFAULT_CONTENT_DIR), pages.map((page) => page.pathname));
|
|
970
|
+
if (missing.length > 0) throw new Error(missingRoutesMessage(missing));
|
|
971
|
+
},
|
|
777
972
|
"astro:server:setup"({ server, logger }) {
|
|
778
973
|
const context = resolveEditorContext(options, server.config.root);
|
|
779
974
|
const previewModule = options.previewModule ?? "/src/lib/render-preview.ts";
|
|
@@ -860,90 +1055,6 @@ function rootInput(root) {
|
|
|
860
1055
|
return process.cwd();
|
|
861
1056
|
}
|
|
862
1057
|
//#endregion
|
|
863
|
-
//#region src/load.ts
|
|
864
|
-
/**
|
|
865
|
-
* Load `site.json` and `pages/*.json` from a content directory.
|
|
866
|
-
* Throws {@link ContentReadError} or {@link ContentValidationError} with the file path.
|
|
867
|
-
*/
|
|
868
|
-
function loadContent(contentDir, model, options = {}) {
|
|
869
|
-
const migrator = createMigrator(model);
|
|
870
|
-
return {
|
|
871
|
-
site: loadSite(contentDir, model.site, { migrator }),
|
|
872
|
-
pages: loadPages(contentDir, model.sections, {
|
|
873
|
-
migrator,
|
|
874
|
-
...options
|
|
875
|
-
})
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
/** Validate and return `contentDir/site.json`. */
|
|
879
|
-
function loadSite(contentDir, site, { migrator = createMigrator() } = {}) {
|
|
880
|
-
return parseFile(path.join(contentDir, "site.json"), site.schema, migrator, "site");
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Validate every `contentDir/pages/*.json` file.
|
|
884
|
-
* Pages are returned in filename order. Slugs must be unique.
|
|
885
|
-
*/
|
|
886
|
-
function loadPages(contentDir, registry, { migrator = createMigrator(), tolerateOrphans = false } = {}) {
|
|
887
|
-
const pagesDir = path.join(contentDir, "pages");
|
|
888
|
-
let entries;
|
|
889
|
-
try {
|
|
890
|
-
entries = fs.readdirSync(pagesDir, { withFileTypes: true });
|
|
891
|
-
} catch (error) {
|
|
892
|
-
if (isErrno(error) && error.code === "ENOENT") throw new ContentReadError(pagesDir, `Pages directory not found: ${pagesDir}`);
|
|
893
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
894
|
-
throw new ContentReadError(pagesDir, `Unable to read pages directory ${pagesDir}: ${message}`);
|
|
895
|
-
}
|
|
896
|
-
const files = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
897
|
-
const pageSchema = tolerateOrphans ? createTolerantPageSchema(registry) : createPageSchema(registry);
|
|
898
|
-
const pages = files.map((name) => parseFile(path.join(pagesDir, name), pageSchema, migrator, "page"));
|
|
899
|
-
const seen = /* @__PURE__ */ new Map();
|
|
900
|
-
for (const [index, page] of pages.entries()) {
|
|
901
|
-
const filePath = path.join(pagesDir, files[index] ?? "");
|
|
902
|
-
const previous = seen.get(page.slug);
|
|
903
|
-
if (previous !== void 0) throw new ContentValidationError(filePath, [{
|
|
904
|
-
path: ["slug"],
|
|
905
|
-
message: `Duplicate slug "${page.slug}" (also defined in ${previous})`
|
|
906
|
-
}]);
|
|
907
|
-
seen.set(page.slug, filePath);
|
|
908
|
-
}
|
|
909
|
-
return pages;
|
|
910
|
-
}
|
|
911
|
-
function parseFile(filePath, schema, migrator, kind) {
|
|
912
|
-
const upgraded = migrator.upgrade(readJsonFile(filePath), kind);
|
|
913
|
-
if (!upgraded.ok) throw new ContentValidationError(filePath, [{
|
|
914
|
-
path: [SCHEMA_VERSION_KEY],
|
|
915
|
-
message: upgraded.message
|
|
916
|
-
}]);
|
|
917
|
-
const result = schema.safeParse(upgraded.value);
|
|
918
|
-
if (!result.success) throw new ContentValidationError(filePath, toIssues(result.error.issues));
|
|
919
|
-
return result.data;
|
|
920
|
-
}
|
|
921
|
-
function readJsonFile(filePath) {
|
|
922
|
-
let raw;
|
|
923
|
-
try {
|
|
924
|
-
raw = fs.readFileSync(filePath, "utf8");
|
|
925
|
-
} catch (error) {
|
|
926
|
-
if (isErrno(error) && error.code === "ENOENT") throw new ContentReadError(filePath, `Content file not found: ${filePath}`);
|
|
927
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
928
|
-
throw new ContentReadError(filePath, `Unable to read ${filePath}: ${message}`);
|
|
929
|
-
}
|
|
930
|
-
try {
|
|
931
|
-
return JSON.parse(raw);
|
|
932
|
-
} catch (error) {
|
|
933
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
934
|
-
throw new ContentReadError(filePath, `Invalid JSON in ${filePath}: ${message}`);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
function toIssues(issues) {
|
|
938
|
-
return issues.map((issue) => ({
|
|
939
|
-
path: [...issue.path],
|
|
940
|
-
message: issue.message
|
|
941
|
-
}));
|
|
942
|
-
}
|
|
943
|
-
function isErrno(error) {
|
|
944
|
-
return error instanceof Error && "code" in error;
|
|
945
|
-
}
|
|
946
|
-
//#endregion
|
|
947
1058
|
//#region src/hosted-template-check.ts
|
|
948
1059
|
const TEMPLATE_DOCS = "https://docs.bearminion.com/integration/#keeping-the-sites-files-current";
|
|
949
1060
|
/** Reads a file, or `undefined` when it is not there. */
|
|
@@ -969,6 +1080,15 @@ function staleTemplateProblems(root) {
|
|
|
969
1080
|
//#region src/hosted-integration.ts
|
|
970
1081
|
const VIRTUAL_ID = "virtual:bearminion/editor";
|
|
971
1082
|
const RESOLVED_ID = `\0${VIRTUAL_ID}`;
|
|
1083
|
+
const DEFAULT_PREVIEW_MODULE = "src/lib/render-preview.ts";
|
|
1084
|
+
/** The absolute path of the preview module, or `null` when the site has none. A module named by hand must exist. */
|
|
1085
|
+
function resolvePreviewModule(root, option) {
|
|
1086
|
+
if (option === false) return null;
|
|
1087
|
+
const file = path.resolve(root, option ?? DEFAULT_PREVIEW_MODULE);
|
|
1088
|
+
if (fs.existsSync(file)) return file;
|
|
1089
|
+
if (option === void 0) return null;
|
|
1090
|
+
throw new Error(`bearminionHostedEditor: previewModule ${JSON.stringify(option)} does not exist (looked for ${file}).`);
|
|
1091
|
+
}
|
|
972
1092
|
/**
|
|
973
1093
|
* Turns an Astro project into the hosted editor: server rendering, the sign-in middleware, and pages that draw from the
|
|
974
1094
|
* repository's current content (`Astro.locals.bearminion`). Add it to the editor deployment's build only: the public
|
|
@@ -984,6 +1104,8 @@ function bearminionHostedEditor(options) {
|
|
|
984
1104
|
if (!config.adapter) throw new Error("bearminionHostedEditor renders on a server, so the project needs an adapter (for example @astrojs/cloudflare or @astrojs/vercel). Add it to the editor build only.");
|
|
985
1105
|
const root = fileURLToPath(config.root);
|
|
986
1106
|
const editorModule = path.resolve(root, options.module);
|
|
1107
|
+
const previewModule = resolvePreviewModule(root, options.previewModule);
|
|
1108
|
+
if (!previewModule && options.previewModule === void 0) logger.warn(`No ${DEFAULT_PREVIEW_MODULE}, so the editor has no live preview: a section just added shows after Save and a reload. Name the module with \`previewModule\`, or pass \`previewModule: false\` to silence this.`);
|
|
987
1109
|
const stale = staleTemplateProblems(root);
|
|
988
1110
|
if (stale.length > 0) logger.warn(`This site's files are older than the editor needs:\n${stale.map((problem) => ` - ${problem}`).join("\n")}\nHow to bring them up to date: ${TEMPLATE_DOCS}`);
|
|
989
1111
|
updateConfig({
|
|
@@ -994,7 +1116,12 @@ function bearminionHostedEditor(options) {
|
|
|
994
1116
|
plugins: [{
|
|
995
1117
|
name: "bearminion:hosted-editor-module",
|
|
996
1118
|
resolveId: (id) => id === VIRTUAL_ID ? RESOLVED_ID : null,
|
|
997
|
-
load: (id) => id === RESOLVED_ID ?
|
|
1119
|
+
load: (id) => id === RESOLVED_ID ? [
|
|
1120
|
+
`export { default as editor } from ${JSON.stringify(editorModule)}`,
|
|
1121
|
+
`export const signIn = ${JSON.stringify(signIn)}`,
|
|
1122
|
+
previewModule ? `export const preview = () => import(${JSON.stringify(previewModule)}).then((module) => module.default)` : "export const preview = undefined",
|
|
1123
|
+
""
|
|
1124
|
+
].join("\n") : null
|
|
998
1125
|
}]
|
|
999
1126
|
}
|
|
1000
1127
|
});
|