@cossackframework/cms 0.0.0-stage → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/agent-docs.json +259 -0
- package/app/README.md +78 -0
- package/app/cossack-recipe.json +43 -0
- package/app/src/auth-bot-check.ts +32 -0
- package/app/src/auth-bot-token.ts +11 -0
- package/app/src/auth-input.ts +35 -0
- package/app/src/auth-options.ts +18 -0
- package/app/src/auth-providers.ts +16 -0
- package/app/src/auth.ts +1082 -0
- package/app/src/brand.ts +68 -0
- package/app/src/cms/ai.ts +54 -0
- package/app/src/cms/analytics.ts +33 -0
- package/app/src/cms/block-errors.ts +55 -0
- package/app/src/cms/block-inserter.ts +111 -0
- package/app/src/cms/block-panel.ts +68 -0
- package/app/src/cms/block-rows.ts +44 -0
- package/app/src/cms/block-tree.ts +585 -0
- package/app/src/cms/blocks.css +708 -0
- package/app/src/cms/builder.ts +126 -0
- package/app/src/cms/cache.ts +44 -0
- package/app/src/cms/carousel.client.ts +52 -0
- package/app/src/cms/collab/presence.ts +69 -0
- package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
- package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
- package/app/src/cms/collab/room.ts +881 -0
- package/app/src/cms/compare.client.ts +47 -0
- package/app/src/cms/condition-control.ts +109 -0
- package/app/src/cms/content-api.ts +143 -0
- package/app/src/cms/content.ts +524 -0
- package/app/src/cms/countdown.client.ts +37 -0
- package/app/src/cms/editor-layout-editor.ts +260 -0
- package/app/src/cms/editor-layout-view.ts +37 -0
- package/app/src/cms/editor.ts +381 -0
- package/app/src/cms/entry.ts +26 -0
- package/app/src/cms/feeds.ts +145 -0
- package/app/src/cms/field-controls.ts +222 -0
- package/app/src/cms/field-group-editor.ts +105 -0
- package/app/src/cms/field-group-view.ts +211 -0
- package/app/src/cms/form-view.ts +203 -0
- package/app/src/cms/form.client.ts +203 -0
- package/app/src/cms/guards.ts +27 -0
- package/app/src/cms/handoff.ts +202 -0
- package/app/src/cms/headings.ts +51 -0
- package/app/src/cms/icons.ts +80 -0
- package/app/src/cms/import.client.ts +16 -0
- package/app/src/cms/index.ts +191 -0
- package/app/src/cms/lightbox.client.ts +109 -0
- package/app/src/cms/machine.ts +118 -0
- package/app/src/cms/maintenance.ts +97 -0
- package/app/src/cms/manage.ts +1236 -0
- package/app/src/cms/mcp-tools.ts +388 -0
- package/app/src/cms/mcp.ts +242 -0
- package/app/src/cms/media-chooser.ts +123 -0
- package/app/src/cms/media-usage.ts +57 -0
- package/app/src/cms/middleware.ts +199 -0
- package/app/src/cms/middlewares.ts +13 -0
- package/app/src/cms/network-ui.ts +36 -0
- package/app/src/cms/network-view.ts +38 -0
- package/app/src/cms/notes-announce.ts +65 -0
- package/app/src/cms/notes-rail.ts +207 -0
- package/app/src/cms/notification-rules.ts +66 -0
- package/app/src/cms/recovery.ts +82 -0
- package/app/src/cms/replace.ts +63 -0
- package/app/src/cms/reserved-paths.ts +19 -0
- package/app/src/cms/rich-text-field.ts +325 -0
- package/app/src/cms/rich-text-schema.ts +91 -0
- package/app/src/cms/rich-text.client.ts +255 -0
- package/app/src/cms/search.client.ts +116 -0
- package/app/src/cms/seo-head.ts +78 -0
- package/app/src/cms/seo.ts +241 -0
- package/app/src/cms/settings-draft.ts +218 -0
- package/app/src/cms/settings-file.ts +127 -0
- package/app/src/cms/settings-form.ts +180 -0
- package/app/src/cms/settings-languages.ts +125 -0
- package/app/src/cms/settings-nav.ts +102 -0
- package/app/src/cms/settings-network.ts +151 -0
- package/app/src/cms/settings-permalinks.ts +114 -0
- package/app/src/cms/settings-scroll.ts +10 -0
- package/app/src/cms/settings-search.ts +77 -0
- package/app/src/cms/settings-section.ts +38 -0
- package/app/src/cms/share.client.ts +27 -0
- package/app/src/cms/site-editing.ts +219 -0
- package/app/src/cms/site-editor.client.ts +1008 -0
- package/app/src/cms/site-editor.ts +99 -0
- package/app/src/cms/site-export.ts +60 -0
- package/app/src/cms/site-forms.ts +143 -0
- package/app/src/cms/site-import.ts +28 -0
- package/app/src/cms/site-session.ts +36 -0
- package/app/src/cms/site-taskbar.ts +77 -0
- package/app/src/cms/site-view.ts +1014 -0
- package/app/src/cms/site.ts +1322 -0
- package/app/src/cms/sitemaps.ts +131 -0
- package/app/src/cms/stat.client.ts +56 -0
- package/app/src/cms/style-controls.ts +252 -0
- package/app/src/cms/tabs.client.ts +36 -0
- package/app/src/cms/taskbar.ts +134 -0
- package/app/src/cms/term-icons.ts +10 -0
- package/app/src/cms/traffic.ts +26 -0
- package/app/src/cms/ui.ts +170 -0
- package/app/src/cms/updates.ts +124 -0
- package/app/src/cms/uploads.ts +26 -0
- package/app/src/cms/worker.ts +13 -0
- package/app/src/config/auth.ts +30 -0
- package/app/src/config/cms.ts +18 -0
- package/app/src/dashboard/access.ts +344 -0
- package/app/src/dashboard/agent-icons.ts +44 -0
- package/app/src/dashboard/app-passwords.ts +74 -0
- package/app/src/dashboard/avatar-field.ts +58 -0
- package/app/src/dashboard/bulk.ts +53 -0
- package/app/src/dashboard/head.ts +29 -0
- package/app/src/dashboard/icons.ts +15 -0
- package/app/src/dashboard/list-table.ts +120 -0
- package/app/src/dashboard/modules/roles.ts +15 -0
- package/app/src/dashboard/modules/sessions.ts +15 -0
- package/app/src/dashboard/modules/settings.ts +15 -0
- package/app/src/dashboard/modules/users.ts +18 -0
- package/app/src/dashboard/page.ts +67 -0
- package/app/src/dashboard/registry.ts +13 -0
- package/app/src/dashboard/session-list.ts +98 -0
- package/app/src/dashboard/tabs.ts +26 -0
- package/app/src/dashboard/time-ago.ts +16 -0
- package/app/src/dashboard/types.ts +40 -0
- package/app/src/dashboard/user-sections.ts +172 -0
- package/app/src/lib/permissions.ts +84 -0
- package/app/src/middlewares/auth.ts +117 -0
- package/app/src/pages/(site)/[...path]/index.ts +609 -0
- package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
- package/app/src/pages/(site)/feed/index.ts +12 -0
- package/app/src/pages/(site)/index.ts +11 -0
- package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
- package/app/src/pages/(site)/layout.ts +219 -0
- package/app/src/pages/(site)/llms.txt/index.ts +23 -0
- package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
- package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
- package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
- package/app/src/pages/(site)/robots.txt/index.ts +29 -0
- package/app/src/pages/(site)/search/index.ts +36 -0
- package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
- package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
- package/app/src/pages/api/auth/session.ts +48 -0
- package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
- package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
- package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
- package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
- package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
- package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
- package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
- package/app/src/pages/api/cms/cache/purge.ts +6 -0
- package/app/src/pages/api/cms/collections/index.ts +6 -0
- package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
- package/app/src/pages/api/cms/comments/[id].ts +9 -0
- package/app/src/pages/api/cms/comments/index.ts +126 -0
- package/app/src/pages/api/cms/comments/queue.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
- package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
- package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
- package/app/src/pages/api/cms/export/[collection].ts +37 -0
- package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
- package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
- package/app/src/pages/api/cms/import/[collection].ts +23 -0
- package/app/src/pages/api/cms/mcp.ts +29 -0
- package/app/src/pages/api/cms/me/index.ts +6 -0
- package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
- package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
- package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
- package/app/src/pages/api/cms/media/[id].ts +6 -0
- package/app/src/pages/api/cms/media.ts +26 -0
- package/app/src/pages/api/cms/menus/[location].ts +14 -0
- package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
- package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
- package/app/src/pages/api/cms/network/sites/index.ts +14 -0
- package/app/src/pages/api/cms/notes/[id].ts +13 -0
- package/app/src/pages/api/cms/notes/index.ts +6 -0
- package/app/src/pages/api/cms/payments/webhook.ts +28 -0
- package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
- package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
- package/app/src/pages/api/cms/plugins/index.ts +6 -0
- package/app/src/pages/api/cms/recovery.ts +29 -0
- package/app/src/pages/api/cms/redirects/index.ts +9 -0
- package/app/src/pages/api/cms/roles/index.ts +6 -0
- package/app/src/pages/api/cms/schema/[collection].ts +13 -0
- package/app/src/pages/api/cms/search.ts +16 -0
- package/app/src/pages/api/cms/settings/[group].ts +9 -0
- package/app/src/pages/api/cms/settings/index.ts +9 -0
- package/app/src/pages/api/cms/site-export.ts +34 -0
- package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
- package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
- package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
- package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
- package/app/src/pages/api/cms/uploads/index.ts +26 -0
- package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
- package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
- package/app/src/pages/api/cms/users/index.ts +12 -0
- package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
- package/app/src/pages/api/cms/webhooks/index.ts +9 -0
- package/app/src/pages/auth/[provider]/callback.ts +11 -0
- package/app/src/pages/auth/[provider]/redirect.ts +9 -0
- package/app/src/pages/auth/forgot-password/index.ts +75 -0
- package/app/src/pages/auth/layout.ts +32 -0
- package/app/src/pages/auth/login/index.ts +198 -0
- package/app/src/pages/auth/magic/index.ts +68 -0
- package/app/src/pages/auth/register/index.ts +117 -0
- package/app/src/pages/auth/reset-password/index.ts +65 -0
- package/app/src/pages/auth/setup/index.ts +194 -0
- package/app/src/pages/auth/two-factor/index.ts +67 -0
- package/app/src/pages/auth/verify/index.ts +62 -0
- package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
- package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
- package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
- package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
- package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
- package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
- package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
- package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
- package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
- package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
- package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
- package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
- package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
- package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
- package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
- package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
- package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
- package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
- package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
- package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
- package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
- package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
- package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
- package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
- package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
- package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
- package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
- package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
- package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
- package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
- package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
- package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
- package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
- package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
- package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
- package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
- package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
- package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
- package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
- package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
- package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
- package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
- package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
- package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
- package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
- package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
- package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
- package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +182 -0
- package/app/src/pages/dashboard/index.ts +214 -0
- package/app/src/pages/dashboard/layout.ts +320 -0
- package/app/src/pages/dashboard/profile/index.ts +211 -0
- package/app/src/pages/dashboard/profile/security/index.ts +255 -0
- package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
- package/app/src/pages/dashboard/roles/index.ts +134 -0
- package/app/src/pages/dashboard/roles/new/index.ts +95 -0
- package/app/src/pages/dashboard/sessions/index.ts +105 -0
- package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
- package/app/src/pages/dashboard/users/index.ts +299 -0
- package/app/src/pages/dashboard/users/new/index.ts +123 -0
- package/app/src/passkeys.client.ts +18 -0
- package/app/src/plugins/default-theme/assets/cover.svg +31 -0
- package/app/src/plugins/default-theme/assets/logo.svg +8 -0
- package/app/src/plugins/default-theme/parts/comments.ts +66 -0
- package/app/src/plugins/default-theme/parts/list.ts +38 -0
- package/app/src/plugins/default-theme/parts/media.ts +15 -0
- package/app/src/plugins/default-theme/parts/options.ts +45 -0
- package/app/src/plugins/default-theme/plugin.json +275 -0
- package/app/src/plugins/default-theme/templates/archive.ts +14 -0
- package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
- package/app/src/plugins/default-theme/templates/entry.ts +27 -0
- package/app/src/plugins/default-theme/templates/home.ts +8 -0
- package/app/src/plugins/default-theme/templates/layout.ts +40 -0
- package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
- package/app/src/plugins/default-theme/templates/search.ts +32 -0
- package/app/src/services/rbac.ts +65 -0
- package/app/src/services/roles.ts +89 -0
- package/app/src/services/users.ts +173 -0
- package/package.json +123 -3
- package/src/automations.ts +95 -0
- package/src/bindings.ts +138 -0
- package/src/block-references.ts +239 -0
- package/src/block-shape.ts +155 -0
- package/src/blocks.ts +1157 -0
- package/src/cache.ts +54 -0
- package/src/checks.ts +198 -0
- package/src/cloudflare-workers.d.ts +13 -0
- package/src/cloudflare.ts +61 -0
- package/src/collab.ts +372 -0
- package/src/collections.ts +421 -0
- package/src/comments.ts +46 -0
- package/src/cron.ts +95 -0
- package/src/dashboard-menu.ts +105 -0
- package/src/diff.ts +113 -0
- package/src/editor-layout.ts +316 -0
- package/src/errors.ts +50 -0
- package/src/field-groups.ts +498 -0
- package/src/fields.ts +411 -0
- package/src/form-builder.ts +1053 -0
- package/src/forms.ts +109 -0
- package/src/highlight.ts +134 -0
- package/src/hooks.ts +510 -0
- package/src/icon-catalog.ts +55 -0
- package/src/icons.ts +128 -0
- package/src/images.ts +149 -0
- package/src/index.ts +100 -0
- package/src/isolate-core.ts +245 -0
- package/src/isolate.ts +19 -0
- package/src/isolation.ts +69 -0
- package/src/mail.ts +182 -0
- package/src/manifest.ts +476 -0
- package/src/media.ts +193 -0
- package/src/menus.ts +287 -0
- package/src/module.ts +32 -0
- package/src/modules/content.ts +64 -0
- package/src/modules/forms.ts +35 -0
- package/src/node.ts +66 -0
- package/src/notes.ts +237 -0
- package/src/permissions.ts +139 -0
- package/src/plugin-settings.ts +114 -0
- package/src/records.ts +56 -0
- package/src/redirects.ts +59 -0
- package/src/resource.ts +245 -0
- package/src/richtext.ts +402 -0
- package/src/schema-json.ts +112 -0
- package/src/search.ts +89 -0
- package/src/seo.ts +477 -0
- package/src/server/accounts.ts +418 -0
- package/src/server/ai.ts +33 -0
- package/src/server/api-tokens.ts +91 -0
- package/src/server/areas.ts +116 -0
- package/src/server/audit.ts +94 -0
- package/src/server/auth.ts +89 -0
- package/src/server/automations.ts +190 -0
- package/src/server/autosaves.ts +69 -0
- package/src/server/brand-icons.ts +50 -0
- package/src/server/brands.ts +86 -0
- package/src/server/budget.ts +97 -0
- package/src/server/cache.ts +104 -0
- package/src/server/capabilities.ts +333 -0
- package/src/server/cloudflare.ts +92 -0
- package/src/server/comments.ts +237 -0
- package/src/server/drafts.ts +176 -0
- package/src/server/field-groups.ts +88 -0
- package/src/server/files.ts +780 -0
- package/src/server/forms.ts +726 -0
- package/src/server/handoffs.ts +107 -0
- package/src/server/host-schema.ts +312 -0
- package/src/server/host.ts +2892 -0
- package/src/server/images.ts +34 -0
- package/src/server/index.ts +59 -0
- package/src/server/indexnow.ts +91 -0
- package/src/server/isolation.ts +183 -0
- package/src/server/locked.ts +45 -0
- package/src/server/mail.ts +93 -0
- package/src/server/markdown.ts +24 -0
- package/src/server/menus.ts +286 -0
- package/src/server/network-policy.ts +60 -0
- package/src/server/network.ts +665 -0
- package/src/server/notes.ts +275 -0
- package/src/server/outbox.ts +213 -0
- package/src/server/path-moves.ts +33 -0
- package/src/server/payments.ts +59 -0
- package/src/server/previews.ts +62 -0
- package/src/server/purge.ts +140 -0
- package/src/server/reconcile.ts +38 -0
- package/src/server/redirects.ts +183 -0
- package/src/server/repository.ts +1107 -0
- package/src/server/schedules.ts +105 -0
- package/src/server/schema.ts +562 -0
- package/src/server/security.ts +391 -0
- package/src/server/seed.ts +52 -0
- package/src/server/shared-fields.ts +34 -0
- package/src/server/site-export.ts +151 -0
- package/src/server/site-import.ts +482 -0
- package/src/server/site-search.ts +289 -0
- package/src/server/site-settings.ts +286 -0
- package/src/server/sites.ts +243 -0
- package/src/server/stores.ts +314 -0
- package/src/server/stripe.ts +173 -0
- package/src/server/taxonomies.ts +415 -0
- package/src/server/tokens.ts +25 -0
- package/src/server/traffic.ts +118 -0
- package/src/server/users.ts +653 -0
- package/src/server/webhooks.ts +245 -0
- package/src/settings-controls.ts +54 -0
- package/src/settings-document.ts +111 -0
- package/src/settings.ts +426 -0
- package/src/storage/cloudflare.ts +94 -0
- package/src/storage/index.ts +30 -0
- package/src/storage/node.ts +114 -0
- package/src/taxonomy.ts +51 -0
- package/src/theme.ts +1135 -0
- package/src/to-markdown.ts +179 -0
- package/src/updates.ts +126 -0
- package/src/version.ts +2 -0
- package/src/vite.d.ts +25 -0
- package/src/vite.js +199 -0
- package/src/webhooks.ts +107 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { Client, ClientState, Cossack, Page, Server, State, defineServerMiddleware, setRequestLocale, type HeadValue } from '@cossackframework/core';
|
|
2
|
+
import { input } from '@cossackframework/core/input';
|
|
3
|
+
import { isTransportPath } from '@cossackframework/core/transport-routes';
|
|
4
|
+
import { getCookie } from 'hono/cookie';
|
|
5
|
+
import { component, html } from '@cossackframework/renderer';
|
|
6
|
+
import { hasPermission, isCmsError, isSameOriginPost, PERMISSIONS, type ArchiveView, type EntryView, type LanguageLink, type Note, type RecordShape, type ThemeData } from '@cossackframework/cms';
|
|
7
|
+
import type { CmsHost } from '@cossackframework/cms/server';
|
|
8
|
+
import { archive, authorArchive, authorView, bindableEntry, bindingScopes, commentResult, entryLock, entryViews, homeView, isMembersOnly, isProtected, languageLinks, localePrefix, pageNumber, redirectFor, requestLock, resolvePath, searchBase, searchEntries, termArchive, themeData, themeState, unlockCookie, unlockToken, resolvedOptions, type Resolved, type ThemeState, notFoundPage } from '#app/cms/site';
|
|
9
|
+
import { archiveTemplate, entryTemplate, withContentFields, siteContent, siteTheme, tagDocument, themeContext, unavailable } from '#app/cms/site-view';
|
|
10
|
+
import { authorSeo, entrySeo, homeSeo, listSeo } from '#app/cms/seo';
|
|
11
|
+
import { emptySeo, seoHead, type SeoView } from '#app/cms/seo-head';
|
|
12
|
+
import type { SiteDraft, SiteEditable } from '#app/cms/site-editor';
|
|
13
|
+
import { draftBlockOptions, draftEntry, draftMedia, editableRecord, frameDraft, saveDocuments, saveDraft, siteDraft, siteEditable } from '#app/cms/site-editing';
|
|
14
|
+
import { siteSession, type SiteEditingContext } from '#app/cms/site-session';
|
|
15
|
+
import type { SiteDocument } from '#app/cms/site-editor';
|
|
16
|
+
import { contentMenus, siteInfo, type SiteInfo } from '#app/cms/site';
|
|
17
|
+
import type { MenuItemView } from '@cossackframework/cms';
|
|
18
|
+
import { fieldErrors } from '#app/cms/content';
|
|
19
|
+
import { entryAsMarkdown, wantsMarkdown } from '#app/cms/machine';
|
|
20
|
+
import { applyCacheHeaders, cacheHeaders, listedCollections } from '#app/cms/cache';
|
|
21
|
+
import { trackCrawler, trackNotFound } from '#app/cms/traffic';
|
|
22
|
+
import { siteOrigin } from '#app/cms/seo';
|
|
23
|
+
import type { EditorBlock, EditorValues } from '#app/cms/editor';
|
|
24
|
+
import type { MediaPreview } from '#app/cms/field-controls';
|
|
25
|
+
import type { MediaChooserState } from '#app/cms/media-chooser';
|
|
26
|
+
|
|
27
|
+
/** What the layout needs of the draft's documents at render time, to mark the areas and the patterns in them. */
|
|
28
|
+
function editingContext(documents: readonly SiteDocument[]): SiteEditingContext {
|
|
29
|
+
return {
|
|
30
|
+
areas: documents.filter(document => document.kind === 'area').map(document => ({ name: document.name, blocks: document.blocks })),
|
|
31
|
+
editable: documents.some(document => document.kind === 'area' && document.editable),
|
|
32
|
+
patterns: documents.filter(document => document.kind === 'pattern').map(document => ({ id: document.name, editable: document.editable })),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The site editor, loaded the first time an editor enters edit mode; visitors never load it. */
|
|
37
|
+
let SiteEditor: typeof import('#app/cms/site-editor.client').SiteEditor | undefined;
|
|
38
|
+
|
|
39
|
+
const segmentsOf = (path: string | undefined) => (path ?? '').split('/').filter(Boolean);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the path before rendering, so entries can redirect to their canonical URL and
|
|
43
|
+
* missing paths can follow redirects. A root catch-all's middleware also sees requests for
|
|
44
|
+
* routes registered after it, such as /crpc, so it acts only on page reads. The home page
|
|
45
|
+
* (`src/pages/(site)/index.ts`) runs it too.
|
|
46
|
+
*/
|
|
47
|
+
export const resolveSitePath = defineServerMiddleware(async (c, next) => {
|
|
48
|
+
// Pages read with GET; a POST is a visitor's password for a protected entry, resolved the same way, never redirected.
|
|
49
|
+
const post = c.req.method === 'POST';
|
|
50
|
+
if ((c.req.method !== 'GET' && c.req.method !== 'HEAD' && !post) || isTransportPath(c.req.path)) { await next(); return; }
|
|
51
|
+
// Unknown API paths keep their JSON 404.
|
|
52
|
+
if (c.req.path === '/api' || c.req.path.startsWith('/api/')) return c.json({ error: 'Not Found', code: 'COSSACK_NOT_FOUND' }, 404);
|
|
53
|
+
const cms = c.get('cms');
|
|
54
|
+
let resolved: Resolved | { kind: 'unavailable' } = { kind: 'none', locale: 'en' };
|
|
55
|
+
// Before setup, or while a migration is pending, content is unavailable.
|
|
56
|
+
try {
|
|
57
|
+
resolved = await resolvePath(cms, segmentsOf(c.req.param('path')));
|
|
58
|
+
const query = new URL(c.req.url).search.slice(1);
|
|
59
|
+
// A canonical or language redirect keeps the query, such as ?page=2 or ?edit.
|
|
60
|
+
if (resolved.kind === 'redirect' && query && !resolved.url.includes('?')) resolved = { ...resolved, url: `${resolved.url}?${query}` };
|
|
61
|
+
if (resolved.kind === 'none' && !post) {
|
|
62
|
+
resolved = await redirectFor(cms, c.req.path, query, work => { try { c.executionCtx.waitUntil(work.catch(() => undefined)); } catch { void work.catch(() => undefined); } }) ?? resolved;
|
|
63
|
+
}
|
|
64
|
+
} catch (error) { if (!isCmsError(error, 'CMS_UNAVAILABLE')) throw error; resolved = { kind: 'unavailable' }; }
|
|
65
|
+
if (resolved.kind === 'redirect') return post ? c.text('Not found', 404) : c.redirect(resolved.url, resolved.status ?? 301);
|
|
66
|
+
// Agents asking for Markdown get the entry as a document; the HTML varies on Accept.
|
|
67
|
+
if (resolved.kind === 'entry' && !post) {
|
|
68
|
+
c.header('vary', 'Accept');
|
|
69
|
+
if (wantsMarkdown(c.req.raw) && await cms.settings.get('seo.markdown')) {
|
|
70
|
+
// As the HTML page decides: its editors and a visitor who unlocked it read a protected entry, members a members-only one.
|
|
71
|
+
const lock = await requestLock(cms, resolved.record, `cms/${resolved.collection.name}`, c.get('principal'), getCookie(c, unlockCookie(resolved.record)));
|
|
72
|
+
if (lock === 'password') return c.text('This entry is password protected.', 403);
|
|
73
|
+
if (lock === 'members') return c.text('This entry is for members.', 403);
|
|
74
|
+
trackCrawler(c, 'markdown');
|
|
75
|
+
const url = (await cms.entryUrls(resolved.collection, [resolved.record])).get(resolved.record.id) ?? c.req.path;
|
|
76
|
+
// Caches key HTML by URL and ignore Vary: Markdown chosen by Accept is never stored; `?format=md` is the address to cache.
|
|
77
|
+
const addressed = /^(?:md|markdown)$/.test(c.req.query('format') ?? '');
|
|
78
|
+
const headers = addressed && !isMembersOnly(resolved.record) && !isProtected(resolved.record) ? await cacheHeaders(cms, [cms.purge.tag.entry(resolved.collection.name, resolved.record.id), cms.purge.tag.collection(resolved.collection.name)]) : { 'cache-control': 'private, no-store' };
|
|
79
|
+
return c.body(await entryAsMarkdown(cms, resolved.collection, resolved.record, url, siteOrigin(c)), 200, { 'content-type': 'text/markdown; charset=utf-8', ...headers, 'x-robots-tag': 'noindex' });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!post) {
|
|
83
|
+
if (resolved.kind === 'none') trackNotFound(c);
|
|
84
|
+
if (resolved.kind !== 'unavailable') trackCrawler(c, resolved.kind === 'none' || resolved.kind === 'gone' ? 'not-found' : resolved.kind === 'entry' || resolved.kind === 'archive' || resolved.kind === 'home' || resolved.kind === 'term' || resolved.kind === 'author' || resolved.kind === 'search' ? resolved.kind : 'other');
|
|
85
|
+
}
|
|
86
|
+
c.set('cms.site', resolved);
|
|
87
|
+
// The page renders in its content's language: <html lang>, and the theme's text when a catalog has it.
|
|
88
|
+
if ('locale' in resolved) setRequestLocale(resolved.locale);
|
|
89
|
+
await next();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Every site URL without its own route: the home page (/, which `src/pages/(site)/index.ts`
|
|
94
|
+
* routes here too), collection archives (/posts), entries (/posts/hello-world,
|
|
95
|
+
* /shop/rocket-skates), term archives (/category/news), nested pages (/about/team) and other
|
|
96
|
+
* languages' pages (/fr, /fr/a-propos), drawn by the active theme. Missing paths follow
|
|
97
|
+
* Tools → Redirects; anything else is a 404. An entry its editor may update, a static front
|
|
98
|
+
* page included, is edited in place at `?edit`.
|
|
99
|
+
*/
|
|
100
|
+
@Page({ transport: 'http', middlewares: [resolveSitePath] })
|
|
101
|
+
export default class SitePath extends Cossack {
|
|
102
|
+
@State() kind: 'entry' | 'list' | 'home' | 'none' | 'gone' | 'unavailable' = 'none';
|
|
103
|
+
@State() entry: EntryView | null = null;
|
|
104
|
+
/** The entry is the page Settings → Reading shows for missing addresses: status 404, no indexing. */
|
|
105
|
+
@State() notFound = false;
|
|
106
|
+
/** Why this visitor cannot read the entry: the password form or a sign-in prompt shows instead of its content. */
|
|
107
|
+
@State() locked: 'password' | 'members' | null = null;
|
|
108
|
+
/** The site takes registrations: a members-only entry's prompt links to the registration page. */
|
|
109
|
+
@State() registration = false;
|
|
110
|
+
@State() wrongPassword = false;
|
|
111
|
+
@State() view: ArchiveView = { kind: 'archive', collection: null, taxonomy: null, title: '', description: '', entries: [], paging: { page: 1, pages: 1, base: '/' }, query: '' };
|
|
112
|
+
@State() theme: ThemeState = { name: null, options: {} };
|
|
113
|
+
/** The page in each of the site's languages, for `helpers.languages()` in the page's templates and blocks. */
|
|
114
|
+
@State() languages: LanguageLink[] = [];
|
|
115
|
+
/** The theme's menus, for Navigation blocks in the entry's own content; empty when it has none. */
|
|
116
|
+
@State() menus: Record<string, readonly MenuItemView[]> = {};
|
|
117
|
+
/** The site's title, logo and URLs in the page's language, for site blocks in the content. */
|
|
118
|
+
@State() site: SiteInfo | null = null;
|
|
119
|
+
/** What the theme's loader for the page returned. */
|
|
120
|
+
@State() data: ThemeData = {};
|
|
121
|
+
@State() seo: SeoView = emptySeo();
|
|
122
|
+
/** For a signed-in user who may update the entry: what `?edit` opens, and the taskbar's editor links. Null for others. */
|
|
123
|
+
@State() editable: SiteEditable | null = null;
|
|
124
|
+
/** A list page whose frame (the theme's areas) the user may change: `?edit` opens the frame alone. */
|
|
125
|
+
@State() frameEditable = false;
|
|
126
|
+
/** Edit mode: the entry's draft. `?edit` opens it. */
|
|
127
|
+
@State() draft: SiteDraft | null = null;
|
|
128
|
+
@ClientState() editorReady = false;
|
|
129
|
+
@ClientState() saving = false;
|
|
130
|
+
|
|
131
|
+
head(): HeadValue {
|
|
132
|
+
if (this.notFound) return { title: this.entry?.title ?? __('Page not found'), meta: [{ tag: 'meta', attributes: { name: 'robots', content: 'noindex' } }] };
|
|
133
|
+
if (this.seo.title) return seoHead(this.seo);
|
|
134
|
+
// Before setup the site is unavailable: the layout's site title, kept out of search results.
|
|
135
|
+
if (this.kind === 'unavailable') return { meta: [{ tag: 'meta', attributes: { name: 'robots', content: 'noindex' } }] };
|
|
136
|
+
return { title: this.kind === 'gone' ? __('Page removed') : __('Page not found'), meta: [{ tag: 'meta', attributes: { name: 'robots', content: 'noindex' } }] };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async init() {
|
|
140
|
+
const cms = this.c.get('cms');
|
|
141
|
+
const resolved = this.c.get('cms.site') ?? { kind: 'none', locale: 'en' };
|
|
142
|
+
const page = pageNumber(this.c.req.query('page'));
|
|
143
|
+
const base = `/${segmentsOf(this.c.req.param('path')).join('/')}`;
|
|
144
|
+
try {
|
|
145
|
+
this.theme = await themeState(cms);
|
|
146
|
+
if (resolved.kind === 'unavailable') { this.kind = 'unavailable'; this.c.status(503); return; }
|
|
147
|
+
if (resolved.kind === 'gone') { this.kind = 'gone'; this.c.status(410); await applyCacheHeaders(this.c, cms, [], { max: 60 }); return; }
|
|
148
|
+
if (resolved.kind === 'none' || resolved.kind === 'redirect') {
|
|
149
|
+
this.c.status(404);
|
|
150
|
+
const locale = resolved.kind === 'none' ? resolved.locale : undefined;
|
|
151
|
+
// Settings → Reading may choose a page for missing addresses: it renders as an entry, with status 404 and no indexing.
|
|
152
|
+
const chosen = await notFoundPage(cms, locale ?? (await cms.languages()).default);
|
|
153
|
+
if (chosen) {
|
|
154
|
+
this.kind = 'entry';
|
|
155
|
+
this.entry = chosen;
|
|
156
|
+
this.notFound = true;
|
|
157
|
+
this.site = await siteInfo(cms, locale ?? (await cms.languages()).default, { url: this.c.req.url });
|
|
158
|
+
this.data = await themeData(cms, this.theme, { kind: 'entry', collection: chosen.collection, template: chosen.template }, chosen, this.c.get('principal'), locale);
|
|
159
|
+
} else this.data = await themeData(cms, this.theme, { kind: 'not-found' }, this.view, this.c.get('principal'), locale);
|
|
160
|
+
// A page may appear here later: held a minute, and purged with the site.
|
|
161
|
+
await applyCacheHeaders(this.c, cms, [], { max: 60 });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const settings = await cms.settings.all();
|
|
165
|
+
const links = await languageLinks(cms, resolved);
|
|
166
|
+
this.languages = links;
|
|
167
|
+
this.site = await siteInfo(cms, resolved.locale, { url: this.c.req.url, page: resolved });
|
|
168
|
+
const usage = { user: false };
|
|
169
|
+
const viewOptions = {
|
|
170
|
+
comment: commentResult(this.c.req.query('comment')), ...this.readerOptions(),
|
|
171
|
+
forms: { query: this.c.req.query(), principal: this.c.get('principal'), url: base }, usage,
|
|
172
|
+
};
|
|
173
|
+
/** The entry the page shows, which its editor may edit in place: an entry, or the static front page. */
|
|
174
|
+
let shown: { collection: string; record: RecordShape } | null = null;
|
|
175
|
+
// Templates read the theme's options with their bindings resolved, as the layout does.
|
|
176
|
+
// A locked entry binds as its readers see it unless this reader may read it; the password never binds.
|
|
177
|
+
const bound = resolved.kind === 'entry' ? await bindableEntry(cms, resolved.collection.name, resolved.record, this.c.get('principal'), getCookie(this.c, unlockCookie(resolved.record))) : null;
|
|
178
|
+
this.theme = { ...this.theme, options: resolvedOptions(this.theme.options, bindingScopes(settings, { entry: bound, user: viewOptions.user })) };
|
|
179
|
+
if (resolved.kind === 'home') {
|
|
180
|
+
const home = await homeView(cms, resolved.locale, page, viewOptions);
|
|
181
|
+
if (home.page && home.record) {
|
|
182
|
+
this.kind = 'entry';
|
|
183
|
+
this.entry = home.page;
|
|
184
|
+
shown = { collection: 'pages', record: home.record };
|
|
185
|
+
this.seo = await entrySeo(cms, this.c, cms.collection('pages'), home.record, { ...home.page, url: base }, links);
|
|
186
|
+
} else {
|
|
187
|
+
this.kind = 'home';
|
|
188
|
+
this.view = { ...this.view, kind: 'home', ...home.view };
|
|
189
|
+
this.seo = await homeSeo(cms, this.c, { url: base, locale: resolved.locale, links, page });
|
|
190
|
+
}
|
|
191
|
+
} else if (resolved.kind === 'search') {
|
|
192
|
+
const query = (this.c.req.query('q') ?? '').trim().slice(0, 200);
|
|
193
|
+
this.kind = 'list';
|
|
194
|
+
const found = query ? await searchEntries(cms, query, { locale: resolved.locale, page, base: searchBase(base, query) }) : { entries: [], paging: { page: 1, pages: 1, base }, loose: false };
|
|
195
|
+
this.view = { ...this.view, kind: 'search', collection: null, query, title: query ? `${__('Results for')} “${query}”` : __('Search'), ...found };
|
|
196
|
+
this.seo = await listSeo(cms, this.c, { kind: 'search', title: this.view.title, description: '', url: base, locale: resolved.locale, links, noindex: true });
|
|
197
|
+
} else if (resolved.kind === 'entry' && resolved.collection.name === 'pages' && resolved.record.id === settings['reading.pageForPosts']) {
|
|
198
|
+
// Settings → Reading's posts page lists the latest posts under its own title.
|
|
199
|
+
this.kind = 'list';
|
|
200
|
+
this.view = { ...this.view, title: String(resolved.record.title ?? ''), collection: 'posts', ...await archive(cms, cms.collection('posts'), page, { base, locale: resolved.locale }) };
|
|
201
|
+
const posts = cms.collection('posts');
|
|
202
|
+
this.seo = await listSeo(cms, this.c, { kind: 'archive', collection: posts, title: this.view.title, description: '', url: base, locale: resolved.locale, links, page, noindex: posts.robots?.archiveNoindex, nofollow: posts.robots?.nofollow });
|
|
203
|
+
} else if (resolved.kind === 'entry') {
|
|
204
|
+
this.kind = 'entry';
|
|
205
|
+
shown = { collection: resolved.collection.name, record: resolved.record };
|
|
206
|
+
// Editors read their protected and members-only entries; visitors unlock protected ones with the password, which a cookie remembers.
|
|
207
|
+
const reader = this.c.get('principal');
|
|
208
|
+
const editor = reader.kind === 'user' && cms.resource(`cms/${resolved.collection.name}`).canUpdate(resolved.record, reader);
|
|
209
|
+
const unlocked = isProtected(resolved.record) && getCookie(this.c, unlockCookie(resolved.record)) === await unlockToken(resolved.record);
|
|
210
|
+
const only = new Set([resolved.record.id]);
|
|
211
|
+
this.locked = entryLock(resolved.record, { unlocked: unlocked ? only : undefined, signedIn: reader.kind === 'user', roles: viewOptions.roles, editor });
|
|
212
|
+
this.wrongPassword = this.c.req.query('password') === 'wrong';
|
|
213
|
+
if (this.locked === 'members') this.registration = await cms.settings.get('general.usersCanRegister');
|
|
214
|
+
// The page depends on the password cookie or the session, which shared caches ignore: never stored, locked or unlocked.
|
|
215
|
+
if (isProtected(resolved.record) || isMembersOnly(resolved.record)) this.c.header('cache-control', 'private, no-store');
|
|
216
|
+
this.entry = (await entryViews(cms, resolved.collection, [resolved.record], { ...viewOptions, full: true, ...(unlocked ? { unlocked: only } : {}), ...(editor ? { editable: only } : {}) }))[0]!;
|
|
217
|
+
this.seo = await entrySeo(cms, this.c, resolved.collection, resolved.record, this.entry, links);
|
|
218
|
+
} else if (resolved.kind === 'archive') {
|
|
219
|
+
this.kind = 'list';
|
|
220
|
+
this.view = { ...this.view, title: resolved.collection.label, description: resolved.collection.description ?? '', collection: resolved.collection.name, ...await archive(cms, resolved.collection, page, { base, locale: resolved.locale }) };
|
|
221
|
+
this.seo = await listSeo(cms, this.c, { kind: 'archive', collection: resolved.collection, title: this.view.title, description: this.view.description, url: base, locale: resolved.locale, links, page, noindex: resolved.collection.robots?.archiveNoindex, nofollow: resolved.collection.robots?.nofollow });
|
|
222
|
+
} else if (resolved.kind === 'term') {
|
|
223
|
+
const taxonomy = cms.taxonomies.declaration(resolved.term.taxonomy);
|
|
224
|
+
this.kind = 'list';
|
|
225
|
+
this.view = { ...this.view, kind: 'term', title: `${taxonomy.singular}: ${resolved.term.name}`, description: resolved.term.description, ...await termArchive(cms, resolved.term, page, base, resolved.locale) };
|
|
226
|
+
this.seo = await listSeo(cms, this.c, { kind: 'term', term: resolved.term, taxonomy: taxonomy.label, title: this.view.title, description: this.view.description, url: base, locale: resolved.locale, links, page, noindex: taxonomy.noindex });
|
|
227
|
+
} else if (resolved.kind === 'author') {
|
|
228
|
+
const author = authorView(resolved.user, localePrefix(await cms.languages(), resolved.locale));
|
|
229
|
+
this.kind = 'list';
|
|
230
|
+
this.view = { ...this.view, kind: 'author', author, taxonomy: null, title: author.name, description: author.bio, ...await authorArchive(cms, resolved.user, page, base, resolved.locale) };
|
|
231
|
+
this.seo = await authorSeo(cms, this.c, { user: resolved.user, url: base, locale: resolved.locale, links, page });
|
|
232
|
+
}
|
|
233
|
+
if (this.kind === 'entry' && this.entry) await this.refreshMenus();
|
|
234
|
+
const principal = this.c.get('principal');
|
|
235
|
+
if (shown && principal.kind === 'user') {
|
|
236
|
+
this.editable = await siteEditable(cms, shown.collection, shown.record.id, principal);
|
|
237
|
+
// An editor's page may hold their draft: never cache it.
|
|
238
|
+
if (this.editable) this.c.header('cache-control', 'private, no-store');
|
|
239
|
+
if (this.editable && this.c.req.query('edit') !== undefined) await this.startEditing();
|
|
240
|
+
}
|
|
241
|
+
// A list page has no entry to edit, but its header and footer are the theme's areas: editable in place by whoever may change them.
|
|
242
|
+
this.frameEditable = !shown && (this.kind === 'home' || this.kind === 'list') && principal.kind === 'user' && hasPermission(principal, PERMISSIONS.manageAppearance);
|
|
243
|
+
if (this.frameEditable) {
|
|
244
|
+
this.c.header('cache-control', 'private, no-store');
|
|
245
|
+
if (this.c.req.query('edit') !== undefined) await this.startEditing();
|
|
246
|
+
}
|
|
247
|
+
// The site taskbar shows the page's SEO and, for an entry the user may edit, its status and editor.
|
|
248
|
+
this.c.set('cms.taskbar', { seo: this.seo, frame: this.frameEditable, entry: this.editable && shown
|
|
249
|
+
? { collection: this.editable.collection, id: this.editable.id, status: String(shown.record.status ?? ''), dashboard: this.editable.dashboard, inPlace: true } : null });
|
|
250
|
+
// A binding to the signed-in user makes the page theirs alone.
|
|
251
|
+
if (usage.user && viewOptions.user) this.c.header('cache-control', 'private, no-store');
|
|
252
|
+
if (this.kind === 'entry' && this.entry) this.data = await themeData(cms, this.theme, { kind: 'entry', collection: this.entry.collection, template: this.entry.template }, this.entry, principal, resolved.locale);
|
|
253
|
+
else if (this.kind === 'home' || this.kind === 'list') this.data = await themeData(cms, this.theme, this.view, this.view, principal, resolved.locale);
|
|
254
|
+
await applyCacheHeaders(this.c, cms, this.cacheTags(cms, resolved, shown));
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (!isCmsError(error, 'CMS_UNAVAILABLE')) throw error;
|
|
257
|
+
this.kind = 'unavailable';
|
|
258
|
+
this.c.status(503);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* What the page shows, for its `Cache-Tag` header: the entry, the collections it lists (lists
|
|
264
|
+
* and feeds of a collection, the Latest entries blocks of the entry and of the theme's areas,
|
|
265
|
+
* which the layout noted) and the term, so a change purges the pages that showed it.
|
|
266
|
+
*/
|
|
267
|
+
private cacheTags(cms: CmsHost, resolved: Resolved, shown: { collection: string; record: RecordShape } | null): string[] {
|
|
268
|
+
const { tag } = cms.purge;
|
|
269
|
+
const tags = [...(this.c.get('cms.cacheTags') ?? [])];
|
|
270
|
+
const listed = (collections: Iterable<string>) => { for (const name of collections) tags.push(tag.collection(name)); };
|
|
271
|
+
if (shown) tags.push(tag.entry(shown.collection, shown.record.id), tag.collection(shown.collection));
|
|
272
|
+
if (this.entry) listed(listedCollections(this.entry.content));
|
|
273
|
+
if (resolved.kind === 'home' || resolved.kind === 'search' || resolved.kind === 'author') listed(cms.collections().filter(collection => typeof collection.path === 'string').map(collection => collection.name));
|
|
274
|
+
if (resolved.kind === 'archive') listed([resolved.collection.name]);
|
|
275
|
+
if (this.kind === 'list' && this.view.collection) listed([this.view.collection]);
|
|
276
|
+
if (resolved.kind === 'term') {
|
|
277
|
+
tags.push(tag.term(resolved.term.taxonomy, resolved.term.slug));
|
|
278
|
+
listed(cms.taxonomies.usage(resolved.term.taxonomy).map(usage => usage.resource).filter(resource => resource.startsWith('cms/')).map(resource => resource.slice(4)));
|
|
279
|
+
}
|
|
280
|
+
return tags;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** A visitor's password for a protected entry: right, and a cookie remembers it; wrong, and the form says so. */
|
|
284
|
+
async post() {
|
|
285
|
+
if (!isSameOriginPost(this.c.req.raw)) return this.c.text('Forbidden', 403);
|
|
286
|
+
const resolved = this.c.get('cms.site');
|
|
287
|
+
if (!resolved || resolved.kind !== 'entry' || !isProtected(resolved.record)) return this.c.text('Not found', 404);
|
|
288
|
+
const form = await this.c.req.formData();
|
|
289
|
+
const typed = String(form.get('password') ?? '');
|
|
290
|
+
const url = this.c.req.path;
|
|
291
|
+
if (typed !== String(resolved.record.password)) return this.redirect(`${url}?password=wrong#password`);
|
|
292
|
+
const secure = new URL(this.c.req.url).protocol === 'https:' ? '; Secure' : '';
|
|
293
|
+
// Path=/: the comments form posts to /api/cms/comments, which checks the same unlock.
|
|
294
|
+
this.c.header('set-cookie', `${unlockCookie(resolved.record)}=${await unlockToken(resolved.record)}; Path=/; Max-Age=${10 * 24 * 3600}; HttpOnly; SameSite=Lax${secure}`, { append: true });
|
|
295
|
+
return this.redirect(url);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** What a members-only entry shows a visitor who is not signed in: the theme's prompt, or a plain one. */
|
|
299
|
+
private membersPrompt(theme: ReturnType<typeof siteTheme>, context: ReturnType<typeof themeContext>) {
|
|
300
|
+
const entry = this.entry!;
|
|
301
|
+
const back = encodeURIComponent(this.c.req.path);
|
|
302
|
+
const signedIn = this.c.get('principal').kind === 'user';
|
|
303
|
+
const view = { entry, signedIn, signIn: `/auth/login?redirect=${back}`, register: this.registration && !signedIn ? `/auth/register?redirect=${back}` : null };
|
|
304
|
+
return theme.members?.({ ...context, view }) ?? html`<article class="space-y-6" data-members-only>
|
|
305
|
+
<header><h1 class="text-4xl font-bold tracking-tight text-foreground">${entry.title}</h1></header>
|
|
306
|
+
<div class="max-w-sm space-y-3">
|
|
307
|
+
${signedIn ? html`<p class="text-sm text-muted-foreground">${__('This content is for members with another kind of account than yours.')}</p>` : html`
|
|
308
|
+
<p class="text-sm text-muted-foreground">${__('This content is for members. Sign in to read it.')}</p>
|
|
309
|
+
<p class="flex flex-wrap items-center gap-3">
|
|
310
|
+
<a href=${view.signIn} class="rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground no-underline">${__('Sign in')}</a>
|
|
311
|
+
${view.register ? html`<a href=${view.register} class="text-sm text-primary hover:underline">${__('Create an account')}</a>` : null}
|
|
312
|
+
</p>`}
|
|
313
|
+
</div>
|
|
314
|
+
</article>`;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The password form of a protected entry: the theme's, or a plain one. */
|
|
318
|
+
private passwordForm(theme: ReturnType<typeof siteTheme>, context: ReturnType<typeof themeContext>) {
|
|
319
|
+
const entry = this.entry!;
|
|
320
|
+
const view = { entry, action: this.c.req.path, error: this.wrongPassword };
|
|
321
|
+
return theme.password?.({ ...context, view }) ?? html`<article class="space-y-6" data-protected>
|
|
322
|
+
<header><h1 class="text-4xl font-bold tracking-tight text-foreground">${entry.title}</h1></header>
|
|
323
|
+
<form id="password" method="post" action=${view.action} class="max-w-sm space-y-3">
|
|
324
|
+
<p class="text-sm text-muted-foreground">${__('This content is password protected. To view it, enter the password below.')}</p>
|
|
325
|
+
${view.error ? html`<p role="alert" class="text-sm text-destructive">${__('That password is not right. Try again.')}</p>` : null}
|
|
326
|
+
<label for="entry-password" class="block text-sm font-medium text-foreground">${__('Password')}</label>
|
|
327
|
+
<input id="entry-password" name="password" type="password" required autocomplete="off" class="block w-full rounded-md border border-input bg-background px-3 py-2 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring">
|
|
328
|
+
<button type="submit" class="rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground border-none cursor-pointer">${__('Enter')}</button>
|
|
329
|
+
</form>
|
|
330
|
+
</article>`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// --- Editing on the site ------------------------------------------------------------------
|
|
334
|
+
|
|
335
|
+
/** Enter edit mode: a draft of the saved entry, rendered like a preview. */
|
|
336
|
+
@Server()
|
|
337
|
+
async startEditing() {
|
|
338
|
+
// The entry this address shows, never the one the client's state names.
|
|
339
|
+
await this.openDraft(await this.routeEntry());
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Start again from the saved entry being edited, after a conflict: the draft's own entry, since
|
|
344
|
+
* a save elsewhere may have moved it to another address. Its editor's rights are checked again.
|
|
345
|
+
*/
|
|
346
|
+
@Server()
|
|
347
|
+
async restartEditing() {
|
|
348
|
+
const draft = this.draft;
|
|
349
|
+
await this.openDraft(draft?.collection && draft.id ? { collection: draft.collection, id: draft.id } : await this.routeEntry());
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private async openDraft(shown: { collection: string; id: string } | null) {
|
|
353
|
+
const cms = this.c.get('cms');
|
|
354
|
+
const found = shown ? await editableRecord(cms, shown.collection, shown.id, this.c.get('principal')) : null;
|
|
355
|
+
if (!found) {
|
|
356
|
+
// A list page: the frame alone, for a user who may change the theme's areas.
|
|
357
|
+
const frame = this.frameEditable ? await frameDraft(cms, this.c.get('principal')) : null;
|
|
358
|
+
this.editable = null;
|
|
359
|
+
this.draft = frame;
|
|
360
|
+
if (frame) this.c.set('cms.editing', editingContext(frame.documents));
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.editable = { collection: found.collection.name, id: found.record.id, dashboard: `/dashboard/content/${found.collection.name}/${found.record.id}` };
|
|
364
|
+
this.draft = await siteDraft(cms, found.collection, found.record, this.c.get('principal'));
|
|
365
|
+
// The layout renders the areas with their markers from the first paint (`server$` in the layout reads this at render time).
|
|
366
|
+
this.c.set('cms.editing', editingContext(this.draft.documents));
|
|
367
|
+
this.entry = await draftEntry(cms, found.collection, found.record, this.draft.values, this.formRequest());
|
|
368
|
+
await this.refreshMenus();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* The entry the page's address shows, as `init` finds it: an entry (not the posts page) or the
|
|
373
|
+
* static front page. The other editing methods act on the draft this one started, and check
|
|
374
|
+
* again that the user may edit its entry.
|
|
375
|
+
*/
|
|
376
|
+
private async routeEntry(): Promise<{ collection: string; id: string } | null> {
|
|
377
|
+
const cms = this.c.get('cms');
|
|
378
|
+
const resolved = await resolvePath(cms, segmentsOf(this.c.req.param('path'))).catch(() => null);
|
|
379
|
+
if (resolved?.kind === 'entry') {
|
|
380
|
+
if (resolved.collection.name === 'pages' && resolved.record.id === await cms.settings.get('reading.pageForPosts').catch(() => null)) return null;
|
|
381
|
+
return { collection: resolved.collection.name, id: resolved.record.id };
|
|
382
|
+
}
|
|
383
|
+
if (resolved?.kind === 'home') {
|
|
384
|
+
const home = await homeView(cms, resolved.locale, 1);
|
|
385
|
+
return home.record ? { collection: 'pages', id: home.record.id } : null;
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** Render the page from the draft's values. Invalid values keep the last rendering and show why. */
|
|
391
|
+
@Server({ input: input.args(input.record()) })
|
|
392
|
+
async previewDraft(values: EditorValues) {
|
|
393
|
+
const cms = this.c.get('cms');
|
|
394
|
+
const draft = this.draft;
|
|
395
|
+
const found = draft ? await editableRecord(cms, draft.collection, draft.id, this.c.get('principal')) : null;
|
|
396
|
+
if (!draft || !found) { this.draft = null; return; }
|
|
397
|
+
try {
|
|
398
|
+
this.entry = await draftEntry(cms, found.collection, found.record, values, this.formRequest(), draft.documents, await draftBlockOptions(cms, draft, this.c.get('principal')));
|
|
399
|
+
await this.refreshMenus();
|
|
400
|
+
this.draft = { ...draft, values, changed: true, error: '', errors: {} };
|
|
401
|
+
} catch (error) {
|
|
402
|
+
if (!isCmsError(error)) throw error;
|
|
403
|
+
this.draft = { ...draft, values, changed: true, error: error.message, errors: fieldErrors(error) };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Save the draft over the revision it started from; a newer save is a conflict to reload. */
|
|
408
|
+
@Server()
|
|
409
|
+
async saveDraft(values: EditorValues) {
|
|
410
|
+
const cms = this.c.get('cms');
|
|
411
|
+
const principal = this.c.get('principal');
|
|
412
|
+
const draft = this.draft;
|
|
413
|
+
if (draft && !draft.collection) {
|
|
414
|
+
// The frame alone: the documents are everything there is to save.
|
|
415
|
+
this.draft = { ...draft, documents: await saveDocuments(cms, draft.documents, await draftBlockOptions(cms, draft, principal), principal) };
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const found = draft ? await editableRecord(cms, draft.collection, draft.id, principal) : null;
|
|
419
|
+
if (!draft || !found) { this.draft = null; return; }
|
|
420
|
+
// The areas save on their own, each over its revision; a conflict stays on its document and the others still save.
|
|
421
|
+
const documents = await saveDocuments(cms, draft.documents, await draftBlockOptions(cms, draft, principal), principal);
|
|
422
|
+
if (!draft.changed) { this.draft = { ...draft, documents }; return; }
|
|
423
|
+
try {
|
|
424
|
+
const record = await saveDraft(cms, draft, values, principal);
|
|
425
|
+
this.draft = { ...await siteDraft(cms, found.collection, record, principal), chooser: draft.chooser, documents };
|
|
426
|
+
this.entry = await draftEntry(cms, found.collection, record, this.draft.values, this.formRequest());
|
|
427
|
+
await this.refreshMenus();
|
|
428
|
+
} catch (error) {
|
|
429
|
+
if (!isCmsError(error)) throw error;
|
|
430
|
+
this.draft = { ...draft, values, documents, conflict: error.code === 'CMS_CONFLICT', error: error.message, errors: fieldErrors(error) };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** Leave edit mode: the page shows the saved entry again. */
|
|
435
|
+
@Server()
|
|
436
|
+
async stopEditing() {
|
|
437
|
+
const cms = this.c.get('cms');
|
|
438
|
+
const draft = this.draft;
|
|
439
|
+
this.draft = null;
|
|
440
|
+
const found = draft ? await editableRecord(cms, draft.collection, draft.id, this.c.get('principal')) : null;
|
|
441
|
+
// As init shows it to this reader: an editor reads the protected or members-only entry, and user bindings resolve.
|
|
442
|
+
if (found) this.entry = (await entryViews(cms, found.collection, [found.record], { ...this.readerOptions(), full: true, forms: this.formRequest(), editable: new Set([found.record.id]) }))[0]!;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Who reads the page, for entry views: signed in means the principal is a user (a session still owing its second factor is a visitor here). */
|
|
446
|
+
private readerOptions(): { user: { name: string } | null; roles: readonly string[] } {
|
|
447
|
+
const reader = this.c.get('principal');
|
|
448
|
+
return { user: reader.kind === 'user' && this.user ? { name: this.user.name } : null, roles: reader.kind === 'user' ? reader.roles : [] };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** What the entry's forms need in edit mode, whose server methods run under /crpc: the editor and the entry's page. */
|
|
452
|
+
private formRequest() {
|
|
453
|
+
return { query: {}, principal: this.c.get('principal'), url: this.entry?.url ?? '/' };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The menus the entry's own Navigation blocks show; nothing when it has none. */
|
|
457
|
+
private async refreshMenus() {
|
|
458
|
+
this.menus = this.entry ? await contentMenus(this.c.get('cms'), this.theme, this.entry.content, { locale: this.entry.locale, user: this.c.get('principal').kind === 'user' && this.user ? { name: this.user.name } : null, forms: this.formRequest() }) : {};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** The media library, for the editor of this entry only. */
|
|
462
|
+
@Server({ input: input.args(input.string({ maxLength: 2000 })) })
|
|
463
|
+
async searchDraftMedia(search: string) {
|
|
464
|
+
const cms = this.c.get('cms');
|
|
465
|
+
const draft = this.draft;
|
|
466
|
+
if (!draft) return;
|
|
467
|
+
const items = await draftMedia(cms, draft, search, this.c.get('principal'), draft.chooser.kind);
|
|
468
|
+
if (items) this.draft = { ...draft, chooser: { ...draft.chooser, search, items } };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** A document's blocks changed: keep them, let the layout preview the areas, and render the entry again for a pattern it shows. */
|
|
472
|
+
@Client()
|
|
473
|
+
changeDocument(key: string, blocks: EditorBlock[]) {
|
|
474
|
+
if (!this.draft) return;
|
|
475
|
+
this.draft = { ...this.draft, documents: this.draft.documents.map(document => document.key === key ? { ...document, blocks, changed: true, error: '' } : document) };
|
|
476
|
+
this.shareDocuments();
|
|
477
|
+
// A pattern the entry shows: render the entry again from its draft. The frame alone has no entry to render.
|
|
478
|
+
if (key.startsWith('pattern:') && this.draft.collection) void this.changeDraft(this.draft.values, true);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** The areas' and patterns' drafts, for the layout to preview them; null ends the session and shows the saved frame again. */
|
|
482
|
+
@Client()
|
|
483
|
+
private shareDocuments() {
|
|
484
|
+
const documents = this.draft?.documents ?? [];
|
|
485
|
+
siteSession.set(this.draft ? {
|
|
486
|
+
areas: documents.filter(document => document.kind === 'area').map(document => ({ name: document.name, blocks: document.blocks })),
|
|
487
|
+
patterns: documents.filter(document => document.kind === 'pattern').map(document => ({ id: document.name, blocks: document.blocks })),
|
|
488
|
+
} : null);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** Start again from the saved entry and areas, after a conflict. */
|
|
492
|
+
@Client()
|
|
493
|
+
async reloadDraft() {
|
|
494
|
+
await this.restartEditing();
|
|
495
|
+
this.shareDocuments();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** Leave edit mode, and drop `?edit` from the address so a reload shows the page, not the editor. */
|
|
499
|
+
@Client()
|
|
500
|
+
async exitEditing() {
|
|
501
|
+
siteSession.set(null);
|
|
502
|
+
const url = new URL(window.location.href);
|
|
503
|
+
if (url.searchParams.has('edit')) { url.searchParams.delete('edit'); window.history.replaceState(window.history.state, '', url); }
|
|
504
|
+
await this.stopEditing();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Load the editor's code once edit mode shows. */
|
|
508
|
+
@Client()
|
|
509
|
+
async loadEditor(element: Element | undefined) {
|
|
510
|
+
if (!element || SiteEditor) { this.editorReady = Boolean(SiteEditor); return; }
|
|
511
|
+
SiteEditor = (await import('#app/cms/site-editor.client')).SiteEditor;
|
|
512
|
+
this.editorReady = true;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** Values waiting to be previewed while a preview runs; only the latest is rendered. */
|
|
516
|
+
private previewPending: EditorValues | null = null;
|
|
517
|
+
private previewing = false;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Keep new values and, for a preview, render the page from them. Previews run one at a
|
|
521
|
+
* time so a slow earlier one cannot land after a later one and show a stale page; values
|
|
522
|
+
* changed meanwhile are previewed next and win over the ones the server echoes back.
|
|
523
|
+
*/
|
|
524
|
+
@Client()
|
|
525
|
+
async changeDraft(values: EditorValues, preview: boolean) {
|
|
526
|
+
if (!this.draft) return;
|
|
527
|
+
this.draft = { ...this.draft, values, changed: true };
|
|
528
|
+
if (!preview) return;
|
|
529
|
+
this.previewPending = values;
|
|
530
|
+
if (this.previewing) return;
|
|
531
|
+
this.previewing = true;
|
|
532
|
+
try {
|
|
533
|
+
while (this.previewPending && this.draft) {
|
|
534
|
+
const next = this.previewPending;
|
|
535
|
+
this.previewPending = null;
|
|
536
|
+
await this.previewDraft(next);
|
|
537
|
+
if (this.previewPending && this.draft) this.draft = { ...this.draft, values: this.previewPending };
|
|
538
|
+
}
|
|
539
|
+
} finally { this.previewing = false; }
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
@Client()
|
|
543
|
+
async save() {
|
|
544
|
+
if (!this.draft) return;
|
|
545
|
+
this.saving = true;
|
|
546
|
+
try { await this.saveDraft(this.draft.values); }
|
|
547
|
+
finally { this.saving = false; }
|
|
548
|
+
this.shareDocuments();
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
@Client()
|
|
552
|
+
setChooser(chooser: MediaChooserState) {
|
|
553
|
+
if (this.draft) this.draft = { ...this.draft, chooser };
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
@Client()
|
|
557
|
+
setPreviews(previews: Record<string, MediaPreview>) {
|
|
558
|
+
if (this.draft) this.draft = { ...this.draft, previews };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
@Client()
|
|
562
|
+
setNotes(notes: Note[]) {
|
|
563
|
+
if (this.draft) this.draft = { ...this.draft, notes };
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Edit mode: the editor, once its code is loaded. `data-site-editing` hides the site taskbar meanwhile. */
|
|
567
|
+
private editor() {
|
|
568
|
+
const draft = this.draft;
|
|
569
|
+
if (!draft) return null;
|
|
570
|
+
return html`<div data-site-editing ref=${(element: Element) => this.loadEditor(element)}>${this.editorReady && SiteEditor ? component(SiteEditor, {
|
|
571
|
+
draft, saving: this.saving,
|
|
572
|
+
onChange: (values: EditorValues, preview: boolean) => this.changeDraft(values, preview),
|
|
573
|
+
onSave: () => this.save(), onExit: () => this.exitEditing(), onReload: () => this.reloadDraft(),
|
|
574
|
+
onSearchMedia: (search: string) => this.searchDraftMedia(search),
|
|
575
|
+
onChooser: (chooser: MediaChooserState) => this.setChooser(chooser),
|
|
576
|
+
onPreviews: (previews: Record<string, MediaPreview>) => this.setPreviews(previews),
|
|
577
|
+
onNotes: (notes: Note[]) => this.setNotes(notes),
|
|
578
|
+
onDocumentChange: (key: string, blocks: EditorBlock[]) => this.changeDocument(key, blocks),
|
|
579
|
+
}) : html`<p role="status" class="fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded-full border border-border bg-background px-4 py-2 text-sm text-muted-foreground shadow-lg">${__('Loading the editor…')}</p>`}</div>`;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
render() {
|
|
583
|
+
if (this.kind === 'unavailable') return unavailable();
|
|
584
|
+
const theme = siteTheme(this.theme);
|
|
585
|
+
const context = themeContext(theme, { ...this.theme, data: { page: this.data }, editing: Boolean(this.draft), languages: this.languages, menus: this.menus, site: this.site ?? undefined }, (path, exact) => this.isActive(path, exact));
|
|
586
|
+
if (this.kind === 'entry' && this.entry && this.locked) return siteContent(this.locked === 'members' ? this.membersPrompt(theme, context) : this.passwordForm(theme, context), this.theme);
|
|
587
|
+
if (this.kind === 'entry' && this.entry) {
|
|
588
|
+
// In edit mode the content's blocks carry their document: the entry's own, or a pattern's, locked when the user may not change it.
|
|
589
|
+
const entry = this.draft ? { ...this.entry, content: tagDocument(this.entry.content, 'entry', false, new Map(this.draft.documents.filter(document => document.kind === 'pattern').map(document => [document.name, !document.editable]))) } : this.entry;
|
|
590
|
+
const page = siteContent(entryTemplate(theme, entry.collection, entry.template)({ ...context, entry: withContentFields(entry) }), this.theme);
|
|
591
|
+
// The editor sits outside the content root, which contains fixed elements; the taskbar is the layout's.
|
|
592
|
+
return this.draft ? html`${page}${this.editor()}` : page;
|
|
593
|
+
}
|
|
594
|
+
if (this.kind === 'home' || this.kind === 'list') {
|
|
595
|
+
const page = siteContent(archiveTemplate(theme, this.view)({ ...context, view: this.view }), this.theme);
|
|
596
|
+
return this.draft ? html`${page}${this.editor()}` : page;
|
|
597
|
+
}
|
|
598
|
+
if (this.kind === 'gone') return html`<section class="space-y-3 py-16 text-center">
|
|
599
|
+
<h1 class="text-3xl font-bold text-foreground">${__('Page removed')}</h1>
|
|
600
|
+
<p class="text-muted-foreground">${__('This page was removed and is not coming back.')}</p>
|
|
601
|
+
<a href="/" class="text-primary hover:underline">${__('Go to the home page')}</a>
|
|
602
|
+
</section>`;
|
|
603
|
+
return theme.notFound?.(context) ?? html`<section class="space-y-3 py-16 text-center">
|
|
604
|
+
<h1 class="text-3xl font-bold text-foreground">${__('Page not found')}</h1>
|
|
605
|
+
<p class="text-muted-foreground">${__('The page you are looking for does not exist.')}</p>
|
|
606
|
+
<a href="/" class="text-primary hover:underline">${__('Go to the home page')}</a>
|
|
607
|
+
</section>`;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Cossack, Page } from '@cossackframework/core';
|
|
2
|
+
import { feedResponse } from '#app/cms/feeds';
|
|
3
|
+
import { trackCrawler } from '#app/cms/traffic';
|
|
4
|
+
|
|
5
|
+
/** `/feed/atom`, `/feed/json`, `/feed/<collection>` and `/feed/<collection>/<format>`, with `?term=<slug>` on each. */
|
|
6
|
+
@Page({ transport: 'http' })
|
|
7
|
+
export default class FeedOf extends Cossack {
|
|
8
|
+
async get() {
|
|
9
|
+
trackCrawler(this.c, 'feed');
|
|
10
|
+
const path = this.c.req.param('rest') ?? '';
|
|
11
|
+
return feedResponse(this.c.get('cms'), this.c.req.raw, path.split('/').filter(Boolean));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Cossack, Page } from '@cossackframework/core';
|
|
2
|
+
import { feedResponse } from '#app/cms/feeds';
|
|
3
|
+
import { trackCrawler } from '#app/cms/traffic';
|
|
4
|
+
|
|
5
|
+
/** The posts feed as RSS 2.0, sized and filled by Settings → Reading; `/feed/atom`, `/feed/json` and other collections are beside it. */
|
|
6
|
+
@Page({ transport: 'http' })
|
|
7
|
+
export default class Feed extends Cossack {
|
|
8
|
+
async get() {
|
|
9
|
+
trackCrawler(this.c, 'feed');
|
|
10
|
+
return feedResponse(this.c.get('cms'), this.c.req.raw, []);
|
|
11
|
+
}
|
|
12
|
+
}
|