@cossackframework/cms 0.0.0 → 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 +145 -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 +114 -2
- 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,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO data of site pages: templated titles and descriptions, canonical URLs, social images,
|
|
3
|
+
* robots directives, language alternates and one JSON-LD graph (publisher, site, page,
|
|
4
|
+
* breadcrumbs, article or typed entity, author). Server-only; the page keeps the result in
|
|
5
|
+
* state and `seoHead()` turns it into tags.
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from 'hono';
|
|
8
|
+
import {
|
|
9
|
+
ARTICLE_TYPES, authorUrl, entryAuthors, mediaUrl, renderSeoTemplate, robotsDirectives, schemaGraph, schemaProperties, SCHEMA_PROPERTIES, TITLE_SEPARATORS, urlList,
|
|
10
|
+
type Block, type CollectionDefinition, type EntryView, type LanguageLink, type RecordShape, type SchemaAuthor, type SchemaBreadcrumb, type SchemaImage, type SchemaPage, type SchemaSite, type SiteSettings, type TermShape,
|
|
11
|
+
} from '@cossackframework/cms';
|
|
12
|
+
import { MAIN_SITE, type CmsFile, type CmsHost, type CmsUser, type NetworkSite } from '@cossackframework/cms/server';
|
|
13
|
+
import { siteUrl, type CmsBindings } from './index';
|
|
14
|
+
import type { SeoView } from './seo-head';
|
|
15
|
+
import { entryAncestors as ancestors, isMembersOnly, isProtected, localePrefix } from './site';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The site's own configured address: APP_URL for the main site, an added site's domain (see
|
|
19
|
+
* `siteUrl`). Without APP_URL, a request on the added site's own host gives its scheme and port,
|
|
20
|
+
* which `siteUrl` can only guess.
|
|
21
|
+
*/
|
|
22
|
+
function configuredOrigin(c: Context): string | undefined {
|
|
23
|
+
const bindings = c.env as CmsBindings | undefined;
|
|
24
|
+
const site = c.get?.('site' as never) as Pick<NetworkSite, 'id' | 'host'> | undefined;
|
|
25
|
+
const app = bindings?.APP_URL || env('APP_URL', '');
|
|
26
|
+
if (site && site.id !== MAIN_SITE && bindings) {
|
|
27
|
+
if (!app && site.host) {
|
|
28
|
+
const url = new URL(c.req.url);
|
|
29
|
+
if (url.host === site.host || url.hostname === site.host) return url.origin;
|
|
30
|
+
}
|
|
31
|
+
return siteUrl(bindings, site);
|
|
32
|
+
}
|
|
33
|
+
return app || undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether the request names this machine, where its Host header is the developer's own. */
|
|
37
|
+
function localRequest(c: Context): boolean {
|
|
38
|
+
const { hostname } = new URL(c.req.url);
|
|
39
|
+
return ['localhost', '127.0.0.1', '[::1]'].includes(hostname) || hostname.endsWith('.localhost');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The request's site address for pages it renders (canonical URLs, sitemaps, previews): the
|
|
44
|
+
* configured address, otherwise the request's origin.
|
|
45
|
+
*/
|
|
46
|
+
export function siteOrigin(c: Context): string {
|
|
47
|
+
return (configuredOrigin(c) || new URL(c.req.url).origin).replace(/\/+$/, '');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The site address for links that leave the request, in email: the configured address, or the
|
|
52
|
+
* request's origin only on this machine. Elsewhere the Host header is the client's to choose, so
|
|
53
|
+
* a link built from it could send a reader to someone else's site; null then, and no link.
|
|
54
|
+
*/
|
|
55
|
+
export function mailOrigin(c: Context): string | null {
|
|
56
|
+
const configured = configuredOrigin(c);
|
|
57
|
+
if (configured) return configured.replace(/\/+$/, '');
|
|
58
|
+
return localRequest(c) ? new URL(c.req.url).origin : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function absolute(origin: string, url: string): string {
|
|
62
|
+
return !url ? '' : /^https?:\/\//.test(url) ? url : `${origin}${url.startsWith('/') ? '' : '/'}${url}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function separator(settings: SiteSettings): string {
|
|
66
|
+
return TITLE_SEPARATORS[settings['seo.titleSeparator']] ?? '–';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function alternates(origin: string, links: readonly LanguageLink[]): SeoView['alternates'] {
|
|
70
|
+
if (!links.length) return [];
|
|
71
|
+
const fallback = links.find(link => link.code === links[0]!.code)!;
|
|
72
|
+
return [...links.map(link => ({ hreflang: link.code, href: absolute(origin, link.url) })), { hreflang: 'x-default', href: absolute(origin, fallback.url) }];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** An image for sharing and structured data: a media file, or a URL from the settings. */
|
|
76
|
+
function imageOf(origin: string, file: CmsFile | null | undefined, fallback: string): SchemaImage | null {
|
|
77
|
+
if (file && file.contentType.startsWith('image/')) return { url: absolute(origin, mediaUrl(file)), width: file.width, height: file.height, alt: file.alt };
|
|
78
|
+
return fallback ? { url: absolute(origin, fallback) } : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The media file an entry's SEO box or featured image names, if any. */
|
|
82
|
+
async function fileOf(cms: CmsHost, id: unknown): Promise<CmsFile | null> {
|
|
83
|
+
return typeof id === 'string' && id && cms.files ? cms.files.get(id) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** What the graph says about the site: who publishes it, with logo and profiles. */
|
|
87
|
+
async function schemaSite(cms: CmsHost, origin: string, settings: SiteSettings, locale: string): Promise<SchemaSite> {
|
|
88
|
+
const logo = settings['seo.logo'];
|
|
89
|
+
let image: SchemaImage | null = logo ? { url: absolute(origin, logo) } : null;
|
|
90
|
+
const match = /^\/media\/([^/]+)\//.exec(logo);
|
|
91
|
+
if (match && cms.files) image = imageOf(origin, await cms.files.get(match[1]!), logo);
|
|
92
|
+
return {
|
|
93
|
+
origin, name: settings['general.siteTitle'], tagline: settings['general.tagline'], locale, representation: settings['seo.representation'],
|
|
94
|
+
publisherName: settings['seo.publisherName'], logo: image, sameAs: urlList(settings['seo.sameAs']),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** An author as structured data: the owner's profile, linked to their page when author pages are on. */
|
|
99
|
+
function schemaAuthor(origin: string, user: CmsUser | undefined, settings: SiteSettings, prefix: string): SchemaAuthor | null {
|
|
100
|
+
if (!user) return null;
|
|
101
|
+
const meta = user.meta;
|
|
102
|
+
const page = settings['seo.authorPages'] ? authorUrl(user.slug, prefix) : null;
|
|
103
|
+
return {
|
|
104
|
+
name: user.name, url: page ? absolute(origin, page) : null, image: user.avatar ? absolute(origin, user.avatar) : null,
|
|
105
|
+
description: typeof meta.bio === 'string' ? meta.bio : '', jobTitle: typeof meta.jobTitle === 'string' ? meta.jobTitle : '',
|
|
106
|
+
website: typeof meta.website === 'string' && /^https?:\/\//.test(meta.website) ? meta.website : null, sameAs: urlList(meta.profiles),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Questions and answers blocks of an entry that asked for FAQPage markup. */
|
|
111
|
+
function faqOf(record: RecordShape): { question: string; answer: string }[] {
|
|
112
|
+
const found: { question: string; answer: string }[] = [];
|
|
113
|
+
const visit = (blocks: readonly Block[]) => {
|
|
114
|
+
for (const block of blocks) {
|
|
115
|
+
if (block.type === 'core/faq' && block.data.schema === true) {
|
|
116
|
+
for (const item of block.children ?? []) if (item.type === 'core/faq-item' && typeof item.data.question === 'string' && typeof item.data.answer === 'string') found.push({ question: item.data.question, answer: item.data.answer });
|
|
117
|
+
}
|
|
118
|
+
if (block.children) visit(block.children);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
for (const value of Object.values(record)) if (Array.isArray(value) && value.every(entry => entry && typeof entry === 'object' && 'type' in entry)) visit(value as Block[]);
|
|
122
|
+
return found;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Shared head data for any page kind. */
|
|
126
|
+
function base(origin: string, settings: SiteSettings, input: { title: string; ogTitle: string; ogDescription?: string; description: string; url: string; image: SchemaImage | null; robots: string; type: 'website' | 'article' | 'profile'; locale: string; links: readonly LanguageLink[]; graph: object | null; published?: string; modified?: string; markdownUrl?: string }): SeoView {
|
|
127
|
+
return {
|
|
128
|
+
title: input.title, ogTitle: input.ogTitle, ogDescription: input.ogDescription ?? input.description, description: input.description, canonical: input.url, image: input.image?.url ?? '', imageWidth: input.image?.width ?? null, imageHeight: input.image?.height ?? null, imageAlt: input.image?.alt ?? '',
|
|
129
|
+
robots: input.robots, type: input.type, siteName: settings['general.siteTitle'], locale: input.locale, twitterSite: settings['seo.twitter'] ? `@${settings['seo.twitter'].replace(/^@/, '')}` : '',
|
|
130
|
+
publishedTime: input.published ?? '', modifiedTime: input.modified ?? '', alternates: alternates(origin, input.links), jsonLd: input.graph ? JSON.stringify(input.graph).replace(/</g, '\\u003c') : '', markdownUrl: input.markdownUrl ?? '',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Directives shared by every page: the site hidden, and the image preview size. */
|
|
135
|
+
function siteRobots(settings: SiteSettings) {
|
|
136
|
+
return { hidden: settings['reading.discourageSearchEngines'], maxImagePreview: settings['seo.maxImagePreview'] };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Breadcrumbs of an entry: home, the collection's archive, then its ancestors; the entry itself is added by the graph. */
|
|
140
|
+
async function breadcrumbs(cms: CmsHost, origin: string, collection: CollectionDefinition, record: RecordShape, locale: string, prefix: string): Promise<SchemaBreadcrumb[]> {
|
|
141
|
+
const crumbs: SchemaBreadcrumb[] = [{ name: __('Home'), url: absolute(origin, prefix || '/') }];
|
|
142
|
+
const archive = collection.hierarchical ? null : await cms.archiveUrl(collection, locale).catch(() => null);
|
|
143
|
+
if (archive && archive !== (prefix || '/')) crumbs.push({ name: collection.label, url: absolute(origin, archive) });
|
|
144
|
+
if (collection.hierarchical) for (const ancestor of await ancestors(cms, collection, record)) crumbs.push({ name: ancestor.name, url: absolute(origin, ancestor.url) });
|
|
145
|
+
return crumbs;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The collection's mapped schema properties of a record, media resolved to absolute URLs. */
|
|
149
|
+
async function mappedProperties(cms: CmsHost, origin: string, collection: CollectionDefinition, record: RecordShape): Promise<{ [property: string]: unknown }> {
|
|
150
|
+
const schema = collection.schema;
|
|
151
|
+
if (!schema || !schema.map || !SCHEMA_PROPERTIES[schema.type].length) return {};
|
|
152
|
+
const fields = cms.resourceById(`cms/${collection.name}`).fields;
|
|
153
|
+
const mediaIds = Object.values(schema.map).flatMap(name => fields[name]?.media ? (Array.isArray(record[name]) ? record[name] as string[] : typeof record[name] === 'string' ? [record[name] as string] : []) : []);
|
|
154
|
+
const files = cms.files && mediaIds.length ? await cms.files.getMany(mediaIds) : new Map<string, CmsFile>();
|
|
155
|
+
return schemaProperties(schema, record, fields, { mediaUrl: id => { const file = files.get(id); return file ? absolute(origin, mediaUrl(file)) : null; } });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The terms of an entry as `about` things: each with its `sameAs` URL when the term's meta has one. */
|
|
159
|
+
async function aboutTerms(cms: CmsHost, collection: CollectionDefinition, record: RecordShape): Promise<{ name: string; sameAs?: string }[]> {
|
|
160
|
+
const ids = (collection.taxonomies ?? []).flatMap(name => Array.isArray(record[name]) ? record[name] as string[] : []);
|
|
161
|
+
if (!ids.length) return [];
|
|
162
|
+
const terms = await cms.taxonomies.getMany(ids);
|
|
163
|
+
return [...terms.values()].map((term: TermShape) => ({ name: term.name, ...(typeof term.meta.sameAs === 'string' && /^https?:\/\//.test(term.meta.sameAs) ? { sameAs: term.meta.sameAs } : {}) }));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** An entry page: its SEO box first, then the collection's and the site's templates and the entry's own values. */
|
|
167
|
+
export async function entrySeo(cms: CmsHost, c: Context, collection: CollectionDefinition, record: RecordShape, view: EntryView, links: readonly LanguageLink[]): Promise<SeoView> {
|
|
168
|
+
const settings = await cms.settings.all();
|
|
169
|
+
const origin = siteOrigin(c);
|
|
170
|
+
const languages = await cms.languages();
|
|
171
|
+
const prefix = localePrefix(languages, view.locale);
|
|
172
|
+
const sep = separator(settings);
|
|
173
|
+
const seo = (record.seo ?? {}) as { title?: string; description?: string; image?: string | null; canonical?: string; noindex?: boolean; nosnippet?: boolean; maxSnippet?: number | null; noarchive?: boolean; socialTitle?: string; socialDescription?: string };
|
|
174
|
+
// A locked entry's content stays out of the page: its summary, FAQ answers and mapped fields too.
|
|
175
|
+
const locked = view.locked !== null;
|
|
176
|
+
const summary = !locked && typeof record.summary === 'string' ? record.summary.trim() : '';
|
|
177
|
+
const url = absolute(origin, seo.canonical || view.url || '');
|
|
178
|
+
const type = collection.schema?.type ?? 'WebPage';
|
|
179
|
+
const article = ARTICLE_TYPES.has(type);
|
|
180
|
+
const published = typeof record.publishedAt === 'number' ? new Date(record.publishedAt).toISOString() : '';
|
|
181
|
+
const modified = new Date(record.updatedAt).toISOString();
|
|
182
|
+
const ids = entryAuthors(record);
|
|
183
|
+
const users = await cms.users.getMany(ids);
|
|
184
|
+
const authors = ids.map(id => schemaAuthor(origin, users.get(id), settings, prefix)).filter(author => author !== null);
|
|
185
|
+
const variables = { title: view.title, sep, site: settings['general.siteTitle'], tagline: settings['general.tagline'], excerpt: seo.description || summary || view.excerpt, author: authors.map(author => author.name).join(', '), collection: collection.label, date: view.date };
|
|
186
|
+
const title = renderSeoTemplate(collection.seoTemplates?.title || settings['seo.entryTitle'], { ...variables, title: seo.title || view.title });
|
|
187
|
+
const description = seo.description || renderSeoTemplate(collection.seoTemplates?.description || settings['seo.entryDescription'], variables);
|
|
188
|
+
const image = imageOf(origin, await fileOf(cms, seo.image), '') ?? (view.image ? { url: absolute(origin, view.image.url), width: view.image.width, height: view.image.height, alt: view.image.alt } : imageOf(origin, null, settings['seo.defaultImage']));
|
|
189
|
+
const robots = robotsDirectives({ ...siteRobots(settings), noindex: seo.noindex === true || collection.robots?.noindex === true, nofollow: collection.robots?.nofollow === true, nosnippet: seo.nosnippet === true, maxSnippet: seo.maxSnippet ?? null, noarchive: seo.noarchive === true });
|
|
190
|
+
const page: SchemaPage = {
|
|
191
|
+
kind: 'entry', url, title: seo.title || view.title, description, locale: view.locale, image, published, modified, type,
|
|
192
|
+
breadcrumbs: type === 'none' ? [] : await breadcrumbs(cms, origin, collection, record, view.locale, prefix),
|
|
193
|
+
properties: locked ? {} : await mappedProperties(cms, origin, collection, record), authors, about: type === 'none' ? [] : await aboutTerms(cms, collection, record),
|
|
194
|
+
keywords: view.terms.flatMap(group => group.terms.map(term => term.name)), section: view.terms[0]?.terms[0]?.name ?? '', abstract: summary, faq: type === 'none' || locked ? [] : faqOf(record),
|
|
195
|
+
};
|
|
196
|
+
return base(origin, settings, { title, ogTitle: seo.socialTitle || seo.title || view.title, ogDescription: seo.socialDescription || description, description, url, image, robots, type: article ? 'article' : type === 'Person' ? 'profile' : 'website', locale: view.locale, links, graph: schemaGraph(await schemaSite(cms, origin, settings, view.locale), page), published: article ? published : '', modified: article ? modified : '', markdownUrl: settings['seo.markdown'] && view.url && !isProtected(record) && !isMembersOnly(record) ? `${absolute(origin, view.url)}?format=md` : '' });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** A list page: an archive, a term archive or search results. */
|
|
200
|
+
export async function listSeo(cms: CmsHost, c: Context, input: { kind: 'archive' | 'term' | 'search'; title: string; description: string; url: string; locale: string; links: readonly LanguageLink[]; page?: number; noindex?: boolean; nofollow?: boolean; collection?: CollectionDefinition | null; term?: TermShape; taxonomy?: string; template?: string }): Promise<SeoView> {
|
|
201
|
+
const settings = await cms.settings.all();
|
|
202
|
+
const origin = siteOrigin(c);
|
|
203
|
+
const sep = separator(settings);
|
|
204
|
+
const page = input.page ?? 1;
|
|
205
|
+
const url = absolute(origin, page > 1 ? `${input.url}?page=${page}` : input.url);
|
|
206
|
+
const variables = { title: input.title, sep, site: settings['general.siteTitle'], tagline: settings['general.tagline'], term: input.term?.name ?? '', taxonomy: input.taxonomy ?? '', collection: input.collection?.label ?? '', page };
|
|
207
|
+
const template = input.template || (input.kind === 'term' ? settings['seo.termTitle'] : input.kind === 'search' ? '%title% %sep% %site%' : input.collection?.seoTemplates?.archiveTitle || settings['seo.archiveTitle']);
|
|
208
|
+
const title = renderSeoTemplate(template, variables);
|
|
209
|
+
const description = input.description || (input.kind === 'archive' && page === 1 ? settings['general.tagline'] : '');
|
|
210
|
+
const image = imageOf(origin, null, settings['seo.defaultImage']);
|
|
211
|
+
const robots = robotsDirectives({ ...siteRobots(settings), noindex: input.noindex === true, nofollow: input.nofollow === true });
|
|
212
|
+
const graph = schemaGraph(await schemaSite(cms, origin, settings, input.locale), { kind: input.kind, url, title: renderSeoTemplate('%title%', variables), description, locale: input.locale, image, breadcrumbs: [{ name: __('Home'), url: absolute(origin, '/') }] });
|
|
213
|
+
return base(origin, settings, { title, ogTitle: renderSeoTemplate('%title%', variables), description, url, image, robots, type: 'website', locale: input.locale, links: input.links, graph });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** An author's page: their profile as a `ProfilePage`. */
|
|
217
|
+
export async function authorSeo(cms: CmsHost, c: Context, input: { user: CmsUser; url: string; locale: string; links: readonly LanguageLink[]; page?: number }): Promise<SeoView> {
|
|
218
|
+
const settings = await cms.settings.all();
|
|
219
|
+
const origin = siteOrigin(c);
|
|
220
|
+
const languages = await cms.languages();
|
|
221
|
+
const page = input.page ?? 1;
|
|
222
|
+
const url = absolute(origin, page > 1 ? `${input.url}?page=${page}` : input.url);
|
|
223
|
+
const profile = schemaAuthor(origin, input.user, settings, localePrefix(languages, input.locale))!;
|
|
224
|
+
const title = renderSeoTemplate(settings['seo.authorTitle'], { author: input.user.name, sep: separator(settings), site: settings['general.siteTitle'], tagline: settings['general.tagline'], page });
|
|
225
|
+
const description = profile.description || `${__('Entries by')} ${input.user.name}`;
|
|
226
|
+
const image = profile.image ? { url: profile.image } : imageOf(origin, null, settings['seo.defaultImage']);
|
|
227
|
+
const graph = schemaGraph(await schemaSite(cms, origin, settings, input.locale), { kind: 'author', url, title: input.user.name, description, locale: input.locale, image, profile, breadcrumbs: [{ name: __('Home'), url: absolute(origin, '/') }] });
|
|
228
|
+
return base(origin, settings, { title, ogTitle: input.user.name, description, url, image, robots: robotsDirectives(siteRobots(settings)), type: 'profile', locale: input.locale, links: input.links, graph });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The home page. */
|
|
232
|
+
export async function homeSeo(cms: CmsHost, c: Context, input: { url: string; locale: string; links: readonly LanguageLink[]; page?: number }): Promise<SeoView> {
|
|
233
|
+
const settings = await cms.settings.all();
|
|
234
|
+
const origin = siteOrigin(c);
|
|
235
|
+
const page = input.page ?? 1;
|
|
236
|
+
const url = absolute(origin, page > 1 ? `${input.url}?page=${page}` : input.url);
|
|
237
|
+
const title = renderSeoTemplate(settings['seo.homeTitle'], { sep: separator(settings), site: settings['general.siteTitle'], tagline: settings['general.tagline'], page });
|
|
238
|
+
const image = imageOf(origin, null, settings['seo.defaultImage']);
|
|
239
|
+
const graph = schemaGraph(await schemaSite(cms, origin, settings, input.locale), { kind: 'home', url, title: settings['general.siteTitle'], description: settings['general.tagline'], locale: input.locale, image });
|
|
240
|
+
return base(origin, settings, { title, ogTitle: settings['general.siteTitle'], description: settings['general.tagline'], url, image, robots: robotsDirectives(siteRobots(settings)), type: 'website', locale: input.locale, links: input.links, graph });
|
|
241
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/** A client draft owned by the Settings layout, never a process-wide settings cache. */
|
|
2
|
+
import { Client, ClientState, createStore, Service, Shared } from '@cossackframework/core';
|
|
3
|
+
import { parseSettingsDocument, type SettingsDocument } from '@cossackframework/cms';
|
|
4
|
+
import type { SettingRow, SettingValue } from './settings-form';
|
|
5
|
+
|
|
6
|
+
export function settingsChanges(before: SettingsDocument, after: SettingsDocument): SettingsDocument {
|
|
7
|
+
const changes: SettingsDocument = {};
|
|
8
|
+
for (const [group, fields] of Object.entries(after)) {
|
|
9
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
10
|
+
if (!Object.hasOwn(before[group] ?? {}, name) || !Object.is(before[group]?.[name], value)) (changes[group] ??= {})[name] = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return changes;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function mergeSettings(before: SettingsDocument, patch: SettingsDocument): SettingsDocument {
|
|
17
|
+
const result: SettingsDocument = {};
|
|
18
|
+
for (const [group, fields] of Object.entries(before)) result[group] = { ...fields };
|
|
19
|
+
for (const [group, fields] of Object.entries(patch)) result[group] = { ...result[group], ...fields };
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Editor display is not an import/export operation; a site's full catalog can exceed file limits. */
|
|
24
|
+
export function formatSettingsDraft(document: SettingsDocument): string {
|
|
25
|
+
const sorted = Object.fromEntries(Object.keys(document).sort().map(group => [group,
|
|
26
|
+
Object.fromEntries(Object.keys(document[group]!).sort().map(name => [name, document[group]![name]]))]));
|
|
27
|
+
return `${JSON.stringify(sorted, null, 2)}\n`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// A click reaches the framework router in the same event turn. Clearing this marker in
|
|
31
|
+
// a task also handles canceled clicks, same-page links, and failed navigation. A
|
|
32
|
+
// microtask is too early: browsers checkpoint between native event listeners.
|
|
33
|
+
let settingsClick: object | undefined;
|
|
34
|
+
export function settingsNavigation(event: MouseEvent): void {
|
|
35
|
+
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
36
|
+
const anchor = event.currentTarget as HTMLAnchorElement;
|
|
37
|
+
if (anchor.target && anchor.target !== '_self' || anchor.hasAttribute('download')) return;
|
|
38
|
+
const url = new URL(anchor.href, window.location.href);
|
|
39
|
+
if (url.origin !== window.location.origin || !isSettingsPath(url.pathname)) return;
|
|
40
|
+
const marker = {};
|
|
41
|
+
settingsClick = marker;
|
|
42
|
+
setTimeout(() => { if (settingsClick === marker) settingsClick = undefined; }, 0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isSettingsPath(path: string): boolean { return path === '/dashboard/settings' || path.startsWith('/dashboard/settings/'); }
|
|
46
|
+
|
|
47
|
+
export interface SettingsPreview { before: SettingsDocument; after: SettingsDocument; patch: SettingsDocument; imported: boolean }
|
|
48
|
+
|
|
49
|
+
@Service()
|
|
50
|
+
export class SettingsDraft {
|
|
51
|
+
@ClientState() initialized = false;
|
|
52
|
+
@ClientState() baseline: SettingsDocument = {};
|
|
53
|
+
@ClientState() values: SettingsDocument = {};
|
|
54
|
+
@ClientState() rawJson = '';
|
|
55
|
+
@ClientState() jsonError = '';
|
|
56
|
+
@ClientState() controls: Record<string, SettingValue> = {};
|
|
57
|
+
@ClientState() errors: Record<string, string> = {};
|
|
58
|
+
@ClientState() baselineErrors: Record<string, string> = {};
|
|
59
|
+
@ClientState() jsonEdited = false;
|
|
60
|
+
@ClientState() preview: SettingsPreview | null = null;
|
|
61
|
+
@ClientState() search = '';
|
|
62
|
+
@ClientState() saving = false;
|
|
63
|
+
@ClientState() toolbarHeight = 56;
|
|
64
|
+
/** Invalidates pending controls when the whole document is replaced or discarded. */
|
|
65
|
+
@ClientState() epoch = 0;
|
|
66
|
+
/** Counts the toolbar's discards, so the page can clear what the last save reported. */
|
|
67
|
+
@ClientState() discards = 0;
|
|
68
|
+
@ClientState() sections: Record<string, unknown> = {};
|
|
69
|
+
@ClientState() sectionBaselines: Record<string, unknown> = {};
|
|
70
|
+
private pathname = '';
|
|
71
|
+
private changesStore = createStore(0);
|
|
72
|
+
|
|
73
|
+
@Client()
|
|
74
|
+
subscribe(listener: () => void): () => void { return this.changesStore.subscribe(listener); }
|
|
75
|
+
|
|
76
|
+
@Client()
|
|
77
|
+
changed(): void { this.changesStore.update(revision => revision + 1); }
|
|
78
|
+
|
|
79
|
+
@Client()
|
|
80
|
+
setSearch(search: string): void { this.search = search; this.changed(); }
|
|
81
|
+
|
|
82
|
+
@Client()
|
|
83
|
+
setSaving(saving: boolean): void { if (saving && !this.saving) this.epoch++; this.saving = saving; this.changed(); }
|
|
84
|
+
|
|
85
|
+
@Client()
|
|
86
|
+
setToolbarHeight(height: number): void { if (height !== this.toolbarHeight) { this.toolbarHeight = height; this.changed(); } }
|
|
87
|
+
|
|
88
|
+
@Shared()
|
|
89
|
+
section<T>(key: string, initial: T): T { return Object.hasOwn(this.sections, key) ? this.sections[key] as T : initial; }
|
|
90
|
+
|
|
91
|
+
@Client()
|
|
92
|
+
initializeSection<T>(key: string, initial: T): void { if (!Object.hasOwn(this.sections, key)) this.acceptSection(key, initial); }
|
|
93
|
+
|
|
94
|
+
@Client()
|
|
95
|
+
setSection<T>(key: string, value: T): void { this.sections = { ...this.sections, [key]: structuredClone(value) }; this.changed(); }
|
|
96
|
+
|
|
97
|
+
@Client()
|
|
98
|
+
acceptSection<T>(key: string, value: T): void {
|
|
99
|
+
this.sectionBaselines = { ...this.sectionBaselines, [key]: structuredClone(value) };
|
|
100
|
+
this.setSection(key, value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Client()
|
|
104
|
+
discardSection(key: string): void { if (Object.hasOwn(this.sectionBaselines, key)) this.setSection(key, this.sectionBaselines[key]); }
|
|
105
|
+
|
|
106
|
+
@Shared()
|
|
107
|
+
sectionDirty(key: string): boolean { return JSON.stringify(this.sections[key]) !== JSON.stringify(this.sectionBaselines[key]); }
|
|
108
|
+
|
|
109
|
+
@Client()
|
|
110
|
+
setPreview(preview: SettingsPreview | null): void { this.preview = preview; this.changed(); }
|
|
111
|
+
|
|
112
|
+
@Client()
|
|
113
|
+
initialize(document: SettingsDocument, errors: Record<string, string> = {}): void {
|
|
114
|
+
if (!this.initialized) { this.accept(document); this.errors = { ...errors }; this.baselineErrors = { ...errors }; this.changed(); }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Client()
|
|
118
|
+
accept(document: SettingsDocument): void {
|
|
119
|
+
this.epoch++;
|
|
120
|
+
this.baseline = mergeSettings({}, document);
|
|
121
|
+
this.values = mergeSettings({}, document);
|
|
122
|
+
this.rawJson = formatSettingsDraft(document);
|
|
123
|
+
this.jsonError = '';
|
|
124
|
+
this.controls = {};
|
|
125
|
+
this.errors = {};
|
|
126
|
+
this.baselineErrors = {};
|
|
127
|
+
this.jsonEdited = false;
|
|
128
|
+
this.preview = null;
|
|
129
|
+
this.initialized = true;
|
|
130
|
+
this.changed();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@Client()
|
|
134
|
+
discard(): void {
|
|
135
|
+
const errors = this.baselineErrors;
|
|
136
|
+
this.accept(this.baseline);
|
|
137
|
+
this.baselineErrors = errors;
|
|
138
|
+
this.errors = { ...errors };
|
|
139
|
+
this.sections = structuredClone(this.sectionBaselines);
|
|
140
|
+
this.discards++;
|
|
141
|
+
this.changed();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@Shared()
|
|
145
|
+
hasInvalidControls(): boolean { return Object.keys(this.errors).some(key => !Object.hasOwn(this.baselineErrors, key)); }
|
|
146
|
+
|
|
147
|
+
@Shared()
|
|
148
|
+
changes(): SettingsDocument { return settingsChanges(this.baseline, this.values); }
|
|
149
|
+
|
|
150
|
+
@Shared()
|
|
151
|
+
documentDirty(): boolean { return !!this.jsonError || this.hasInvalidControls() || Object.keys(this.changes()).length > 0 || !!this.preview && Object.keys(this.preview.patch).length > 0; }
|
|
152
|
+
|
|
153
|
+
@Shared()
|
|
154
|
+
dirty(): boolean { return this.documentDirty() || Object.keys(this.sections).some(key => this.sectionDirty(key)); }
|
|
155
|
+
|
|
156
|
+
@Shared()
|
|
157
|
+
control(row: SettingRow, fallback?: SettingValue): SettingValue | undefined {
|
|
158
|
+
const key = `${row.namespace}.${row.name}`;
|
|
159
|
+
if (Object.hasOwn(this.controls, key)) return this.controls[key];
|
|
160
|
+
if (!Object.hasOwn(this.values[row.namespace] ?? {}, row.name)) return fallback;
|
|
161
|
+
const value = this.values[row.namespace]![row.name];
|
|
162
|
+
return typeof value === 'number' ? String(value) : value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Client()
|
|
166
|
+
set(row: SettingRow, value: SettingValue): void {
|
|
167
|
+
if (this.jsonError || this.preview?.imported) return;
|
|
168
|
+
this.preview = null;
|
|
169
|
+
const key = `${row.namespace}.${row.name}`;
|
|
170
|
+
this.controls = { ...this.controls, [key]: value };
|
|
171
|
+
const errors = { ...this.errors };
|
|
172
|
+
delete errors[key];
|
|
173
|
+
let typed: string | number | boolean | null = value;
|
|
174
|
+
if (value !== null && (row.kind === 'number' || row.kind === 'integer')) {
|
|
175
|
+
typed = Number(value);
|
|
176
|
+
if (typeof value !== 'string' || value.trim() === '' || !Number.isFinite(typed)) errors[key] = 'must be a number.';
|
|
177
|
+
} else if (typeof value === 'string' && row.kind !== 'text') typed = value.trim();
|
|
178
|
+
this.errors = errors;
|
|
179
|
+
if (errors[key]) { this.changed(); return; }
|
|
180
|
+
this.values = mergeSettings(this.values, { [row.namespace]: { [row.name]: typed } });
|
|
181
|
+
this.rawJson = formatSettingsDraft(this.values);
|
|
182
|
+
this.jsonEdited = false;
|
|
183
|
+
this.changed();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@Client()
|
|
187
|
+
editJson(text: string): void {
|
|
188
|
+
this.epoch++;
|
|
189
|
+
this.rawJson = text;
|
|
190
|
+
this.jsonEdited = true;
|
|
191
|
+
this.preview = null;
|
|
192
|
+
try {
|
|
193
|
+
const patch = parseSettingsDocument(text);
|
|
194
|
+
this.values = mergeSettings(this.baseline, patch);
|
|
195
|
+
this.controls = {};
|
|
196
|
+
this.errors = {};
|
|
197
|
+
this.jsonError = '';
|
|
198
|
+
} catch (error) {
|
|
199
|
+
this.jsonError = error instanceof Error ? error.message : 'Enter valid settings JSON.';
|
|
200
|
+
}
|
|
201
|
+
this.changed();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
@Client()
|
|
205
|
+
navigated(pathname: string): void { this.pathname = pathname; }
|
|
206
|
+
|
|
207
|
+
@Client()
|
|
208
|
+
preventNavigation(): boolean {
|
|
209
|
+
const internalClick = settingsClick !== undefined;
|
|
210
|
+
settingsClick = undefined;
|
|
211
|
+
const historyWithinSettings = this.pathname !== window.location.pathname && isSettingsPath(window.location.pathname);
|
|
212
|
+
if (internalClick || historyWithinSettings || !this.dirty()) return false;
|
|
213
|
+
return !window.confirm(__('Leave Settings? Your changes are not saved.'));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@Shared()
|
|
217
|
+
onDispose(): void { settingsClick = undefined; }
|
|
218
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** A scalar URL setting backed by the dashboard's existing media library and upload pipeline. */
|
|
2
|
+
import { Client, ClientState, Component, Cossack } from '@cossackframework/core';
|
|
3
|
+
import type { FieldMediaKind } from '@cossackframework/cms';
|
|
4
|
+
import { Button, Input, type FieldControlAttributes } from '@cossackframework/ui';
|
|
5
|
+
import { component, html } from '@cossackframework/renderer';
|
|
6
|
+
import type { MediaPreview } from './field-controls';
|
|
7
|
+
import { closedChooser, mediaChooser, uploadFile, type MediaChooserState } from './media-chooser';
|
|
8
|
+
import { notice } from './ui';
|
|
9
|
+
|
|
10
|
+
export interface SettingsMedia {
|
|
11
|
+
find(search: string, kind: string): Promise<MediaPreview[]>;
|
|
12
|
+
canUpload: boolean;
|
|
13
|
+
/** Changes when the owner discards or replaces its draft, even if this value stays equal. */
|
|
14
|
+
epoch?(): unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SettingsFileProps = {
|
|
18
|
+
attributes: FieldControlAttributes;
|
|
19
|
+
label: string;
|
|
20
|
+
value: string;
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
kinds?: readonly FieldMediaKind[];
|
|
23
|
+
media?: SettingsMedia;
|
|
24
|
+
onChange(value: string): void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
@Component()
|
|
28
|
+
export class SettingsFile extends Cossack {
|
|
29
|
+
declare props: SettingsFileProps;
|
|
30
|
+
@ClientState() private chooser: MediaChooserState = closedChooser();
|
|
31
|
+
@ClientState() private error = '';
|
|
32
|
+
@ClientState() private uploading = false;
|
|
33
|
+
private request = 0;
|
|
34
|
+
private uploadAbort?: AbortController;
|
|
35
|
+
private destroyed = false;
|
|
36
|
+
|
|
37
|
+
onCleanup() { this.destroyed = true; this.request++; this.uploadAbort?.abort(); }
|
|
38
|
+
|
|
39
|
+
@Client()
|
|
40
|
+
async open() {
|
|
41
|
+
if (this.props.disabled || !this.props.media) return;
|
|
42
|
+
this.error = '';
|
|
43
|
+
this.chooser = { ...closedChooser(), open: true, field: this.props.attributes.id, kind: this.props.kinds?.[0] ?? '',
|
|
44
|
+
accept: '', canUpload: this.props.media.canUpload, uploadMultiple: false };
|
|
45
|
+
await this.search('');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Client()
|
|
49
|
+
close() { this.request++; this.chooser = { ...this.chooser, open: false }; }
|
|
50
|
+
|
|
51
|
+
@Client()
|
|
52
|
+
async search(search: string) {
|
|
53
|
+
if (!this.props.media) return;
|
|
54
|
+
const request = ++this.request;
|
|
55
|
+
this.chooser = { ...this.chooser, search, error: '' };
|
|
56
|
+
try {
|
|
57
|
+
const items = await this.props.media.find(search, this.chooser.kind);
|
|
58
|
+
if (request === this.request && !this.destroyed) this.chooser = { ...this.chooser, items };
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (request === this.request && !this.destroyed) this.chooser = { ...this.chooser, error: error instanceof Error ? error.message : __('The media library could not be loaded.') };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Client()
|
|
65
|
+
async filter(kind: string) {
|
|
66
|
+
this.chooser = { ...this.chooser, kind };
|
|
67
|
+
await this.search(this.chooser.search);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Client()
|
|
71
|
+
choose(file: MediaPreview) {
|
|
72
|
+
if (this.props.disabled) return;
|
|
73
|
+
this.props.onChange(file.url);
|
|
74
|
+
this.close();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Client()
|
|
78
|
+
async upload(event: Event) {
|
|
79
|
+
const input = event.currentTarget as HTMLInputElement;
|
|
80
|
+
const file = input.files?.[0];
|
|
81
|
+
input.value = '';
|
|
82
|
+
if (!file || this.uploading || this.props.disabled || !this.props.media?.canUpload) return;
|
|
83
|
+
this.error = '';
|
|
84
|
+
const epoch = this.props.media.epoch?.();
|
|
85
|
+
const original = this.props.value;
|
|
86
|
+
const id = this.props.attributes.id;
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
this.uploadAbort = controller;
|
|
89
|
+
this.uploading = true;
|
|
90
|
+
this.chooser = { ...this.chooser, busy: true, error: '' };
|
|
91
|
+
try {
|
|
92
|
+
const uploaded = await uploadFile(file, controller.signal);
|
|
93
|
+
if (!this.destroyed && !this.props.disabled && this.props.attributes.id === id && this.props.value === original && this.props.media?.epoch?.() === epoch) {
|
|
94
|
+
this.props.onChange(uploaded.url);
|
|
95
|
+
this.close();
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (!controller.signal.aborted && !this.destroyed && this.props.attributes.id === id && this.props.value === original && this.props.media?.epoch?.() === epoch) {
|
|
99
|
+
this.error = error instanceof Error ? error.message : __('The upload failed.');
|
|
100
|
+
this.chooser = { ...this.chooser, error: this.error };
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
this.uploadAbort = undefined;
|
|
104
|
+
this.uploading = false;
|
|
105
|
+
this.chooser = { ...this.chooser, busy: false };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
render() {
|
|
110
|
+
const { attributes, label, value, disabled, media } = this.props;
|
|
111
|
+
return html`<div class="space-y-2">
|
|
112
|
+
${component(Input, { ...attributes, type: 'text', disabled, placeholder: '/media/…', '.value': value,
|
|
113
|
+
'@input': (event: Event) => this.props.onChange((event.target as HTMLInputElement).value) })}
|
|
114
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
115
|
+
${media ? component(Button, { type: 'button', size: 'sm', variant: 'outline', disabled: disabled || this.uploading, '@click': this.open }, __('Choose file')) : null}
|
|
116
|
+
${media?.canUpload ? html`<label class=${`relative inline-flex items-center rounded-md border border-border px-3 py-1.5 text-sm text-foreground hover:bg-muted focus-within:ring-2 focus-within:ring-ring ${disabled || this.uploading ? 'opacity-50' : 'cursor-pointer'}`}>
|
|
117
|
+
${this.uploading ? __('Uploading…') : __('Upload file')}
|
|
118
|
+
<input id=${`${attributes.id}-upload`} type="file" aria-label=${`${__('Upload file')}: ${label}`}
|
|
119
|
+
class="absolute inset-0 w-full cursor-pointer opacity-0" ?disabled=${disabled || this.uploading} @change=${this.upload}>
|
|
120
|
+
</label>` : null}
|
|
121
|
+
${value ? component(Button, { type: 'button', size: 'sm', variant: 'ghost', disabled, 'aria-label': `${__('Clear file')}: ${label}`, '@click': () => this.props.onChange('') }, __('Clear')) : null}
|
|
122
|
+
</div>
|
|
123
|
+
${this.error && !this.chooser.open ? notice(this.error, 'error') : null}
|
|
124
|
+
${this.chooser.open ? mediaChooser(this.chooser, { search: this.search, filter: this.filter, choose: this.choose, upload: this.upload, close: this.close }) : null}
|
|
125
|
+
</div>`;
|
|
126
|
+
}
|
|
127
|
+
}
|