@basicbenframework/cms 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +206 -2
- package/db/migrations/001_create_users.js +15 -0
- package/db/migrations/002_create_posts.js +18 -0
- package/db/migrations/003_create_categories.js +19 -0
- package/db/migrations/004_create_tags.js +16 -0
- package/db/migrations/005_create_post_tags.js +16 -0
- package/db/migrations/006_create_pages.js +26 -0
- package/db/migrations/007_create_comments.js +24 -0
- package/db/migrations/008_create_media.js +22 -0
- package/db/migrations/009_update_posts_blogging.js +27 -0
- package/db/migrations/010_create_settings.js +29 -0
- package/db/migrations/011_add_user_roles.js +23 -0
- package/db/migrations/012_create_auth_tokens.js +30 -0
- package/db/migrations/013_add_email_verified.js +24 -0
- package/db/migrations/014_create_user_two_factor.js +30 -0
- package/db/migrations/015_create_user_credentials.js +35 -0
- package/db/migrations/016_create_rate_limits.js +31 -0
- package/db/migrations/017_add_content_html.js +38 -0
- package/db/migrations/018_create_api_tokens.js +34 -0
- package/db/migrations/019_create_post_categories.js +40 -0
- package/db/migrations/020_add_author_profiles.js +60 -0
- package/db/migrations/021_add_page_featured_image.js +23 -0
- package/db/migrations/022_backfill_post_slugs_and_excerpts.js +57 -0
- package/db/migrations/023_add_user_session_controls.js +25 -0
- package/db/migrations/024_add_post_status_and_trash.js +45 -0
- package/db/migrations/025_add_social_and_indexing_fields.js +40 -0
- package/db/migrations/026_create_post_revisions.js +29 -0
- package/db/migrations/027_add_media_dimensions.js +19 -0
- package/db/migrations/028_create_navigation_menus.js +65 -0
- package/db/migrations/029_create_redirects.js +40 -0
- package/db/migrations/030_add_comment_status_and_notifications.js +53 -0
- package/db/migrations/031_create_post_locks.js +38 -0
- package/db/migrations/032_create_snippets.js +31 -0
- package/db/migrations/033_create_members.js +70 -0
- package/db/migrations/034_add_post_visibility.js +28 -0
- package/db/migrations/035_create_newsletters.js +72 -0
- package/db/migrations/036_create_analytics.js +89 -0
- package/db/migrations/037_create_ops_heartbeats.js +30 -0
- package/db/migrations/038_create_content_types.js +84 -0
- package/db/migrations/039_create_content_type_fields.js +47 -0
- package/db/migrations/040_create_taxonomies.js +80 -0
- package/db/migrations/041_add_newsletter_handoff.js +28 -0
- package/db/migrations/042_create_mysendbox_contacts.js +63 -0
- package/lib/cli/backup.d.mts +2 -0
- package/lib/cli/backup.mjs +124 -0
- package/lib/cli/export.d.mts +2 -0
- package/lib/cli/export.mjs +54 -0
- package/lib/cli/import-ghost.d.mts +2 -0
- package/lib/cli/import-ghost.mjs +50 -0
- package/lib/cli/import-json.d.mts +2 -0
- package/lib/cli/import-json.mjs +61 -0
- package/lib/cli/import-wordpress.d.mts +2 -0
- package/lib/cli/import-wordpress.mjs +169 -0
- package/lib/cli/import-wxr.d.mts +2 -0
- package/lib/cli/import-wxr.mjs +55 -0
- package/lib/cli/index.d.mts +2 -0
- package/lib/cli/index.mjs +53 -0
- package/lib/cli/lib/backup.d.mts +112 -0
- package/lib/cli/lib/backup.mjs +297 -0
- package/lib/cli/lib/ghost.d.mts +30 -0
- package/lib/cli/lib/ghost.mjs +201 -0
- package/lib/cli/lib/html-to-markdown.d.mts +61 -0
- package/lib/cli/lib/html-to-markdown.mjs +523 -0
- package/lib/cli/lib/import-common.d.mts +100 -0
- package/lib/cli/lib/import-common.mjs +252 -0
- package/lib/cli/lib/json-import.d.mts +22 -0
- package/lib/cli/lib/json-import.mjs +422 -0
- package/lib/cli/lib/site-import.d.mts +32 -0
- package/lib/cli/lib/site-import.mjs +456 -0
- package/lib/cli/lib/wordpress-rest.d.mts +25 -0
- package/lib/cli/lib/wordpress-rest.mjs +177 -0
- package/lib/cli/lib/wxr.d.mts +18 -0
- package/lib/cli/lib/wxr.mjs +307 -0
- package/lib/cli/lib/xml.d.mts +33 -0
- package/lib/cli/lib/xml.mjs +186 -0
- package/lib/cli/restore.d.mts +2 -0
- package/lib/cli/restore.mjs +98 -0
- package/lib/client/components/Alert.d.ts +7 -0
- package/lib/client/components/Alert.js +8 -0
- package/lib/client/components/Avatar.d.ts +15 -0
- package/lib/client/components/Avatar.js +10 -0
- package/lib/client/components/BackLink.d.ts +7 -0
- package/lib/client/components/BackLink.js +6 -0
- package/lib/client/components/Button.d.ts +7 -0
- package/lib/client/components/Button.js +12 -0
- package/lib/client/components/Card.d.ts +7 -0
- package/lib/client/components/Card.js +6 -0
- package/lib/client/components/CommentThread.d.ts +15 -0
- package/lib/client/components/CommentThread.js +101 -0
- package/lib/client/components/Empty.d.ts +6 -0
- package/lib/client/components/Empty.js +6 -0
- package/lib/client/components/Input.d.ts +6 -0
- package/lib/client/components/Input.js +6 -0
- package/lib/client/components/Link.d.ts +31 -0
- package/lib/client/components/Link.js +49 -0
- package/lib/client/components/Loading.d.ts +1 -0
- package/lib/client/components/Loading.js +6 -0
- package/lib/client/components/Logo.d.ts +5 -0
- package/lib/client/components/Logo.js +4 -0
- package/lib/client/components/MarkdownEditor.d.ts +41 -0
- package/lib/client/components/MarkdownEditor.js +156 -0
- package/lib/client/components/Nav/DarkModeToggle.d.ts +6 -0
- package/lib/client/components/Nav/DarkModeToggle.js +6 -0
- package/lib/client/components/Nav/DesktopNav.d.ts +8 -0
- package/lib/client/components/Nav/DesktopNav.js +9 -0
- package/lib/client/components/Nav/MobileNav.d.ts +9 -0
- package/lib/client/components/Nav/MobileNav.js +15 -0
- package/lib/client/components/NavLink.d.ts +8 -0
- package/lib/client/components/NavLink.js +6 -0
- package/lib/client/components/PageHeader.d.ts +8 -0
- package/lib/client/components/PageHeader.js +6 -0
- package/lib/client/components/PostCard.d.ts +8 -0
- package/lib/client/components/PostCard.js +7 -0
- package/lib/client/components/Textarea.d.ts +6 -0
- package/lib/client/components/Textarea.js +6 -0
- package/lib/client/components/ThemeContext.d.ts +18 -0
- package/lib/client/components/ThemeContext.js +8 -0
- package/lib/client/components/admin/AdminIcons.d.ts +13 -0
- package/lib/client/components/admin/AdminIcons.js +66 -0
- package/lib/client/components/admin/ContentModelPanels.d.ts +22 -0
- package/lib/client/components/admin/ContentModelPanels.js +93 -0
- package/lib/client/components/admin/FeaturedImageBox.d.ts +21 -0
- package/lib/client/components/admin/FeaturedImageBox.js +24 -0
- package/lib/client/components/admin/MediaGrid.d.ts +23 -0
- package/lib/client/components/admin/MediaGrid.js +69 -0
- package/lib/client/components/admin/MediaPicker.d.ts +17 -0
- package/lib/client/components/admin/MediaPicker.js +61 -0
- package/lib/client/components/admin/Pagination.d.ts +27 -0
- package/lib/client/components/admin/Pagination.js +29 -0
- package/lib/client/components/admin/SnippetPicker.d.ts +27 -0
- package/lib/client/components/admin/SnippetPicker.js +65 -0
- package/lib/client/components/admin/TermPicker.d.ts +52 -0
- package/lib/client/components/admin/TermPicker.js +58 -0
- package/lib/client/contexts/ToastContext.d.ts +12 -0
- package/lib/client/contexts/ToastContext.js +49 -0
- package/lib/client/features.d.ts +11 -0
- package/lib/client/features.js +7 -0
- package/lib/client/hooks/useContentTypes.d.ts +48 -0
- package/lib/client/hooks/useContentTypes.js +48 -0
- package/lib/client/hooks/useMediaLibrary.d.ts +46 -0
- package/lib/client/hooks/useMediaLibrary.js +189 -0
- package/lib/client/hooks/usePostLock.d.ts +32 -0
- package/lib/client/hooks/usePostLock.js +107 -0
- package/lib/client/host/index.d.ts +71 -0
- package/lib/client/host/index.js +58 -0
- package/lib/client/i18n/index.d.ts +79 -0
- package/lib/client/i18n/index.js +177 -0
- package/lib/client/i18n/locales/es/content.d.ts +4 -0
- package/lib/client/i18n/locales/es/content.js +220 -0
- package/lib/client/i18n/locales/es/editor.d.ts +9 -0
- package/lib/client/i18n/locales/es/editor.js +144 -0
- package/lib/client/i18n/locales/es/index.d.ts +8 -0
- package/lib/client/i18n/locales/es/index.js +7 -0
- package/lib/client/i18n/locales/es/layout.d.ts +4 -0
- package/lib/client/i18n/locales/es/layout.js +35 -0
- package/lib/client/i18n/locales/es/people.d.ts +4 -0
- package/lib/client/i18n/locales/es/people.js +187 -0
- package/lib/client/i18n/locales/es/site.d.ts +4 -0
- package/lib/client/i18n/locales/es/site.js +208 -0
- package/lib/client/layouts/AdminLayout.d.ts +7 -0
- package/lib/client/layouts/AdminLayout.js +1046 -0
- package/lib/client/layouts/AppLayout.d.ts +6 -0
- package/lib/client/layouts/AppLayout.js +19 -0
- package/lib/client/layouts/AuthLayout.d.ts +6 -0
- package/lib/client/layouts/AuthLayout.js +14 -0
- package/lib/client/layouts/DocsLayout.d.ts +6 -0
- package/lib/client/layouts/DocsLayout.js +28 -0
- package/lib/client/layouts/RootLayout.d.ts +6 -0
- package/lib/client/layouts/RootLayout.js +11 -0
- package/lib/client/pages/AcceptInvite.d.ts +8 -0
- package/lib/client/pages/AcceptInvite.js +60 -0
- package/lib/client/pages/Auth.d.ts +1 -0
- package/lib/client/pages/Auth.js +40 -0
- package/lib/client/pages/Authentication.d.ts +1 -0
- package/lib/client/pages/Authentication.js +230 -0
- package/lib/client/pages/Content.d.ts +1 -0
- package/lib/client/pages/Content.js +21 -0
- package/lib/client/pages/Database.d.ts +1 -0
- package/lib/client/pages/Database.js +264 -0
- package/lib/client/pages/Extending.d.ts +1 -0
- package/lib/client/pages/Extending.js +28 -0
- package/lib/client/pages/Feed.d.ts +1 -0
- package/lib/client/pages/Feed.js +19 -0
- package/lib/client/pages/FeedPost.d.ts +1 -0
- package/lib/client/pages/FeedPost.js +31 -0
- package/lib/client/pages/ForgotPassword.d.ts +8 -0
- package/lib/client/pages/ForgotPassword.js +38 -0
- package/lib/client/pages/GettingStarted.d.ts +1 -0
- package/lib/client/pages/GettingStarted.js +84 -0
- package/lib/client/pages/Headless.d.ts +1 -0
- package/lib/client/pages/Headless.js +49 -0
- package/lib/client/pages/Home.d.ts +1 -0
- package/lib/client/pages/Home.js +67 -0
- package/lib/client/pages/PostForm.d.ts +1 -0
- package/lib/client/pages/PostForm.js +55 -0
- package/lib/client/pages/Posts.d.ts +1 -0
- package/lib/client/pages/Posts.js +35 -0
- package/lib/client/pages/Profile.d.ts +1 -0
- package/lib/client/pages/Profile.js +153 -0
- package/lib/client/pages/ResetPassword.d.ts +8 -0
- package/lib/client/pages/ResetPassword.js +52 -0
- package/lib/client/pages/Routing.d.ts +1 -0
- package/lib/client/pages/Routing.js +192 -0
- package/lib/client/pages/Storage.d.ts +1 -0
- package/lib/client/pages/Storage.js +54 -0
- package/lib/client/pages/Testing.d.ts +1 -0
- package/lib/client/pages/Testing.js +141 -0
- package/lib/client/pages/Validation.d.ts +1 -0
- package/lib/client/pages/Validation.js +123 -0
- package/lib/client/pages/admin/Categories.d.ts +2 -0
- package/lib/client/pages/admin/Categories.js +75 -0
- package/lib/client/pages/admin/Comments.d.ts +11 -0
- package/lib/client/pages/admin/Comments.js +247 -0
- package/lib/client/pages/admin/ContentTypes.d.ts +2 -0
- package/lib/client/pages/admin/ContentTypes.js +163 -0
- package/lib/client/pages/admin/Dashboard.d.ts +2 -0
- package/lib/client/pages/admin/Dashboard.js +66 -0
- package/lib/client/pages/admin/Health.d.ts +12 -0
- package/lib/client/pages/admin/Health.js +148 -0
- package/lib/client/pages/admin/Media.d.ts +2 -0
- package/lib/client/pages/admin/Media.js +101 -0
- package/lib/client/pages/admin/Navigation.d.ts +9 -0
- package/lib/client/pages/admin/Navigation.js +230 -0
- package/lib/client/pages/admin/Pages.d.ts +2 -0
- package/lib/client/pages/admin/Pages.js +53 -0
- package/lib/client/pages/admin/PostEditor.d.ts +17 -0
- package/lib/client/pages/admin/PostEditor.js +532 -0
- package/lib/client/pages/admin/Posts.d.ts +2 -0
- package/lib/client/pages/admin/Posts.js +152 -0
- package/lib/client/pages/admin/Redirects.d.ts +10 -0
- package/lib/client/pages/admin/Redirects.js +87 -0
- package/lib/client/pages/admin/Settings.d.ts +2 -0
- package/lib/client/pages/admin/Settings.js +111 -0
- package/lib/client/pages/admin/Snippets.d.ts +14 -0
- package/lib/client/pages/admin/Snippets.js +85 -0
- package/lib/client/pages/admin/Tags.d.ts +2 -0
- package/lib/client/pages/admin/Tags.js +74 -0
- package/lib/client/pages/admin/Taxonomies.d.ts +2 -0
- package/lib/client/pages/admin/Taxonomies.js +130 -0
- package/lib/client/pages/admin/Tokens.d.ts +9 -0
- package/lib/client/pages/admin/Tokens.js +260 -0
- package/lib/client/pages/admin/Tools.d.ts +12 -0
- package/lib/client/pages/admin/Tools.js +111 -0
- package/lib/client/pages/admin/Users.d.ts +13 -0
- package/lib/client/pages/admin/Users.js +313 -0
- package/lib/client/pages/api-reference.d.ts +33 -0
- package/lib/client/pages/api-reference.js +198 -0
- package/lib/client/styles.css +37 -0
- package/lib/config.d.ts +24 -0
- package/lib/config.js +39 -0
- package/lib/controllers/AdminController.d.ts +46 -0
- package/lib/controllers/AdminController.js +134 -0
- package/lib/controllers/AuthController.d.ts +15 -0
- package/lib/controllers/AuthController.js +194 -0
- package/lib/controllers/AuthorController.d.ts +17 -0
- package/lib/controllers/AuthorController.js +19 -0
- package/lib/controllers/CategoryController.d.ts +10 -0
- package/lib/controllers/CategoryController.js +88 -0
- package/lib/controllers/CommentController.d.ts +68 -0
- package/lib/controllers/CommentController.js +438 -0
- package/lib/controllers/ContentTypeController.d.ts +24 -0
- package/lib/controllers/ContentTypeController.js +91 -0
- package/lib/controllers/EmailVerificationController.d.ts +33 -0
- package/lib/controllers/EmailVerificationController.js +116 -0
- package/lib/controllers/ExportController.d.ts +15 -0
- package/lib/controllers/ExportController.js +41 -0
- package/lib/controllers/FeedController.d.ts +14 -0
- package/lib/controllers/FeedController.js +246 -0
- package/lib/controllers/HealthController.d.ts +21 -0
- package/lib/controllers/HealthController.js +176 -0
- package/lib/controllers/HomeController.d.ts +12 -0
- package/lib/controllers/HomeController.js +16 -0
- package/lib/controllers/MediaController.d.ts +24 -0
- package/lib/controllers/MediaController.js +189 -0
- package/lib/controllers/NavigationController.d.ts +22 -0
- package/lib/controllers/NavigationController.js +176 -0
- package/lib/controllers/PageController.d.ts +13 -0
- package/lib/controllers/PageController.js +172 -0
- package/lib/controllers/PasskeyController.d.ts +36 -0
- package/lib/controllers/PasskeyController.js +201 -0
- package/lib/controllers/PasswordResetController.d.ts +44 -0
- package/lib/controllers/PasswordResetController.js +160 -0
- package/lib/controllers/PostController.d.ts +51 -0
- package/lib/controllers/PostController.js +538 -0
- package/lib/controllers/PostLockController.d.ts +62 -0
- package/lib/controllers/PostLockController.js +101 -0
- package/lib/controllers/ProfileController.d.ts +13 -0
- package/lib/controllers/ProfileController.js +160 -0
- package/lib/controllers/PublicApiController.d.ts +23 -0
- package/lib/controllers/PublicApiController.js +100 -0
- package/lib/controllers/RedirectController.d.ts +32 -0
- package/lib/controllers/RedirectController.js +95 -0
- package/lib/controllers/SettingsController.d.ts +28 -0
- package/lib/controllers/SettingsController.js +105 -0
- package/lib/controllers/SnippetController.d.ts +27 -0
- package/lib/controllers/SnippetController.js +123 -0
- package/lib/controllers/TagController.d.ts +9 -0
- package/lib/controllers/TagController.js +70 -0
- package/lib/controllers/TaxonomyController.d.ts +24 -0
- package/lib/controllers/TaxonomyController.js +149 -0
- package/lib/controllers/TokenController.d.ts +27 -0
- package/lib/controllers/TokenController.js +83 -0
- package/lib/controllers/TwoFactorController.d.ts +31 -0
- package/lib/controllers/TwoFactorController.js +213 -0
- package/lib/controllers/UserController.d.ts +110 -0
- package/lib/controllers/UserController.js +504 -0
- package/lib/features/analytics/AnalyticsPage.d.ts +11 -0
- package/lib/features/analytics/AnalyticsPage.js +123 -0
- package/lib/features/analytics/admin.d.ts +3 -0
- package/lib/features/analytics/admin.js +9 -0
- package/lib/features/analytics/controller.d.ts +19 -0
- package/lib/features/analytics/controller.js +79 -0
- package/lib/features/analytics/helpers.d.ts +84 -0
- package/lib/features/analytics/helpers.js +181 -0
- package/lib/features/analytics/i18n/es.d.ts +4 -0
- package/lib/features/analytics/i18n/es.js +31 -0
- package/lib/features/analytics/index.d.ts +28 -0
- package/lib/features/analytics/index.js +91 -0
- package/lib/features/analytics/manifest.d.ts +8 -0
- package/lib/features/analytics/manifest.js +18 -0
- package/lib/features/analytics/model.d.ts +130 -0
- package/lib/features/analytics/model.js +206 -0
- package/lib/features/members/Member.d.ts +93 -0
- package/lib/features/members/Member.js +194 -0
- package/lib/features/members/MemberAdminController.d.ts +60 -0
- package/lib/features/members/MemberAdminController.js +262 -0
- package/lib/features/members/MemberController.d.ts +88 -0
- package/lib/features/members/MemberController.js +250 -0
- package/lib/features/members/MembersPage.d.ts +10 -0
- package/lib/features/members/MembersPage.js +216 -0
- package/lib/features/members/PostAccessBox.d.ts +15 -0
- package/lib/features/members/PostAccessBox.js +70 -0
- package/lib/features/members/admin.d.ts +3 -0
- package/lib/features/members/admin.js +12 -0
- package/lib/features/members/csv.d.ts +21 -0
- package/lib/features/members/csv.js +74 -0
- package/lib/features/members/events.d.ts +34 -0
- package/lib/features/members/events.js +34 -0
- package/lib/features/members/i18n/es.d.ts +4 -0
- package/lib/features/members/i18n/es.js +106 -0
- package/lib/features/members/index.d.ts +44 -0
- package/lib/features/members/index.js +106 -0
- package/lib/features/members/manifest.d.ts +8 -0
- package/lib/features/members/manifest.js +18 -0
- package/lib/features/members/middleware.d.ts +42 -0
- package/lib/features/members/middleware.js +74 -0
- package/lib/features/members/newsletter.d.ts +177 -0
- package/lib/features/members/newsletter.js +439 -0
- package/lib/features/members/rate-limits.d.ts +34 -0
- package/lib/features/members/rate-limits.js +50 -0
- package/lib/features/members/request.d.ts +13 -0
- package/lib/features/members/request.js +6 -0
- package/lib/features/members/routes.d.ts +15 -0
- package/lib/features/members/routes.js +59 -0
- package/lib/features/members/session.d.ts +102 -0
- package/lib/features/members/session.js +158 -0
- package/lib/features/members/settings.d.ts +14 -0
- package/lib/features/members/settings.js +23 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.d.ts +7 -0
- package/lib/features/mysendbox/MySendboxSettingsCard.js +48 -0
- package/lib/features/mysendbox/admin.d.ts +3 -0
- package/lib/features/mysendbox/admin.js +9 -0
- package/lib/features/mysendbox/broadcasts.d.ts +61 -0
- package/lib/features/mysendbox/broadcasts.js +124 -0
- package/lib/features/mysendbox/client.d.ts +95 -0
- package/lib/features/mysendbox/client.js +61 -0
- package/lib/features/mysendbox/config.d.ts +27 -0
- package/lib/features/mysendbox/config.js +74 -0
- package/lib/features/mysendbox/contacts.d.ts +121 -0
- package/lib/features/mysendbox/contacts.js +378 -0
- package/lib/features/mysendbox/controller.d.ts +11 -0
- package/lib/features/mysendbox/controller.js +47 -0
- package/lib/features/mysendbox/i18n/es.d.ts +4 -0
- package/lib/features/mysendbox/i18n/es.js +28 -0
- package/lib/features/mysendbox/index.d.ts +18 -0
- package/lib/features/mysendbox/index.js +71 -0
- package/lib/features/mysendbox/manifest.d.ts +7 -0
- package/lib/features/mysendbox/manifest.js +6 -0
- package/lib/features/mysendbox/routes.d.ts +6 -0
- package/lib/features/mysendbox/routes.js +14 -0
- package/lib/features/mysendbox/webhook.d.ts +23 -0
- package/lib/features/mysendbox/webhook.js +104 -0
- package/lib/features/theme/OEmbedController.d.ts +31 -0
- package/lib/features/theme/OEmbedController.js +128 -0
- package/lib/features/theme/ThemeController.d.ts +20 -0
- package/lib/features/theme/ThemeController.js +256 -0
- package/lib/features/theme/ThemeSettingsCard.d.ts +7 -0
- package/lib/features/theme/ThemeSettingsCard.js +12 -0
- package/lib/features/theme/admin.d.ts +3 -0
- package/lib/features/theme/admin.js +9 -0
- package/lib/features/theme/html.d.ts +48 -0
- package/lib/features/theme/html.js +97 -0
- package/lib/features/theme/i18n/es.d.ts +4 -0
- package/lib/features/theme/i18n/es.js +9 -0
- package/lib/features/theme/index.d.ts +11 -0
- package/lib/features/theme/index.js +23 -0
- package/lib/features/theme/manifest.d.ts +7 -0
- package/lib/features/theme/manifest.js +6 -0
- package/lib/features/theme/oembed.d.ts +36 -0
- package/lib/features/theme/oembed.js +58 -0
- package/lib/features/theme/routes.d.ts +17 -0
- package/lib/features/theme/routes.js +54 -0
- package/lib/features/theme/templates.d.ts +103 -0
- package/lib/features/theme/templates.js +283 -0
- package/lib/features.d.ts +15 -0
- package/lib/features.js +6 -0
- package/lib/features.manifest.d.ts +10 -0
- package/lib/features.manifest.js +6 -0
- package/lib/helpers/access.d.ts +62 -0
- package/lib/helpers/access.js +92 -0
- package/lib/helpers/api.d.ts +20 -0
- package/lib/helpers/api.js +44 -0
- package/lib/helpers/comment-guard.d.ts +145 -0
- package/lib/helpers/comment-guard.js +253 -0
- package/lib/helpers/comment-mail.d.ts +53 -0
- package/lib/helpers/comment-mail.js +188 -0
- package/lib/helpers/content-model.d.ts +50 -0
- package/lib/helpers/content-model.js +84 -0
- package/lib/helpers/content-paths.d.ts +107 -0
- package/lib/helpers/content-paths.js +200 -0
- package/lib/helpers/export-data.d.ts +85 -0
- package/lib/helpers/export-data.js +229 -0
- package/lib/helpers/gating.d.ts +53 -0
- package/lib/helpers/gating.js +83 -0
- package/lib/helpers/health.d.ts +91 -0
- package/lib/helpers/health.js +279 -0
- package/lib/helpers/heartbeat.d.ts +35 -0
- package/lib/helpers/heartbeat.js +55 -0
- package/lib/helpers/image-size.d.ts +18 -0
- package/lib/helpers/image-size.js +83 -0
- package/lib/helpers/images.d.ts +29 -0
- package/lib/helpers/images.js +41 -0
- package/lib/helpers/mail-templates.d.ts +11 -0
- package/lib/helpers/mail-templates.js +42 -0
- package/lib/helpers/publish-due.d.ts +28 -0
- package/lib/helpers/publish-due.js +67 -0
- package/lib/helpers/redirects.d.ts +43 -0
- package/lib/helpers/redirects.js +80 -0
- package/lib/helpers/seo-fields.d.ts +13 -0
- package/lib/helpers/seo-fields.js +52 -0
- package/lib/helpers/session.d.ts +30 -0
- package/lib/helpers/session.js +27 -0
- package/lib/helpers/site-settings.d.ts +98 -0
- package/lib/helpers/site-settings.js +232 -0
- package/lib/helpers/site.d.ts +14 -0
- package/lib/helpers/site.js +23 -0
- package/lib/helpers/write-hooks.d.ts +33 -0
- package/lib/helpers/write-hooks.js +37 -0
- package/lib/hooks.d.ts +17 -0
- package/lib/hooks.js +101 -0
- package/lib/host/core-tasks.d.ts +4 -0
- package/lib/host/core-tasks.js +26 -0
- package/lib/host/cron.d.ts +39 -0
- package/lib/host/cron.js +85 -0
- package/lib/host/enabled.d.ts +4 -0
- package/lib/host/enabled.js +40 -0
- package/lib/host/index.d.ts +81 -0
- package/lib/host/index.js +87 -0
- package/lib/host/manifest.d.ts +34 -0
- package/lib/host/manifest.js +7 -0
- package/lib/host/menu.d.ts +18 -0
- package/lib/host/menu.js +15 -0
- package/lib/main.d.ts +1 -0
- package/lib/main.js +24 -0
- package/lib/middleware/api-auth.d.ts +59 -0
- package/lib/middleware/api-auth.js +164 -0
- package/lib/middleware/auth.d.ts +49 -0
- package/lib/middleware/auth.js +112 -0
- package/lib/middleware/cache.d.ts +17 -0
- package/lib/middleware/cache.js +52 -0
- package/lib/middleware/rate-limits.d.ts +199 -0
- package/lib/middleware/rate-limits.js +276 -0
- package/lib/middleware/viewer.d.ts +13 -0
- package/lib/middleware/viewer.js +16 -0
- package/lib/models/Category.d.ts +24 -0
- package/lib/models/Category.js +102 -0
- package/lib/models/Comment.d.ts +120 -0
- package/lib/models/Comment.js +283 -0
- package/lib/models/ContentType.d.ts +142 -0
- package/lib/models/ContentType.js +462 -0
- package/lib/models/Credential.d.ts +21 -0
- package/lib/models/Credential.js +31 -0
- package/lib/models/Media.d.ts +53 -0
- package/lib/models/Media.js +132 -0
- package/lib/models/Menu.d.ts +131 -0
- package/lib/models/Menu.js +312 -0
- package/lib/models/Page.d.ts +55 -0
- package/lib/models/Page.js +218 -0
- package/lib/models/Post.d.ts +136 -0
- package/lib/models/Post.js +406 -0
- package/lib/models/PostLock.d.ts +67 -0
- package/lib/models/PostLock.js +112 -0
- package/lib/models/PostRevision.d.ts +45 -0
- package/lib/models/PostRevision.js +82 -0
- package/lib/models/PublicContent.d.ts +283 -0
- package/lib/models/PublicContent.js +577 -0
- package/lib/models/Redirect.d.ts +123 -0
- package/lib/models/Redirect.js +225 -0
- package/lib/models/Settings.d.ts +61 -0
- package/lib/models/Settings.js +128 -0
- package/lib/models/Snippet.d.ts +36 -0
- package/lib/models/Snippet.js +64 -0
- package/lib/models/Tag.d.ts +23 -0
- package/lib/models/Tag.js +117 -0
- package/lib/models/Taxonomy.d.ts +127 -0
- package/lib/models/Taxonomy.js +321 -0
- package/lib/models/TwoFactor.d.ts +26 -0
- package/lib/models/TwoFactor.js +60 -0
- package/lib/models/User.d.ts +49 -0
- package/lib/models/User.js +128 -0
- package/lib/models/derive.d.ts +69 -0
- package/lib/models/derive.js +81 -0
- package/lib/models/pagination.d.ts +30 -0
- package/lib/models/pagination.js +36 -0
- package/lib/models/visibility.d.ts +31 -0
- package/lib/models/visibility.js +47 -0
- package/lib/routes/App.d.ts +2 -0
- package/lib/routes/App.js +146 -0
- package/lib/routes/api/admin.d.ts +6 -0
- package/lib/routes/api/admin.js +11 -0
- package/lib/routes/api/auth.d.ts +6 -0
- package/lib/routes/api/auth.js +24 -0
- package/lib/routes/api/authors.d.ts +5 -0
- package/lib/routes/api/authors.js +8 -0
- package/lib/routes/api/categories.d.ts +8 -0
- package/lib/routes/api/categories.js +15 -0
- package/lib/routes/api/comments.d.ts +8 -0
- package/lib/routes/api/comments.js +35 -0
- package/lib/routes/api/content-model.d.ts +17 -0
- package/lib/routes/api/content-model.js +67 -0
- package/lib/routes/api/cron.d.ts +6 -0
- package/lib/routes/api/cron.js +9 -0
- package/lib/routes/api/export.d.ts +5 -0
- package/lib/routes/api/export.js +11 -0
- package/lib/routes/api/feed.d.ts +5 -0
- package/lib/routes/api/feed.js +16 -0
- package/lib/routes/api/media.d.ts +8 -0
- package/lib/routes/api/media.js +25 -0
- package/lib/routes/api/navigation.d.ts +12 -0
- package/lib/routes/api/navigation.js +17 -0
- package/lib/routes/api/ops.d.ts +9 -0
- package/lib/routes/api/ops.js +19 -0
- package/lib/routes/api/pages.d.ts +8 -0
- package/lib/routes/api/pages.js +21 -0
- package/lib/routes/api/passkeys.d.ts +7 -0
- package/lib/routes/api/passkeys.js +13 -0
- package/lib/routes/api/posts.d.ts +8 -0
- package/lib/routes/api/posts.js +39 -0
- package/lib/routes/api/profile.d.ts +6 -0
- package/lib/routes/api/profile.js +8 -0
- package/lib/routes/api/redirects.d.ts +12 -0
- package/lib/routes/api/redirects.js +13 -0
- package/lib/routes/api/settings.d.ts +8 -0
- package/lib/routes/api/settings.js +15 -0
- package/lib/routes/api/snippets.d.ts +15 -0
- package/lib/routes/api/snippets.js +16 -0
- package/lib/routes/api/tags.d.ts +8 -0
- package/lib/routes/api/tags.js +14 -0
- package/lib/routes/api/tokens.d.ts +7 -0
- package/lib/routes/api/tokens.js +15 -0
- package/lib/routes/api/two-factor.d.ts +7 -0
- package/lib/routes/api/two-factor.js +15 -0
- package/lib/routes/api/users.d.ts +8 -0
- package/lib/routes/api/users.js +25 -0
- package/lib/routes/api/v1.d.ts +12 -0
- package/lib/routes/api/v1.js +55 -0
- package/lib/routes/api/verification.d.ts +6 -0
- package/lib/routes/api/verification.js +11 -0
- package/lib/server/index.d.ts +24 -0
- package/lib/server/index.js +110 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.js +1 -0
- package/lib/vite.d.ts +2 -0
- package/lib/vite.js +101 -0
- package/mail/comment-moderation.html +27 -0
- package/mail/comment-moderation.txt +13 -0
- package/mail/comment-reply.html +28 -0
- package/mail/comment-reply.txt +14 -0
- package/mail/invitation.html +25 -0
- package/mail/invitation.txt +11 -0
- package/mail/member-magic-link.html +23 -0
- package/mail/member-magic-link.txt +10 -0
- package/mail/newsletter.html +26 -0
- package/mail/newsletter.txt +13 -0
- package/mail/password-reset.html +26 -0
- package/mail/password-reset.txt +10 -0
- package/mail/verify-email.html +25 -0
- package/mail/verify-email.txt +8 -0
- package/package.json +85 -4
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
2
|
+
import { ThemeController, themeEnabled } from "./ThemeController.js";
|
|
3
|
+
import { OEmbedController } from "./OEmbedController.js";
|
|
4
|
+
import { publicApiLimit } from "../../middleware/rate-limits.js";
|
|
5
|
+
import { publishDueOpportunistically } from "../../helpers/publish-due.js";
|
|
6
|
+
/**
|
|
7
|
+
* The reference public site (server-rendered theme) and the oEmbed provider.
|
|
8
|
+
*
|
|
9
|
+
* This feature goes **last** in src/features.ts, so these routes are mounted
|
|
10
|
+
* after core's and every other feature's. The router answers
|
|
11
|
+
* with the first route that matches, and `/:slug` and `/:base/:slug` match a
|
|
12
|
+
* great deal: registered last, `/api/...`, `/feed.xml`, `/sitemap.xml` and
|
|
13
|
+
* every other real route are matched before them. Static files are served by
|
|
14
|
+
* middleware that runs before any route, so assets are never shadowed either.
|
|
15
|
+
* Paths the SPA owns (`/admin`, `/login`, …) are handed the app shell by the
|
|
16
|
+
* controller, theme on or off.
|
|
17
|
+
*
|
|
18
|
+
* With DISABLE_PUBLIC_SITE nothing is registered, for the same reason the
|
|
19
|
+
* feeds are not: there is no public site to render or to embed.
|
|
20
|
+
*/
|
|
21
|
+
export function themeRoutes(router) {
|
|
22
|
+
if (process.env.DISABLE_PUBLIC_SITE === 'true')
|
|
23
|
+
return;
|
|
24
|
+
// oEmbed answers whether or not the theme renders pages: a headless front
|
|
25
|
+
// end serving the same paths (SITE_URL) is still "this site".
|
|
26
|
+
router.get('/oembed', publicApiLimit, OEmbedController.show);
|
|
27
|
+
// A scheduled post whose time has come is announced before the first page
|
|
28
|
+
// that could show it, as the content API does on its post reads.
|
|
29
|
+
const live = publishDueOpportunistically;
|
|
30
|
+
router.get('/page/:page', live, ThemeController.homePage);
|
|
31
|
+
router.get('/blog/:slug', live, ThemeController.post);
|
|
32
|
+
router.get('/category/:slug', live, ThemeController.category);
|
|
33
|
+
router.get('/tag/:slug', live, ThemeController.tag);
|
|
34
|
+
router.get('/author/:slug', live, ThemeController.author);
|
|
35
|
+
router.get('/taxonomy/:key/:slug', live, ThemeController.term);
|
|
36
|
+
router.get('/:base/:slug', live, ThemeController.typed);
|
|
37
|
+
router.get('/:slug', live, ThemeController.single);
|
|
38
|
+
// `/` cannot be a route. The static middleware runs before routing and
|
|
39
|
+
// answers `/` with the SPA's index.html from the build directory, so a
|
|
40
|
+
// `router.get('/')` would never be reached. `request.before` runs ahead of
|
|
41
|
+
// the static middleware, and a listener that returns `handled: true` owns
|
|
42
|
+
// the response — so the home page is rendered there, and only when the
|
|
43
|
+
// theme is on; otherwise the request carries on to the SPA as it always has.
|
|
44
|
+
hooks.on(HOOKS.REQUEST_BEFORE, async (context) => {
|
|
45
|
+
const { req, res } = context;
|
|
46
|
+
if (context.handled || req.method !== 'GET' || req.path !== '/')
|
|
47
|
+
return context;
|
|
48
|
+
if (!(await themeEnabled()))
|
|
49
|
+
return context;
|
|
50
|
+
await new Promise((done) => publishDueOpportunistically(req, res, done));
|
|
51
|
+
await ThemeController.home(req, res);
|
|
52
|
+
return { ...context, handled: true };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference theme: server-rendered HTML for the public site.
|
|
3
|
+
*
|
|
4
|
+
* Plain functions from data to markup, built on `html` (every interpolation
|
|
5
|
+
* escaped) — no template engine, no client JavaScript, no dependencies. The
|
|
6
|
+
* data comes from the same `PublicContent` functions the content API uses, so
|
|
7
|
+
* whatever decides what a visitor may see (published, scheduled, visibility)
|
|
8
|
+
* decides it here too; nothing in this file queries the database.
|
|
9
|
+
*
|
|
10
|
+
* It is a reference rather than a design: semantic markup, a small inline
|
|
11
|
+
* stylesheet that respects light and dark, and every head tag a crawler or a
|
|
12
|
+
* link preview reads. A site wanting its own look forks this directory, or
|
|
13
|
+
* goes headless and uses the content API.
|
|
14
|
+
*
|
|
15
|
+
* Pure, so tests render it directly.
|
|
16
|
+
*/
|
|
17
|
+
import { type SafeHtml } from './html.ts';
|
|
18
|
+
import type { PublicPost, PublicPage, PublicAuthor } from '../../models/PublicContent.ts';
|
|
19
|
+
import type { PublicSiteInfo } from '../../models/Settings.ts';
|
|
20
|
+
import type { ContentTypeRecord } from '../../models/ContentType.ts';
|
|
21
|
+
import type { ResponsiveImage } from '../../helpers/images.ts';
|
|
22
|
+
/** A menu item as Menu.publicNavigation returns it. */
|
|
23
|
+
export interface ThemeMenuItem {
|
|
24
|
+
label: string;
|
|
25
|
+
url: string;
|
|
26
|
+
new_tab: boolean;
|
|
27
|
+
children: ThemeMenuItem[];
|
|
28
|
+
}
|
|
29
|
+
/** What every page needs: who the site is, where we are, and how to link. */
|
|
30
|
+
export interface ThemeContext {
|
|
31
|
+
site: PublicSiteInfo;
|
|
32
|
+
/** The request path, used for the canonical URL when nothing overrides it. */
|
|
33
|
+
path: string;
|
|
34
|
+
/** Every content type, for entry paths and custom field labels. */
|
|
35
|
+
types: ContentTypeRecord[];
|
|
36
|
+
/** The primary menu, if one has items. */
|
|
37
|
+
menu: ThemeMenuItem[];
|
|
38
|
+
}
|
|
39
|
+
/** The head of one page, with every fallback already decided by the caller. */
|
|
40
|
+
export interface HeadMeta {
|
|
41
|
+
title: string;
|
|
42
|
+
description?: string | null;
|
|
43
|
+
/** Absolute canonical URL. Defaults to the site URL plus the request path. */
|
|
44
|
+
canonical?: string | null;
|
|
45
|
+
image?: string | null;
|
|
46
|
+
type?: 'website' | 'article' | 'profile';
|
|
47
|
+
noindex?: boolean;
|
|
48
|
+
jsonLd?: Record<string, unknown> | null;
|
|
49
|
+
publishedAt?: string | null;
|
|
50
|
+
modifiedAt?: string | null;
|
|
51
|
+
/** Separate share-card text, when the entry set one. */
|
|
52
|
+
og?: {
|
|
53
|
+
title: string;
|
|
54
|
+
description: string | null;
|
|
55
|
+
} | null;
|
|
56
|
+
twitter?: {
|
|
57
|
+
title: string;
|
|
58
|
+
description: string | null;
|
|
59
|
+
image: string | null;
|
|
60
|
+
} | null;
|
|
61
|
+
/** The page's own absolute URL, when it can be embedded — adds oEmbed discovery. */
|
|
62
|
+
embeddable?: string | null;
|
|
63
|
+
prev?: string | null;
|
|
64
|
+
next?: string | null;
|
|
65
|
+
}
|
|
66
|
+
/** An entry's path on this site, whatever its content type. */
|
|
67
|
+
export declare function pathOf(ctx: Pick<ThemeContext, 'types'>, post: Pick<PublicPost, 'slug' | 'id' | 'type'>): string;
|
|
68
|
+
/**
|
|
69
|
+
* A responsive <img>: width and height so the page does not jump as it loads,
|
|
70
|
+
* a srcset when IMAGE_TRANSFORM_URL is configured, lazy below the fold.
|
|
71
|
+
*/
|
|
72
|
+
export declare function responsiveImg(image: ResponsiveImage | null, options?: {
|
|
73
|
+
sizes?: string;
|
|
74
|
+
eager?: boolean;
|
|
75
|
+
alt?: string;
|
|
76
|
+
}): SafeHtml | '';
|
|
77
|
+
/** One entry in a listing. */
|
|
78
|
+
export declare function card(ctx: ThemeContext, post: PublicPost): SafeHtml;
|
|
79
|
+
/** Everything in <head> a browser, a crawler or a link preview reads. */
|
|
80
|
+
export declare function renderHead(ctx: ThemeContext, meta: HeadMeta): SafeHtml;
|
|
81
|
+
/** The whole page around a body. */
|
|
82
|
+
export declare function documentHtml(ctx: ThemeContext, meta: HeadMeta, body: SafeHtml): string;
|
|
83
|
+
export interface ListingView {
|
|
84
|
+
title: string;
|
|
85
|
+
/** Shown under the heading: a category description, an author bio. */
|
|
86
|
+
intro?: string | null;
|
|
87
|
+
posts: PublicPost[];
|
|
88
|
+
page: number;
|
|
89
|
+
totalPages: number;
|
|
90
|
+
/** The listing's own path, without `?page=`. */
|
|
91
|
+
basePath: string;
|
|
92
|
+
/** The home page and a type archive are the site; archives are collections. */
|
|
93
|
+
heading?: boolean;
|
|
94
|
+
author?: PublicAuthor | null;
|
|
95
|
+
}
|
|
96
|
+
/** The home page, a type archive, or a category/tag/author/term archive. */
|
|
97
|
+
export declare function renderListing(ctx: ThemeContext, view: ListingView): string;
|
|
98
|
+
/** One entry: a blog post or an entry of a custom content type. */
|
|
99
|
+
export declare function renderEntry(ctx: ThemeContext, post: PublicPost): string;
|
|
100
|
+
/** A page. */
|
|
101
|
+
export declare function renderPage(ctx: ThemeContext, page: PublicPage): string;
|
|
102
|
+
/** The 404. Indexed by nobody. */
|
|
103
|
+
export declare function renderNotFound(ctx: ThemeContext): string;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reference theme: server-rendered HTML for the public site.
|
|
3
|
+
*
|
|
4
|
+
* Plain functions from data to markup, built on `html` (every interpolation
|
|
5
|
+
* escaped) — no template engine, no client JavaScript, no dependencies. The
|
|
6
|
+
* data comes from the same `PublicContent` functions the content API uses, so
|
|
7
|
+
* whatever decides what a visitor may see (published, scheduled, visibility)
|
|
8
|
+
* decides it here too; nothing in this file queries the database.
|
|
9
|
+
*
|
|
10
|
+
* It is a reference rather than a design: semantic markup, a small inline
|
|
11
|
+
* stylesheet that respects light and dark, and every head tag a crawler or a
|
|
12
|
+
* link preview reads. A site wanting its own look forks this directory, or
|
|
13
|
+
* goes headless and uses the content API.
|
|
14
|
+
*
|
|
15
|
+
* Pure, so tests render it directly.
|
|
16
|
+
*/
|
|
17
|
+
import { html, raw, jsonForScript, safeHref } from "./html.js";
|
|
18
|
+
import { entryPath, pagePath, categoryPath, tagPath, authorPath, termPath } from "../../helpers/content-paths.js";
|
|
19
|
+
// --- Paths ----------------------------------------------------------------
|
|
20
|
+
/** An entry's path on this site, whatever its content type. */
|
|
21
|
+
export function pathOf(ctx, post) {
|
|
22
|
+
const type = ctx.types.find((candidate) => candidate.key === post.type);
|
|
23
|
+
return entryPath(type?.builtin ? null : type?.route_base, post.slug, post.id);
|
|
24
|
+
}
|
|
25
|
+
function absolute(ctx, path) {
|
|
26
|
+
return `${ctx.site.url}${path}`;
|
|
27
|
+
}
|
|
28
|
+
// --- Fragments --------------------------------------------------------------
|
|
29
|
+
/**
|
|
30
|
+
* A responsive <img>: width and height so the page does not jump as it loads,
|
|
31
|
+
* a srcset when IMAGE_TRANSFORM_URL is configured, lazy below the fold.
|
|
32
|
+
*/
|
|
33
|
+
export function responsiveImg(image, options = {}) {
|
|
34
|
+
if (!image)
|
|
35
|
+
return '';
|
|
36
|
+
return html `<img src="${image.url}"${image.srcset ? html ` srcset="${image.srcset}" sizes="${options.sizes ?? '(max-width: 760px) 100vw, 760px'}"` : ''}${image.width ? html ` width="${image.width}"` : ''}${image.height ? html ` height="${image.height}"` : ''} alt="${image.alt ?? options.alt ?? ''}" ${options.eager ? raw('fetchpriority="high"') : raw('loading="lazy"')} decoding="async">`;
|
|
37
|
+
}
|
|
38
|
+
function formatDate(ctx, iso) {
|
|
39
|
+
if (!iso)
|
|
40
|
+
return '';
|
|
41
|
+
const date = new Date(iso);
|
|
42
|
+
if (Number.isNaN(date.getTime()))
|
|
43
|
+
return '';
|
|
44
|
+
try {
|
|
45
|
+
return new Intl.DateTimeFormat(ctx.site.locale || 'en', { dateStyle: 'long', timeZone: ctx.site.timezone || 'UTC' }).format(date);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return date.toISOString().slice(0, 10);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function timeTag(ctx, iso) {
|
|
52
|
+
const text = formatDate(ctx, iso);
|
|
53
|
+
return text ? html `<time datetime="${iso}">${text}</time>` : '';
|
|
54
|
+
}
|
|
55
|
+
function menuItems(items) {
|
|
56
|
+
return html `<ul>${items.map((item) => html `<li><a href="${safeHref(item.url)}"${item.new_tab ? raw(' target="_blank" rel="noopener"') : ''}>${item.label}</a>${item.children.length ? menuItems(item.children) : ''}</li>`)}</ul>`;
|
|
57
|
+
}
|
|
58
|
+
/** One entry in a listing. */
|
|
59
|
+
export function card(ctx, post) {
|
|
60
|
+
const href = pathOf(ctx, post);
|
|
61
|
+
return html `<article class="card">
|
|
62
|
+
${post.featured_image ? html `<a class="card-image" href="${href}" tabindex="-1" aria-hidden="true">${responsiveImg(post.featured_image, { sizes: '(max-width: 760px) 100vw, 240px' })}</a>` : ''}
|
|
63
|
+
<div>
|
|
64
|
+
<h2><a href="${href}">${post.title}</a></h2>
|
|
65
|
+
<p class="meta">${timeTag(ctx, post.published_at)}${post.author ? html ` · ${post.author}` : ''}</p>
|
|
66
|
+
${post.excerpt ? html `<p>${post.excerpt}</p>` : ''}
|
|
67
|
+
</div>
|
|
68
|
+
</article>`;
|
|
69
|
+
}
|
|
70
|
+
function pager(page, totalPages, base) {
|
|
71
|
+
if (totalPages <= 1)
|
|
72
|
+
return '';
|
|
73
|
+
const link = (n) => (n <= 1 ? base : `${base}${base.includes('?') ? '&' : '?'}page=${n}`);
|
|
74
|
+
return html `<nav class="pager" aria-label="Pagination">
|
|
75
|
+
${page > 1 ? html `<a rel="prev" href="${link(page - 1)}">← Newer</a>` : html `<span></span>`}
|
|
76
|
+
<span>Page ${page} of ${totalPages}</span>
|
|
77
|
+
${page < totalPages ? html `<a rel="next" href="${link(page + 1)}">Older →</a>` : html `<span></span>`}
|
|
78
|
+
</nav>`;
|
|
79
|
+
}
|
|
80
|
+
/** Value of one custom field, as a reader should see it. */
|
|
81
|
+
function fieldValue(ctx, field, value) {
|
|
82
|
+
switch (field.type) {
|
|
83
|
+
case 'boolean':
|
|
84
|
+
return value ? 'Yes' : 'No';
|
|
85
|
+
case 'url':
|
|
86
|
+
return html `<a href="${safeHref(String(value))}" rel="noopener">${String(value)}</a>`;
|
|
87
|
+
case 'date':
|
|
88
|
+
return formatDate(ctx, `${value}T00:00:00Z`) || String(value);
|
|
89
|
+
case 'textarea':
|
|
90
|
+
// Plain text with its line breaks kept; never markup.
|
|
91
|
+
return html `${String(value).split('\n').map((line, index) => (index ? html `<br>${line}` : line))}`;
|
|
92
|
+
default:
|
|
93
|
+
return String(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function customFields(ctx, post) {
|
|
97
|
+
const values = post.fields;
|
|
98
|
+
if (!values)
|
|
99
|
+
return '';
|
|
100
|
+
const type = ctx.types.find((candidate) => candidate.key === post.type);
|
|
101
|
+
const defined = (type?.fields ?? []).filter((field) => values[field.key] !== undefined);
|
|
102
|
+
if (!defined.length)
|
|
103
|
+
return '';
|
|
104
|
+
return html `<dl class="fields">${defined.map((field) => html `<div><dt>${field.label}</dt><dd>${fieldValue(ctx, field, values[field.key])}</dd></div>`)}</dl>`;
|
|
105
|
+
}
|
|
106
|
+
function termLinks(post) {
|
|
107
|
+
const groups = [
|
|
108
|
+
...(post.categories.length ? [{ label: 'Filed under', links: post.categories.map((c) => ({ href: categoryPath(c.slug), name: c.name })) }] : []),
|
|
109
|
+
...(post.tags.length ? [{ label: 'Tags', links: post.tags.map((t) => ({ href: tagPath(t.slug), name: t.name })) }] : []),
|
|
110
|
+
...Object.entries(post.terms).map(([taxonomy, terms]) => ({
|
|
111
|
+
label: taxonomy.replace(/_/g, ' '),
|
|
112
|
+
links: terms.map((term) => ({ href: termPath(taxonomy, term.slug), name: term.name }))
|
|
113
|
+
}))
|
|
114
|
+
];
|
|
115
|
+
if (!groups.length)
|
|
116
|
+
return '';
|
|
117
|
+
return html `<footer class="terms">${groups.map((group) => html `<p><span>${group.label}:</span> ${group.links.map((link, index) => html `${index ? ', ' : ''}<a href="${link.href}">${link.name}</a>`)}</p>`)}</footer>`;
|
|
118
|
+
}
|
|
119
|
+
// --- The document -------------------------------------------------------------
|
|
120
|
+
const STYLES = `
|
|
121
|
+
:root{color-scheme:light dark;--fg:#1d1d1f;--muted:#5f6368;--bg:#fff;--line:#e5e5e5;--accent:#2457c5}
|
|
122
|
+
@media (prefers-color-scheme:dark){:root{--fg:#ececec;--muted:#a3a3a3;--bg:#141414;--line:#2a2a2a;--accent:#8fb0ff}}
|
|
123
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg);font:17px/1.65 system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
124
|
+
a{color:var(--accent)}img{max-width:100%;height:auto}
|
|
125
|
+
.wrap{max-width:760px;margin:0 auto;padding:0 16px}
|
|
126
|
+
.site-header{border-bottom:1px solid var(--line);padding:1rem 0}.site-header .wrap{display:flex;flex-wrap:wrap;gap:1rem;align-items:center;justify-content:space-between}
|
|
127
|
+
.brand{font-weight:700;text-decoration:none;color:var(--fg);display:flex;gap:.5rem;align-items:center}.brand img{height:32px;width:auto}
|
|
128
|
+
.site-header nav ul{list-style:none;display:flex;flex-wrap:wrap;gap:1rem;margin:0;padding:0}.site-header nav ul ul{display:none}
|
|
129
|
+
main{padding:2rem 0}h1{line-height:1.2;margin:.25rem 0 1rem}.meta{color:var(--muted);font-size:.9rem;margin:0}
|
|
130
|
+
.card{display:grid;grid-template-columns:1fr;gap:1rem;padding:1.25rem 0;border-bottom:1px solid var(--line)}
|
|
131
|
+
@media (min-width:600px){.card:has(.card-image){grid-template-columns:240px 1fr}}
|
|
132
|
+
.card h2{margin:0;font-size:1.25rem;line-height:1.3}.card h2 a{color:var(--fg);text-decoration:none}.card p{margin:.4rem 0 0}
|
|
133
|
+
.hero{margin:0 0 1.5rem}.content{overflow-wrap:break-word}.content pre{overflow-x:auto}
|
|
134
|
+
.fields{display:grid;gap:.5rem;border:1px solid var(--line);border-radius:8px;padding:1rem;margin:1.5rem 0}.fields div{display:flex;gap:1rem}.fields dt{font-weight:600;min-width:8rem}.fields dd{margin:0}
|
|
135
|
+
.terms{border-top:1px solid var(--line);margin-top:2rem;padding-top:1rem;color:var(--muted)}.terms span{text-transform:capitalize}
|
|
136
|
+
.author{display:flex;gap:1rem;align-items:center}.author img{border-radius:50%}
|
|
137
|
+
.pager{display:flex;justify-content:space-between;padding:1.5rem 0;color:var(--muted)}
|
|
138
|
+
.site-footer{border-top:1px solid var(--line);padding:1.5rem 0;color:var(--muted);font-size:.9rem}
|
|
139
|
+
`;
|
|
140
|
+
/** Everything in <head> a browser, a crawler or a link preview reads. */
|
|
141
|
+
export function renderHead(ctx, meta) {
|
|
142
|
+
const site = ctx.site;
|
|
143
|
+
const canonical = meta.canonical || absolute(ctx, ctx.path);
|
|
144
|
+
const title = meta.title === site.name ? site.name : `${meta.title} — ${site.name}`;
|
|
145
|
+
const description = meta.description || site.description || null;
|
|
146
|
+
const image = meta.image || site.default_social_image_url;
|
|
147
|
+
const og = meta.og ?? { title: meta.title, description };
|
|
148
|
+
const twitter = meta.twitter ?? { title: og.title, description: og.description, image };
|
|
149
|
+
return html `<meta charset="utf-8">
|
|
150
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
151
|
+
<title>${title}</title>
|
|
152
|
+
${description ? html `<meta name="description" content="${description}">` : ''}
|
|
153
|
+
<link rel="canonical" href="${canonical}">
|
|
154
|
+
${meta.noindex ? raw('<meta name="robots" content="noindex">') : ''}
|
|
155
|
+
${site.icon_url ? html `<link rel="icon" href="${site.icon_url}">` : ''}
|
|
156
|
+
<link rel="alternate" type="application/rss+xml" title="${site.name}" href="${absolute(ctx, '/feed.xml')}">
|
|
157
|
+
<link rel="alternate" type="application/feed+json" title="${site.name}" href="${absolute(ctx, '/feed.json')}">
|
|
158
|
+
${meta.embeddable ? html `<link rel="alternate" type="application/json+oembed" href="${absolute(ctx, `/oembed?url=${encodeURIComponent(meta.embeddable)}&format=json`)}" title="${meta.title}">` : ''}
|
|
159
|
+
${meta.prev ? html `<link rel="prev" href="${meta.prev}">` : ''}
|
|
160
|
+
${meta.next ? html `<link rel="next" href="${meta.next}">` : ''}
|
|
161
|
+
<meta property="og:site_name" content="${site.name}">
|
|
162
|
+
<meta property="og:type" content="${meta.type ?? 'website'}">
|
|
163
|
+
<meta property="og:title" content="${og.title}">
|
|
164
|
+
${og.description ? html `<meta property="og:description" content="${og.description}">` : ''}
|
|
165
|
+
<meta property="og:url" content="${canonical}">
|
|
166
|
+
${image ? html `<meta property="og:image" content="${image}">` : ''}
|
|
167
|
+
<meta property="og:locale" content="${site.locale.replace('-', '_')}">
|
|
168
|
+
${meta.publishedAt ? html `<meta property="article:published_time" content="${meta.publishedAt}">` : ''}
|
|
169
|
+
${meta.modifiedAt ? html `<meta property="article:modified_time" content="${meta.modifiedAt}">` : ''}
|
|
170
|
+
<meta name="twitter:card" content="${twitter.image ? 'summary_large_image' : 'summary'}">
|
|
171
|
+
<meta name="twitter:title" content="${twitter.title}">
|
|
172
|
+
${twitter.description ? html `<meta name="twitter:description" content="${twitter.description}">` : ''}
|
|
173
|
+
${twitter.image ? html `<meta name="twitter:image" content="${twitter.image}">` : ''}
|
|
174
|
+
${meta.jsonLd ? html `<script type="application/ld+json">${jsonForScript(meta.jsonLd)}</script>` : ''}
|
|
175
|
+
<style>${raw(STYLES)}</style>
|
|
176
|
+
${raw(site.code_injection.head)}`;
|
|
177
|
+
}
|
|
178
|
+
/** The whole page around a body. */
|
|
179
|
+
export function documentHtml(ctx, meta, body) {
|
|
180
|
+
const site = ctx.site;
|
|
181
|
+
return `<!doctype html>\n${html `<html lang="${site.locale || 'en'}">
|
|
182
|
+
<head>
|
|
183
|
+
${renderHead(ctx, meta)}
|
|
184
|
+
</head>
|
|
185
|
+
<body>
|
|
186
|
+
<header class="site-header"><div class="wrap">
|
|
187
|
+
<a class="brand" href="/">${site.logo_url ? html `<img src="${site.logo_url}" alt="">` : ''}<span>${site.name}</span></a>
|
|
188
|
+
${ctx.menu.length ? html `<nav aria-label="Primary">${menuItems(ctx.menu)}</nav>` : ''}
|
|
189
|
+
</div></header>
|
|
190
|
+
<main id="content"><div class="wrap">
|
|
191
|
+
${body}
|
|
192
|
+
</div></main>
|
|
193
|
+
<footer class="site-footer"><div class="wrap">
|
|
194
|
+
<p>© ${new Date().getUTCFullYear()} ${site.name} · <a href="/feed.xml">RSS</a></p>
|
|
195
|
+
</div></footer>
|
|
196
|
+
${raw(site.code_injection.foot)}
|
|
197
|
+
</body>
|
|
198
|
+
</html>`}\n`;
|
|
199
|
+
}
|
|
200
|
+
/** The home page, a type archive, or a category/tag/author/term archive. */
|
|
201
|
+
export function renderListing(ctx, view) {
|
|
202
|
+
const pageUrl = (n) => absolute(ctx, n <= 1 ? view.basePath : `${view.basePath}?page=${n}`);
|
|
203
|
+
const isHome = view.basePath === '/';
|
|
204
|
+
const body = html `
|
|
205
|
+
${view.heading === false ? '' : html `<header>
|
|
206
|
+
${view.author ? html `<div class="author">${view.author.avatar_url ? html `<img src="${view.author.avatar_url}" alt="" width="64" height="64">` : ''}<h1>${view.title}</h1></div>` : html `<h1>${view.title}</h1>`}
|
|
207
|
+
${view.intro ? html `<p class="meta">${view.intro}</p>` : ''}
|
|
208
|
+
</header>`}
|
|
209
|
+
${view.posts.length ? view.posts.map((post) => card(ctx, post)) : html `<p>Nothing here yet.</p>`}
|
|
210
|
+
${pager(view.page, view.totalPages, view.basePath)}`;
|
|
211
|
+
return documentHtml(ctx, {
|
|
212
|
+
title: isHome && view.page <= 1 ? ctx.site.name : view.page > 1 ? `${view.title} (page ${view.page})` : view.title,
|
|
213
|
+
description: view.intro || ctx.site.description,
|
|
214
|
+
canonical: pageUrl(view.page),
|
|
215
|
+
type: view.author ? 'profile' : 'website',
|
|
216
|
+
prev: view.page > 1 ? pageUrl(view.page - 1) : null,
|
|
217
|
+
next: view.page < view.totalPages ? pageUrl(view.page + 1) : null,
|
|
218
|
+
jsonLd: isHome
|
|
219
|
+
? { '@context': 'https://schema.org', '@type': 'WebSite', name: ctx.site.name, url: absolute(ctx, '/'), ...(ctx.site.description ? { description: ctx.site.description } : {}) }
|
|
220
|
+
: { '@context': 'https://schema.org', '@type': 'CollectionPage', name: view.title, url: pageUrl(view.page) }
|
|
221
|
+
}, body);
|
|
222
|
+
}
|
|
223
|
+
/** One entry: a blog post or an entry of a custom content type. */
|
|
224
|
+
export function renderEntry(ctx, post) {
|
|
225
|
+
const url = absolute(ctx, pathOf(ctx, post));
|
|
226
|
+
const body = html `<article>
|
|
227
|
+
<header>
|
|
228
|
+
<h1>${post.title}</h1>
|
|
229
|
+
<p class="meta">${timeTag(ctx, post.published_at)}${post.author_profile?.slug
|
|
230
|
+
? html ` · <a href="${authorPath(post.author_profile.slug)}">${post.author_profile.name}</a>`
|
|
231
|
+
: post.author ? html ` · ${post.author}` : ''}</p>
|
|
232
|
+
</header>
|
|
233
|
+
${post.featured_image ? html `<figure class="hero">${responsiveImg(post.featured_image, { eager: true, alt: '' })}</figure>` : ''}
|
|
234
|
+
${customFields(ctx, post)}
|
|
235
|
+
${post.gated
|
|
236
|
+
// The theme always renders the anonymous view, so a members-only entry
|
|
237
|
+
// is its excerpt (when it is a teaser, not the whole body) and a notice —
|
|
238
|
+
// never an empty article that reads as a broken page.
|
|
239
|
+
? html `<div class="content">${post.excerpt ? html `<p>${post.excerpt}</p>` : ''}<p class="gated"><em>This post is for members.</em></p></div>`
|
|
240
|
+
: html `<div class="content">${post.format === 'html' ? raw(post.content) : html `<p>${post.content}</p>`}</div>`}
|
|
241
|
+
${termLinks(post)}
|
|
242
|
+
</article>`;
|
|
243
|
+
return documentHtml(ctx, {
|
|
244
|
+
title: post.meta_title || post.title,
|
|
245
|
+
description: post.meta_description || post.excerpt,
|
|
246
|
+
canonical: post.canonical_url || url,
|
|
247
|
+
image: post.og.image_url,
|
|
248
|
+
type: 'article',
|
|
249
|
+
noindex: post.noindex,
|
|
250
|
+
jsonLd: post.structured_data,
|
|
251
|
+
publishedAt: post.published_at,
|
|
252
|
+
modifiedAt: post.updated_at,
|
|
253
|
+
og: { title: post.og.title, description: post.og.description },
|
|
254
|
+
twitter: { title: post.twitter.title, description: post.twitter.description, image: post.twitter.image_url },
|
|
255
|
+
embeddable: url
|
|
256
|
+
}, body);
|
|
257
|
+
}
|
|
258
|
+
/** A page. */
|
|
259
|
+
export function renderPage(ctx, page) {
|
|
260
|
+
const url = absolute(ctx, pagePath(page.slug));
|
|
261
|
+
const body = html `<article>
|
|
262
|
+
<h1>${page.title}</h1>
|
|
263
|
+
${page.featured_image ? html `<figure class="hero">${responsiveImg(page.featured_image, { eager: true, alt: '' })}</figure>` : ''}
|
|
264
|
+
<div class="content">${page.format === 'html' ? raw(page.content) : html `<p>${page.content}</p>`}</div>
|
|
265
|
+
</article>`;
|
|
266
|
+
return documentHtml(ctx, {
|
|
267
|
+
title: page.meta_title || page.title,
|
|
268
|
+
description: page.meta_description,
|
|
269
|
+
canonical: page.canonical_url || url,
|
|
270
|
+
image: page.og.image_url,
|
|
271
|
+
noindex: page.noindex,
|
|
272
|
+
og: { title: page.og.title, description: page.og.description },
|
|
273
|
+
twitter: { title: page.twitter.title, description: page.twitter.description, image: page.twitter.image_url },
|
|
274
|
+
modifiedAt: page.updated_at,
|
|
275
|
+
jsonLd: { '@context': 'https://schema.org', '@type': 'WebPage', name: page.title, url, dateModified: page.updated_at },
|
|
276
|
+
embeddable: url
|
|
277
|
+
}, body);
|
|
278
|
+
}
|
|
279
|
+
/** The 404. Indexed by nobody. */
|
|
280
|
+
export function renderNotFound(ctx) {
|
|
281
|
+
return documentHtml(ctx, { title: 'Page not found', noindex: true }, html `<h1>Page not found</h1>
|
|
282
|
+
<p>There is nothing at this address. Try the <a href="/">home page</a>.</p>`);
|
|
283
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every feature the CMS ships, by name. Each is a folder in src/features/.
|
|
3
|
+
*
|
|
4
|
+
* A site turns them on with `features` in basicben.config.js, and that list
|
|
5
|
+
* sets the order: a feature's routes are mounted after core's and after the
|
|
6
|
+
* features listed before it. An empty list is the bare core.
|
|
7
|
+
*
|
|
8
|
+
* Importing a feature's index.ts does nothing by itself: a feature acts only
|
|
9
|
+
* through the host, when it is registered.
|
|
10
|
+
*
|
|
11
|
+
* Keep the keys in step with src/client/features.ts and src/features.manifest.ts.
|
|
12
|
+
*/
|
|
13
|
+
import type { Feature } from './host/index.ts';
|
|
14
|
+
declare const features: Record<string, Feature>;
|
|
15
|
+
export default features;
|
package/lib/features.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import analytics from "./features/analytics/index.js";
|
|
2
|
+
import members from "./features/members/index.js";
|
|
3
|
+
import mysendbox from "./features/mysendbox/index.js";
|
|
4
|
+
import theme from "./features/theme/index.js";
|
|
5
|
+
const features = { analytics, members, mysendbox, theme };
|
|
6
|
+
export default features;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static half of every feature, by name: for code that cannot boot the
|
|
3
|
+
* server (the export and backup scripts), for checking a site's `features`
|
|
4
|
+
* list, and for the admin menu.
|
|
5
|
+
*
|
|
6
|
+
* Keep the keys in step with src/features.ts and src/client/features.ts.
|
|
7
|
+
*/
|
|
8
|
+
import type { FeatureManifest } from './host/manifest.ts';
|
|
9
|
+
declare const manifests: Record<string, FeatureManifest>;
|
|
10
|
+
export default manifests;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import analytics from "./features/analytics/manifest.js";
|
|
2
|
+
import members from "./features/members/manifest.js";
|
|
3
|
+
import mysendbox from "./features/mysendbox/manifest.js";
|
|
4
|
+
import theme from "./features/theme/manifest.js";
|
|
5
|
+
const manifests = { analytics, members, mysendbox, theme };
|
|
6
|
+
export default manifests;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may read a restricted post's body: core's mechanism, one feature's policy.
|
|
3
|
+
*
|
|
4
|
+
* A post's `visibility` is `public` or a level some policy understands
|
|
5
|
+
* (`members`, `paid`). Core never decides what a level means. It asks the one
|
|
6
|
+
* registered policy, through `mayRead`, and every surface that serves a body —
|
|
7
|
+
* the content API, the feeds, the built-in blog, the theme — goes through
|
|
8
|
+
* helpers/gating.ts, which goes through here.
|
|
9
|
+
*
|
|
10
|
+
* - **One policy, not a chain.** A second registration throws at boot. A chain
|
|
11
|
+
* would let a later listener turn a deny into an allow.
|
|
12
|
+
* - **Deny by default.** With no policy, public posts are readable and nothing
|
|
13
|
+
* else is: a site that removes the members feature keeps its members-only
|
|
14
|
+
* posts withheld rather than publishing them. If the policy throws, the
|
|
15
|
+
* answer is no.
|
|
16
|
+
*
|
|
17
|
+
* No database access and no imports, so tests and gating.ts load it directly.
|
|
18
|
+
*/
|
|
19
|
+
/** A reader the policy recognised. Opaque to core: only the policy looks inside. */
|
|
20
|
+
export type Viewer = object;
|
|
21
|
+
export interface AccessPolicy<V extends Viewer = Viewer> {
|
|
22
|
+
/** The levels beyond `public` the editor offers, such as `members`. */
|
|
23
|
+
levels: string[];
|
|
24
|
+
/** Request headers that carry the reader's credential. Core treats them like Authorization for caching. */
|
|
25
|
+
headers: string[];
|
|
26
|
+
/** The reader behind a request, or null. */
|
|
27
|
+
identify(req: any): V | null | Promise<V | null>;
|
|
28
|
+
/** Whether this reader may have this post's body. Only asked for a restricted post and a known reader. */
|
|
29
|
+
mayRead(post: {
|
|
30
|
+
visibility?: unknown;
|
|
31
|
+
}, viewer: V): boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const PUBLIC = "public";
|
|
34
|
+
export declare function setAccessPolicy(next: AccessPolicy<any>): void;
|
|
35
|
+
/** For tests: forget the policy. */
|
|
36
|
+
export declare function clearAccessPolicy(): void;
|
|
37
|
+
export declare function hasAccessPolicy(): boolean;
|
|
38
|
+
/** Every level a post may be saved with: `public`, then the policy's. */
|
|
39
|
+
export declare function accessLevels(): string[];
|
|
40
|
+
/** The headers that carry a reader's credential, as the policy spelled them. */
|
|
41
|
+
export declare function credentialHeaders(): string[];
|
|
42
|
+
/** A stored visibility as a string. Blank or missing is `public`, which is what the column defaults to. */
|
|
43
|
+
export declare function visibilityOf(value: unknown): string;
|
|
44
|
+
/** Does this visibility restrict the body at all? Anything but public does. */
|
|
45
|
+
export declare function isRestricted(visibility: unknown): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* May this reader have this post's body?
|
|
48
|
+
*
|
|
49
|
+
* `viewer` is what `viewerOf` returned for the request; null (or anything
|
|
50
|
+
* falsy) is an anonymous reader. Never throws.
|
|
51
|
+
*/
|
|
52
|
+
export declare function mayRead(post: {
|
|
53
|
+
visibility?: unknown;
|
|
54
|
+
}, viewer: unknown): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The reader behind a request, asked of the policy once per request and
|
|
57
|
+
* remembered on it. Null with no policy, no credential, or a policy that
|
|
58
|
+
* throws.
|
|
59
|
+
*/
|
|
60
|
+
export declare function viewerOf(req: {
|
|
61
|
+
viewer?: Viewer | null;
|
|
62
|
+
} & Record<string, any>): Promise<Viewer | null>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may read a restricted post's body: core's mechanism, one feature's policy.
|
|
3
|
+
*
|
|
4
|
+
* A post's `visibility` is `public` or a level some policy understands
|
|
5
|
+
* (`members`, `paid`). Core never decides what a level means. It asks the one
|
|
6
|
+
* registered policy, through `mayRead`, and every surface that serves a body —
|
|
7
|
+
* the content API, the feeds, the built-in blog, the theme — goes through
|
|
8
|
+
* helpers/gating.ts, which goes through here.
|
|
9
|
+
*
|
|
10
|
+
* - **One policy, not a chain.** A second registration throws at boot. A chain
|
|
11
|
+
* would let a later listener turn a deny into an allow.
|
|
12
|
+
* - **Deny by default.** With no policy, public posts are readable and nothing
|
|
13
|
+
* else is: a site that removes the members feature keeps its members-only
|
|
14
|
+
* posts withheld rather than publishing them. If the policy throws, the
|
|
15
|
+
* answer is no.
|
|
16
|
+
*
|
|
17
|
+
* No database access and no imports, so tests and gating.ts load it directly.
|
|
18
|
+
*/
|
|
19
|
+
export const PUBLIC = 'public';
|
|
20
|
+
let policy = null;
|
|
21
|
+
export function setAccessPolicy(next) {
|
|
22
|
+
if (policy)
|
|
23
|
+
throw new Error('An access policy is already registered; there can be only one');
|
|
24
|
+
if (!Array.isArray(next.levels) || next.levels.includes(PUBLIC))
|
|
25
|
+
throw new Error('Access levels must be a list, and not include "public"');
|
|
26
|
+
for (const level of next.levels) {
|
|
27
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(level))
|
|
28
|
+
throw new Error(`Access level "${level}" must be a short lower-case name`);
|
|
29
|
+
}
|
|
30
|
+
policy = { ...next, headers: [...(next.headers ?? [])] };
|
|
31
|
+
}
|
|
32
|
+
/** For tests: forget the policy. */
|
|
33
|
+
export function clearAccessPolicy() {
|
|
34
|
+
policy = null;
|
|
35
|
+
}
|
|
36
|
+
export function hasAccessPolicy() {
|
|
37
|
+
return policy !== null;
|
|
38
|
+
}
|
|
39
|
+
/** Every level a post may be saved with: `public`, then the policy's. */
|
|
40
|
+
export function accessLevels() {
|
|
41
|
+
return [PUBLIC, ...(policy?.levels ?? [])];
|
|
42
|
+
}
|
|
43
|
+
/** The headers that carry a reader's credential, as the policy spelled them. */
|
|
44
|
+
export function credentialHeaders() {
|
|
45
|
+
return policy?.headers ?? [];
|
|
46
|
+
}
|
|
47
|
+
/** A stored visibility as a string. Blank or missing is `public`, which is what the column defaults to. */
|
|
48
|
+
export function visibilityOf(value) {
|
|
49
|
+
return typeof value === 'string' && value.trim() !== '' ? value : PUBLIC;
|
|
50
|
+
}
|
|
51
|
+
/** Does this visibility restrict the body at all? Anything but public does. */
|
|
52
|
+
export function isRestricted(visibility) {
|
|
53
|
+
return visibilityOf(visibility) !== PUBLIC;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* May this reader have this post's body?
|
|
57
|
+
*
|
|
58
|
+
* `viewer` is what `viewerOf` returned for the request; null (or anything
|
|
59
|
+
* falsy) is an anonymous reader. Never throws.
|
|
60
|
+
*/
|
|
61
|
+
export function mayRead(post, viewer) {
|
|
62
|
+
if (!isRestricted(post.visibility))
|
|
63
|
+
return true;
|
|
64
|
+
if (!policy || !viewer)
|
|
65
|
+
return false;
|
|
66
|
+
try {
|
|
67
|
+
return policy.mayRead(post, viewer) === true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The reader behind a request, asked of the policy once per request and
|
|
75
|
+
* remembered on it. Null with no policy, no credential, or a policy that
|
|
76
|
+
* throws.
|
|
77
|
+
*/
|
|
78
|
+
export async function viewerOf(req) {
|
|
79
|
+
if (req.viewer !== undefined)
|
|
80
|
+
return req.viewer;
|
|
81
|
+
let viewer = null;
|
|
82
|
+
if (policy) {
|
|
83
|
+
try {
|
|
84
|
+
viewer = (await policy.identify(req)) ?? null;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
viewer = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
req.viewer = viewer;
|
|
91
|
+
return viewer;
|
|
92
|
+
}
|