@basicbenframework/cms 0.0.0-stage → 0.6.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 +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,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `basicben-backup-20261123T101500123Z-1a2b3c4d5e6f7a8b`, plus an extension.
|
|
3
|
+
*
|
|
4
|
+
* Milliseconds are kept so two backups in the same second still sort.
|
|
5
|
+
*
|
|
6
|
+
* The timestamp sorts and is what retention reads; the random tail makes the
|
|
7
|
+
* name unguessable, so a backup that does end up somewhere world-readable is
|
|
8
|
+
* not found by counting timestamps.
|
|
9
|
+
*/
|
|
10
|
+
export function backupBaseName(now?: Date, random?: string): string;
|
|
11
|
+
/** The time a backup name records, or null for a file that is not ours. */
|
|
12
|
+
export function parseBackupName(name: any): {
|
|
13
|
+
date: Date;
|
|
14
|
+
set: string;
|
|
15
|
+
ext: string;
|
|
16
|
+
} | null;
|
|
17
|
+
/**
|
|
18
|
+
* Which files to delete so that only the newest `keep` backups remain.
|
|
19
|
+
*
|
|
20
|
+
* A backup is a *set* — the JSON and, with --sqlite-copy, the database file
|
|
21
|
+
* share a base name — so retention counts sets, not files: `--keep 7` keeps
|
|
22
|
+
* seven backups, not three and a half. Anything that does not parse as a
|
|
23
|
+
* backup name is never touched; retention must not be a way to delete files
|
|
24
|
+
* that merely share a directory or prefix.
|
|
25
|
+
*/
|
|
26
|
+
export function selectForDeletion(names: any, keep: any): any[];
|
|
27
|
+
/**
|
|
28
|
+
* Where uploads go, from the environment.
|
|
29
|
+
*
|
|
30
|
+
* `BACKUP_S3_*` first: a backup bucket separate from the media bucket is the
|
|
31
|
+
* recommended setup, because a media bucket is usually public — R2 with a
|
|
32
|
+
* custom domain serves *every* key in it — and a backup holds every user's
|
|
33
|
+
* address. Falling back to the media bucket's `S3_*` works, under the
|
|
34
|
+
* `backups/` prefix, and is reported as `shared: true` so the CLI can say so.
|
|
35
|
+
*/
|
|
36
|
+
export function backupStorageConfig(env?: NodeJS.ProcessEnv): {
|
|
37
|
+
config: {
|
|
38
|
+
driver: string;
|
|
39
|
+
bucket: string | undefined;
|
|
40
|
+
accessKeyId: string | undefined;
|
|
41
|
+
secretAccessKey: string | undefined;
|
|
42
|
+
endpoint: string | undefined;
|
|
43
|
+
region: string;
|
|
44
|
+
};
|
|
45
|
+
shared: boolean;
|
|
46
|
+
publicMediaUrl: boolean;
|
|
47
|
+
} | null;
|
|
48
|
+
/** `backups/` unless told otherwise, always ending in exactly one slash. */
|
|
49
|
+
export function normalizePrefix(prefix?: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Write the JSON export to `path`, gzipped if asked.
|
|
52
|
+
*
|
|
53
|
+
* Streamed end to end — the export yields fragments and they go straight to
|
|
54
|
+
* the file — so a large site is never held in memory whole.
|
|
55
|
+
*/
|
|
56
|
+
export function writeJsonBackup(db: any, path: any, { gzip, revisions, now }?: {
|
|
57
|
+
gzip?: boolean | undefined;
|
|
58
|
+
revisions?: boolean | undefined;
|
|
59
|
+
}): Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* A consistent copy of a SQLite database, with secrets removed.
|
|
62
|
+
*
|
|
63
|
+
* `VACUUM INTO` is SQLite's own online backup: one statement, a transaction-
|
|
64
|
+
* consistent snapshot even while the app is writing, and a compacted file.
|
|
65
|
+
* Copying the file with `cp` is not — a copy taken mid-write can be torn, and
|
|
66
|
+
* a WAL-mode database's recent writes are in the `-wal` file beside it.
|
|
67
|
+
*
|
|
68
|
+
* Only for a local file. Turso and Postgres back up on the provider's side
|
|
69
|
+
* (point-in-time recovery), and the JSON backup covers moving off them.
|
|
70
|
+
*/
|
|
71
|
+
export function sqliteSnapshot(db: any, outPath: any): Promise<number>;
|
|
72
|
+
/** Every table that holds credentials or per-database state, plus the IP column. */
|
|
73
|
+
export function scrubSqliteCopy(path: any): void;
|
|
74
|
+
/** Delete local backups beyond the newest `keep`. Returns what was deleted. */
|
|
75
|
+
export function pruneLocal(dir: any, keep: any): Promise<any[]>;
|
|
76
|
+
/** Every key under the prefix, following continuation tokens. */
|
|
77
|
+
export function listAll(storage: any, prefix: any): Promise<any[]>;
|
|
78
|
+
/** Delete bucket backups beyond the newest `keep`. Only keys under `prefix`. */
|
|
79
|
+
export function pruneBucket(storage: any, prefix: any, keep: any): Promise<any[]>;
|
|
80
|
+
/** Whether a buffer is gzip, by its magic number rather than its name. */
|
|
81
|
+
export function isGzip(buffer: any): boolean;
|
|
82
|
+
/** Row counts of the content tables that have rows. Missing tables count as empty. */
|
|
83
|
+
export function nonEmptyTables(db: any): Promise<{}>;
|
|
84
|
+
/**
|
|
85
|
+
* Load a backup into a database: the JSON import, made fit for a restore.
|
|
86
|
+
*
|
|
87
|
+
* The importer was built for merging one site into another, which needs an
|
|
88
|
+
* admin already in the target to own orphaned content. A restore is the
|
|
89
|
+
* opposite case — the target is empty and the admins are *in the file* — so
|
|
90
|
+
* this imports the accounts first, takes the first imported admin as the
|
|
91
|
+
* fallback owner, and then imports everything else. Both passes are one
|
|
92
|
+
* transaction: a restore that fails halfway leaves the database as empty as
|
|
93
|
+
* it found it, not half a site that the "empty database only" rule would
|
|
94
|
+
* then refuse to restore over.
|
|
95
|
+
*
|
|
96
|
+
* Refuses a database that already has content unless `force` is set; with it,
|
|
97
|
+
* the import's usual merge rules apply (existing rows matched by natural key
|
|
98
|
+
* and left alone).
|
|
99
|
+
*/
|
|
100
|
+
export function restoreBackup(db: any, doc: any, { force, dryRun, log }?: {
|
|
101
|
+
force?: boolean | undefined;
|
|
102
|
+
dryRun?: boolean | undefined;
|
|
103
|
+
}): Promise<any>;
|
|
104
|
+
export const BACKUP_PREFIX: "basicben-backup-";
|
|
105
|
+
export const PERSONAL_DATA_WARNING: string;
|
|
106
|
+
/**
|
|
107
|
+
* Content tables that make a database "not empty" for restore purposes.
|
|
108
|
+
*
|
|
109
|
+
* Settings are deliberately not on the list: migrations seed defaults, so a
|
|
110
|
+
* freshly migrated database already has some.
|
|
111
|
+
*/
|
|
112
|
+
export const CONTENT_TABLES: string[];
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The moving parts of `basicben-cms backup` and `basicben-cms restore`, kept
|
|
3
|
+
* apart from the CLI so the tests can drive them against an in-memory
|
|
4
|
+
* database and a fake bucket.
|
|
5
|
+
*
|
|
6
|
+
* ## What a backup is
|
|
7
|
+
*
|
|
8
|
+
* The JSON export (`src/helpers/export-data.ts`), revisions included: every
|
|
9
|
+
* table that is content, with every credential left out. It is portable —
|
|
10
|
+
* restore it into SQLite, Turso or Postgres — and it is safe to hand to a
|
|
11
|
+
* storage provider, because there is nothing in it that signs anyone in.
|
|
12
|
+
*
|
|
13
|
+
* Optionally, on SQLite, a consistent copy of the database file made with
|
|
14
|
+
* `VACUUM INTO`, which keeps ids, analytics counts and everything else the
|
|
15
|
+
* export does not cover. That copy is **scrubbed** before it is written out:
|
|
16
|
+
* the same secrets the export omits are deleted from it, and then the copy is
|
|
17
|
+
* vacuumed again, because SQLite leaves deleted rows readable in free pages
|
|
18
|
+
* until it is.
|
|
19
|
+
*
|
|
20
|
+
* Both contain personal data — account and commenter email addresses — so
|
|
21
|
+
* both are treated as sensitive: random file names, never a public bucket
|
|
22
|
+
* by default, and a warning on every run.
|
|
23
|
+
*/
|
|
24
|
+
import { createWriteStream } from 'node:fs';
|
|
25
|
+
import { readdir, rm, stat } from 'node:fs/promises';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
import { Readable } from 'node:stream';
|
|
28
|
+
import { pipeline } from 'node:stream/promises';
|
|
29
|
+
import { createGzip } from 'node:zlib';
|
|
30
|
+
import { randomBytes } from 'node:crypto';
|
|
31
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
32
|
+
import { exportChunks, NEVER_EXPORTED, isSecretSetting } from "../../helpers/export-data.js";
|
|
33
|
+
import { unusablePassword, defaultAuthor, withDryRun, Report } from './import-common.mjs';
|
|
34
|
+
import { importExport } from './json-import.mjs';
|
|
35
|
+
export const BACKUP_PREFIX = 'basicben-backup-';
|
|
36
|
+
export const PERSONAL_DATA_WARNING = 'This backup contains personal data: account email addresses and names, and commenters\' names\n' +
|
|
37
|
+
'and email addresses. Store it encrypted, with access limited to the people who run the site,\n' +
|
|
38
|
+
'and delete old copies (--keep). It contains no passwords, two-factor secrets, passkeys or tokens.';
|
|
39
|
+
/**
|
|
40
|
+
* `basicben-backup-20261123T101500123Z-1a2b3c4d5e6f7a8b`, plus an extension.
|
|
41
|
+
*
|
|
42
|
+
* Milliseconds are kept so two backups in the same second still sort.
|
|
43
|
+
*
|
|
44
|
+
* The timestamp sorts and is what retention reads; the random tail makes the
|
|
45
|
+
* name unguessable, so a backup that does end up somewhere world-readable is
|
|
46
|
+
* not found by counting timestamps.
|
|
47
|
+
*/
|
|
48
|
+
export function backupBaseName(now = new Date(), random = randomBytes(8).toString('hex')) {
|
|
49
|
+
const stamp = now.toISOString().replace(/[-:.]/g, '');
|
|
50
|
+
return `${BACKUP_PREFIX}${stamp}-${random}`;
|
|
51
|
+
}
|
|
52
|
+
const NAME = /^basicben-backup-(\d{8}T\d{6}(?:\d{3})?Z)-([0-9a-f]{16})(\..+)$/;
|
|
53
|
+
/** The time a backup name records, or null for a file that is not ours. */
|
|
54
|
+
export function parseBackupName(name) {
|
|
55
|
+
const file = String(name).split('/').pop();
|
|
56
|
+
const match = NAME.exec(file);
|
|
57
|
+
if (!match)
|
|
58
|
+
return null;
|
|
59
|
+
const s = match[1];
|
|
60
|
+
const ms = s.length > 16 ? `.${s.slice(15, 18)}` : '';
|
|
61
|
+
const iso = `${s.slice(0, 4)}-${s.slice(4, 6)}-${s.slice(6, 8)}T${s.slice(9, 11)}:${s.slice(11, 13)}:${s.slice(13, 15)}${ms}Z`;
|
|
62
|
+
const date = new Date(iso);
|
|
63
|
+
return Number.isNaN(date.getTime()) ? null : { date, set: `${BACKUP_PREFIX}${match[1]}-${match[2]}`, ext: match[3] };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Which files to delete so that only the newest `keep` backups remain.
|
|
67
|
+
*
|
|
68
|
+
* A backup is a *set* — the JSON and, with --sqlite-copy, the database file
|
|
69
|
+
* share a base name — so retention counts sets, not files: `--keep 7` keeps
|
|
70
|
+
* seven backups, not three and a half. Anything that does not parse as a
|
|
71
|
+
* backup name is never touched; retention must not be a way to delete files
|
|
72
|
+
* that merely share a directory or prefix.
|
|
73
|
+
*/
|
|
74
|
+
export function selectForDeletion(names, keep) {
|
|
75
|
+
if (!Number.isInteger(keep) || keep < 1)
|
|
76
|
+
throw new Error('--keep must be a whole number of at least 1');
|
|
77
|
+
const sets = new Map();
|
|
78
|
+
for (const name of names) {
|
|
79
|
+
const parsed = parseBackupName(name);
|
|
80
|
+
if (!parsed)
|
|
81
|
+
continue;
|
|
82
|
+
if (!sets.has(parsed.set))
|
|
83
|
+
sets.set(parsed.set, { date: parsed.date, names: [] });
|
|
84
|
+
sets.get(parsed.set).names.push(name);
|
|
85
|
+
}
|
|
86
|
+
return [...sets.values()]
|
|
87
|
+
.sort((a, b) => b.date.getTime() - a.date.getTime())
|
|
88
|
+
.slice(keep)
|
|
89
|
+
.flatMap((set) => set.names)
|
|
90
|
+
.sort();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Where uploads go, from the environment.
|
|
94
|
+
*
|
|
95
|
+
* `BACKUP_S3_*` first: a backup bucket separate from the media bucket is the
|
|
96
|
+
* recommended setup, because a media bucket is usually public — R2 with a
|
|
97
|
+
* custom domain serves *every* key in it — and a backup holds every user's
|
|
98
|
+
* address. Falling back to the media bucket's `S3_*` works, under the
|
|
99
|
+
* `backups/` prefix, and is reported as `shared: true` so the CLI can say so.
|
|
100
|
+
*/
|
|
101
|
+
export function backupStorageConfig(env = process.env) {
|
|
102
|
+
const own = Boolean(env.BACKUP_S3_BUCKET);
|
|
103
|
+
const pick = (name) => (own ? env[`BACKUP_S3_${name}`] ?? env[`S3_${name}`] : env[`S3_${name}`]);
|
|
104
|
+
const config = {
|
|
105
|
+
driver: 's3',
|
|
106
|
+
bucket: own ? env.BACKUP_S3_BUCKET : env.S3_BUCKET,
|
|
107
|
+
accessKeyId: pick('ACCESS_KEY_ID'),
|
|
108
|
+
secretAccessKey: pick('SECRET_ACCESS_KEY'),
|
|
109
|
+
endpoint: pick('ENDPOINT'),
|
|
110
|
+
region: pick('REGION') || 'auto'
|
|
111
|
+
};
|
|
112
|
+
if (!config.bucket || !config.accessKeyId || !config.secretAccessKey)
|
|
113
|
+
return null;
|
|
114
|
+
return { config, shared: !own, publicMediaUrl: !own && Boolean(env.S3_PUBLIC_URL) };
|
|
115
|
+
}
|
|
116
|
+
/** `backups/` unless told otherwise, always ending in exactly one slash. */
|
|
117
|
+
export function normalizePrefix(prefix = 'backups/') {
|
|
118
|
+
const trimmed = String(prefix).replace(/^\/+|\/+$/g, '');
|
|
119
|
+
if (!trimmed || trimmed.includes('..'))
|
|
120
|
+
throw new Error('--prefix must be a plain folder name such as backups');
|
|
121
|
+
return `${trimmed}/`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Write the JSON export to `path`, gzipped if asked.
|
|
125
|
+
*
|
|
126
|
+
* Streamed end to end — the export yields fragments and they go straight to
|
|
127
|
+
* the file — so a large site is never held in memory whole.
|
|
128
|
+
*/
|
|
129
|
+
export async function writeJsonBackup(db, path, { gzip = false, revisions = true, now } = {}) {
|
|
130
|
+
const source = Readable.from(exportChunks(db, { revisions, now }));
|
|
131
|
+
if (gzip)
|
|
132
|
+
await pipeline(source, createGzip({ level: 9 }), createWriteStream(path));
|
|
133
|
+
else
|
|
134
|
+
await pipeline(source, createWriteStream(path));
|
|
135
|
+
return (await stat(path)).size;
|
|
136
|
+
}
|
|
137
|
+
const quote = (value) => `'${String(value).replace(/'/g, "''")}'`;
|
|
138
|
+
/**
|
|
139
|
+
* A consistent copy of a SQLite database, with secrets removed.
|
|
140
|
+
*
|
|
141
|
+
* `VACUUM INTO` is SQLite's own online backup: one statement, a transaction-
|
|
142
|
+
* consistent snapshot even while the app is writing, and a compacted file.
|
|
143
|
+
* Copying the file with `cp` is not — a copy taken mid-write can be torn, and
|
|
144
|
+
* a WAL-mode database's recent writes are in the `-wal` file beside it.
|
|
145
|
+
*
|
|
146
|
+
* Only for a local file. Turso and Postgres back up on the provider's side
|
|
147
|
+
* (point-in-time recovery), and the JSON backup covers moving off them.
|
|
148
|
+
*/
|
|
149
|
+
export async function sqliteSnapshot(db, outPath) {
|
|
150
|
+
if ((db.driver ?? 'sqlite') !== 'sqlite') {
|
|
151
|
+
throw new Error(`--sqlite-copy needs the sqlite driver; this database is ${db.driver}. Use your provider's backups (Turso and Postgres both offer point-in-time recovery).`);
|
|
152
|
+
}
|
|
153
|
+
await db.exec(`VACUUM INTO ${quote(outPath)}`);
|
|
154
|
+
scrubSqliteCopy(outPath);
|
|
155
|
+
return (await stat(outPath)).size;
|
|
156
|
+
}
|
|
157
|
+
/** Every table that holds credentials or per-database state, plus the IP column. */
|
|
158
|
+
export function scrubSqliteCopy(path) {
|
|
159
|
+
const copy = new DatabaseSync(path);
|
|
160
|
+
try {
|
|
161
|
+
const tables = new Set(copy.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => row.name));
|
|
162
|
+
for (const table of NEVER_EXPORTED) {
|
|
163
|
+
if (table === '_migrations' || table === 'sqlite_sequence')
|
|
164
|
+
continue; // the schema's own bookkeeping, needed to restore
|
|
165
|
+
if (tables.has(table))
|
|
166
|
+
copy.exec(`DELETE FROM "${table}"`);
|
|
167
|
+
}
|
|
168
|
+
if (tables.has('users')) {
|
|
169
|
+
// A password hash is a credential; an offline copy is where it gets
|
|
170
|
+
// cracked. Accounts restored from this copy reset their password, the
|
|
171
|
+
// same as accounts restored from the JSON.
|
|
172
|
+
const update = copy.prepare('UPDATE users SET password = ? WHERE id = ?');
|
|
173
|
+
for (const { id } of copy.prepare('SELECT id FROM users').all())
|
|
174
|
+
update.run(unusablePassword(), id);
|
|
175
|
+
}
|
|
176
|
+
if (tables.has('comments')) {
|
|
177
|
+
const columns = copy.prepare('PRAGMA table_info(comments)').all().map((row) => row.name);
|
|
178
|
+
if (columns.includes('author_ip'))
|
|
179
|
+
copy.exec('UPDATE comments SET author_ip = NULL');
|
|
180
|
+
}
|
|
181
|
+
if (tables.has('settings')) {
|
|
182
|
+
const remove = copy.prepare('DELETE FROM settings WHERE key = ?');
|
|
183
|
+
for (const { key } of copy.prepare('SELECT key FROM settings').all()) {
|
|
184
|
+
if (isSecretSetting(key))
|
|
185
|
+
remove.run(key);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Deleted rows stay readable in free pages until the file is rebuilt.
|
|
189
|
+
copy.exec('VACUUM');
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
copy.close();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Delete local backups beyond the newest `keep`. Returns what was deleted. */
|
|
196
|
+
export async function pruneLocal(dir, keep) {
|
|
197
|
+
let names = [];
|
|
198
|
+
try {
|
|
199
|
+
names = await readdir(dir);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
const doomed = selectForDeletion(names, keep);
|
|
205
|
+
for (const name of doomed)
|
|
206
|
+
await rm(join(dir, name), { force: true });
|
|
207
|
+
return doomed;
|
|
208
|
+
}
|
|
209
|
+
/** Every key under the prefix, following continuation tokens. */
|
|
210
|
+
export async function listAll(storage, prefix) {
|
|
211
|
+
const keys = [];
|
|
212
|
+
let cursor;
|
|
213
|
+
do {
|
|
214
|
+
const page = await storage.list({ prefix, cursor });
|
|
215
|
+
for (const item of page.items)
|
|
216
|
+
keys.push(item.key);
|
|
217
|
+
cursor = page.cursor;
|
|
218
|
+
} while (cursor);
|
|
219
|
+
return keys;
|
|
220
|
+
}
|
|
221
|
+
/** Delete bucket backups beyond the newest `keep`. Only keys under `prefix`. */
|
|
222
|
+
export async function pruneBucket(storage, prefix, keep) {
|
|
223
|
+
const keys = (await listAll(storage, prefix)).filter((key) => key.startsWith(prefix));
|
|
224
|
+
const doomed = selectForDeletion(keys, keep);
|
|
225
|
+
for (const key of doomed)
|
|
226
|
+
await storage.delete(key);
|
|
227
|
+
return doomed;
|
|
228
|
+
}
|
|
229
|
+
/** Whether a buffer is gzip, by its magic number rather than its name. */
|
|
230
|
+
export function isGzip(buffer) {
|
|
231
|
+
return buffer.length > 2 && buffer[0] === 0x1f && buffer[1] === 0x8b;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Content tables that make a database "not empty" for restore purposes.
|
|
235
|
+
*
|
|
236
|
+
* Settings are deliberately not on the list: migrations seed defaults, so a
|
|
237
|
+
* freshly migrated database already has some.
|
|
238
|
+
*/
|
|
239
|
+
export const CONTENT_TABLES = ['users', 'posts', 'pages', 'comments', 'media', 'categories', 'tags'];
|
|
240
|
+
/** Row counts of the content tables that have rows. Missing tables count as empty. */
|
|
241
|
+
export async function nonEmptyTables(db) {
|
|
242
|
+
const found = {};
|
|
243
|
+
for (const table of CONTENT_TABLES) {
|
|
244
|
+
try {
|
|
245
|
+
const row = await db.get(`SELECT COUNT(*) AS n FROM "${table}"`);
|
|
246
|
+
const n = Number(row?.n ?? 0);
|
|
247
|
+
if (n > 0)
|
|
248
|
+
found[table] = n;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// Not migrated yet; the restore checks for that separately.
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return found;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Load a backup into a database: the JSON import, made fit for a restore.
|
|
258
|
+
*
|
|
259
|
+
* The importer was built for merging one site into another, which needs an
|
|
260
|
+
* admin already in the target to own orphaned content. A restore is the
|
|
261
|
+
* opposite case — the target is empty and the admins are *in the file* — so
|
|
262
|
+
* this imports the accounts first, takes the first imported admin as the
|
|
263
|
+
* fallback owner, and then imports everything else. Both passes are one
|
|
264
|
+
* transaction: a restore that fails halfway leaves the database as empty as
|
|
265
|
+
* it found it, not half a site that the "empty database only" rule would
|
|
266
|
+
* then refuse to restore over.
|
|
267
|
+
*
|
|
268
|
+
* Refuses a database that already has content unless `force` is set; with it,
|
|
269
|
+
* the import's usual merge rules apply (existing rows matched by natural key
|
|
270
|
+
* and left alone).
|
|
271
|
+
*/
|
|
272
|
+
export async function restoreBackup(db, doc, { force = false, dryRun = false, log } = {}) {
|
|
273
|
+
const existing = await nonEmptyTables(db);
|
|
274
|
+
if (Object.keys(existing).length && !force) {
|
|
275
|
+
const list = Object.entries(existing).map(([table, n]) => `${table} (${n})`).join(', ');
|
|
276
|
+
throw new Error(`The target database is not empty: ${list}.\n` +
|
|
277
|
+
'A restore is for an empty, freshly migrated database. Pass --force to merge into this one\n' +
|
|
278
|
+
'instead (existing rows are matched by slug/email and left alone) — after a --dry-run.');
|
|
279
|
+
}
|
|
280
|
+
const users = { ...doc, tables: { users: doc.tables.users ?? [] } };
|
|
281
|
+
const run = async (tx) => {
|
|
282
|
+
const accounts = await importExport(tx, users, { defaultAuthorId: null, log });
|
|
283
|
+
const admin = await defaultAuthor(tx);
|
|
284
|
+
if (!admin) {
|
|
285
|
+
throw new Error('The backup has no admin account, so restored content would have no owner. Register an admin first and use --force.');
|
|
286
|
+
}
|
|
287
|
+
const content = await importExport(tx, doc, { defaultAuthorId: admin.id, log, report: new Report() });
|
|
288
|
+
return { accounts, content, admin };
|
|
289
|
+
};
|
|
290
|
+
if (dryRun)
|
|
291
|
+
return withDryRun(db, true, run);
|
|
292
|
+
let result;
|
|
293
|
+
await db.transaction(async (tx) => {
|
|
294
|
+
result = await run(tx);
|
|
295
|
+
});
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object|string} input - the parsed export, or its JSON text
|
|
3
|
+
* @param {object} [options]
|
|
4
|
+
* @param {string} [options.siteUrl] - replaces `__GHOST_URL__`
|
|
5
|
+
* @param {boolean} [options.primaryTagAsCategory] - default true
|
|
6
|
+
*/
|
|
7
|
+
export function parseGhost(input: object | string, options?: {
|
|
8
|
+
siteUrl?: string | undefined;
|
|
9
|
+
primaryTagAsCategory?: boolean | undefined;
|
|
10
|
+
}): {
|
|
11
|
+
meta: {
|
|
12
|
+
version: any;
|
|
13
|
+
exportedOn: any;
|
|
14
|
+
};
|
|
15
|
+
authors: never[];
|
|
16
|
+
categories: never[];
|
|
17
|
+
tags: any;
|
|
18
|
+
media: never[];
|
|
19
|
+
posts: never[];
|
|
20
|
+
comments: never[];
|
|
21
|
+
notes: any[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The Markdown inside a Mobiledoc document's Markdown card, if it has one.
|
|
25
|
+
*
|
|
26
|
+
* Ghost 1–3 posts written in the Markdown editor are a single such card. Used
|
|
27
|
+
* only when the export has no `html` for a post (hand-trimmed exports, some
|
|
28
|
+
* migration tools), since the rendered HTML includes every other card too.
|
|
29
|
+
*/
|
|
30
|
+
export function markdownCard(mobiledoc: any): any;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a Ghost export (Settings → Labs → Export, Ghost 4 and 5) into the
|
|
3
|
+
* importer's site shape.
|
|
4
|
+
*
|
|
5
|
+
* ## Mapping decisions
|
|
6
|
+
*
|
|
7
|
+
* Body: Ghost stores Lexical (5) or Mobiledoc (4) JSON and renders it to the
|
|
8
|
+
* `html` column, which the export includes. That HTML is what readers saw, so
|
|
9
|
+
* it is the source, converted to Markdown like every other import. A post
|
|
10
|
+
* with no `html` falls back to a Mobiledoc Markdown card if it has one, then
|
|
11
|
+
* to `plaintext`. Lexical and Mobiledoc are not interpreted beyond that —
|
|
12
|
+
* they are editor document formats, and their rendered HTML says the same
|
|
13
|
+
* thing.
|
|
14
|
+
*
|
|
15
|
+
* Tags: Ghost has only tags. Every public tag becomes a tag here. Internal
|
|
16
|
+
* tags (`#name`) are Ghost's private labels for routing and theming, not
|
|
17
|
+
* something a reader sees, so they are not imported.
|
|
18
|
+
*
|
|
19
|
+
* Primary tag: a Ghost post's first tag is its "primary tag", which Ghost
|
|
20
|
+
* themes and routes use the way other CMSes use a category — the breadcrumb,
|
|
21
|
+
* the `/{primary_tag}/{slug}/` permalink. So by default the primary tag is
|
|
22
|
+
* *also* created as a category and set as the post's primary category; the
|
|
23
|
+
* tag stays a tag too, so nothing is lost. `primaryTagAsCategory: false`
|
|
24
|
+
* turns this off.
|
|
25
|
+
*
|
|
26
|
+
* Status: published → published; scheduled → published with a future
|
|
27
|
+
* publish_at; draft → draft; sent (email-only newsletter, never on the web)
|
|
28
|
+
* → draft, so it does not suddenly appear on the site.
|
|
29
|
+
*
|
|
30
|
+
* Members-only and paid posts are imported as ordinary posts: there is no
|
|
31
|
+
* content gating here. Each is counted in the notes so nothing is published
|
|
32
|
+
* that was behind a paywall without someone noticing.
|
|
33
|
+
*
|
|
34
|
+
* Images: Ghost writes `__GHOST_URL__` in exported URLs. Pass `siteUrl` to
|
|
35
|
+
* resolve it; without it those images keep a relative path and a note says so.
|
|
36
|
+
*/
|
|
37
|
+
const STATUS = { published: 'published', scheduled: 'published', draft: 'draft', sent: 'draft' };
|
|
38
|
+
/**
|
|
39
|
+
* @param {object|string} input - the parsed export, or its JSON text
|
|
40
|
+
* @param {object} [options]
|
|
41
|
+
* @param {string} [options.siteUrl] - replaces `__GHOST_URL__`
|
|
42
|
+
* @param {boolean} [options.primaryTagAsCategory] - default true
|
|
43
|
+
*/
|
|
44
|
+
export function parseGhost(input, options = {}) {
|
|
45
|
+
const json = typeof input === 'string' ? JSON.parse(input) : input;
|
|
46
|
+
// Ghost wraps the export in `db: [ … ]`; some tools unwrap it.
|
|
47
|
+
const root = Array.isArray(json?.db) ? json.db[0] : json;
|
|
48
|
+
const data = root?.data;
|
|
49
|
+
if (!data || !Array.isArray(data.posts))
|
|
50
|
+
throw new Error('Not a Ghost export: no data.posts');
|
|
51
|
+
const meta = root.meta ?? {};
|
|
52
|
+
const notes = [];
|
|
53
|
+
const primaryAsCategory = options.primaryTagAsCategory !== false;
|
|
54
|
+
const siteUrl = options.siteUrl?.replace(/\/$/, '');
|
|
55
|
+
let unresolvedUrls = 0;
|
|
56
|
+
const url = (value) => {
|
|
57
|
+
if (!value)
|
|
58
|
+
return null;
|
|
59
|
+
if (value.includes('__GHOST_URL__')) {
|
|
60
|
+
if (!siteUrl) {
|
|
61
|
+
unresolvedUrls++;
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return value.replaceAll('__GHOST_URL__', siteUrl);
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
};
|
|
68
|
+
const html = (value) => (value && siteUrl ? value.replaceAll('__GHOST_URL__', siteUrl) : value);
|
|
69
|
+
// Tags
|
|
70
|
+
const tags = data.tags ?? [];
|
|
71
|
+
const tagById = new Map(tags.map((t) => [t.id, t]));
|
|
72
|
+
const isInternal = (tag) => tag.visibility === 'internal' || String(tag.name ?? '').startsWith('#');
|
|
73
|
+
const site = {
|
|
74
|
+
meta: { version: meta.version ?? null, exportedOn: meta.exported_on ?? null },
|
|
75
|
+
authors: [],
|
|
76
|
+
categories: [],
|
|
77
|
+
tags: tags.filter((t) => !isInternal(t)).map((t) => ({ key: t.id, slug: t.slug, name: t.name })),
|
|
78
|
+
media: [],
|
|
79
|
+
posts: [],
|
|
80
|
+
comments: [],
|
|
81
|
+
notes
|
|
82
|
+
};
|
|
83
|
+
// Authors. Ghost's roles are not carried over: everyone arrives as `author`.
|
|
84
|
+
for (const user of data.users ?? []) {
|
|
85
|
+
site.authors.push({
|
|
86
|
+
key: user.id,
|
|
87
|
+
name: user.name,
|
|
88
|
+
email: user.email || null,
|
|
89
|
+
slug: user.slug,
|
|
90
|
+
bio: user.bio || null,
|
|
91
|
+
website: user.website || null,
|
|
92
|
+
avatarUrl: url(user.profile_image),
|
|
93
|
+
createdAt: user.created_at
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Join tables, in sort order: the first tag and the first author are the
|
|
97
|
+
// primary ones.
|
|
98
|
+
const byPost = (rows, field) => {
|
|
99
|
+
const map = new Map();
|
|
100
|
+
for (const row of [...(rows ?? [])].sort((a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0))) {
|
|
101
|
+
if (!map.has(row.post_id))
|
|
102
|
+
map.set(row.post_id, []);
|
|
103
|
+
map.get(row.post_id).push(row[field]);
|
|
104
|
+
}
|
|
105
|
+
return map;
|
|
106
|
+
};
|
|
107
|
+
const postTags = byPost(data.posts_tags, 'tag_id');
|
|
108
|
+
const postAuthors = byPost(data.posts_authors, 'author_id');
|
|
109
|
+
// Ghost 4+ moved the SEO fields to their own table; Ghost 3 kept them on the post.
|
|
110
|
+
const postsMeta = new Map((data.posts_meta ?? []).map((m) => [m.post_id, m]));
|
|
111
|
+
const primaryCategories = new Map();
|
|
112
|
+
let gated = 0;
|
|
113
|
+
let skipped = 0;
|
|
114
|
+
for (const post of data.posts) {
|
|
115
|
+
const status = STATUS[post.status];
|
|
116
|
+
if (!status) {
|
|
117
|
+
skipped++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (post.status === 'sent')
|
|
121
|
+
notes.push(`"${post.title}" was an email-only newsletter and is imported as a draft`);
|
|
122
|
+
if (post.visibility && post.visibility !== 'public')
|
|
123
|
+
gated++;
|
|
124
|
+
const seo = { ...post, ...(postsMeta.get(post.id) ?? {}) };
|
|
125
|
+
const tagIds = (postTags.get(post.id) ?? []).filter((id) => tagById.has(id) && !isInternal(tagById.get(id)));
|
|
126
|
+
const categoryKeys = [];
|
|
127
|
+
if (primaryAsCategory && post.type !== 'page' && tagIds.length) {
|
|
128
|
+
const primary = tagById.get(tagIds[0]);
|
|
129
|
+
const key = `category:${primary.id}`;
|
|
130
|
+
if (!primaryCategories.has(key)) {
|
|
131
|
+
primaryCategories.set(key, { key, slug: primary.slug, name: primary.name, description: primary.description || null });
|
|
132
|
+
}
|
|
133
|
+
categoryKeys.push(key);
|
|
134
|
+
}
|
|
135
|
+
const body = html(post.html) || markdownCard(post.mobiledoc);
|
|
136
|
+
const bodyIsMarkdown = !post.html && Boolean(body);
|
|
137
|
+
site.posts.push({
|
|
138
|
+
key: post.id,
|
|
139
|
+
type: post.type === 'page' ? 'page' : 'post',
|
|
140
|
+
title: post.title,
|
|
141
|
+
slug: post.slug,
|
|
142
|
+
html: bodyIsMarkdown ? null : body || null,
|
|
143
|
+
markdown: bodyIsMarkdown ? body : body ? undefined : post.plaintext || '',
|
|
144
|
+
excerpt: post.custom_excerpt || null,
|
|
145
|
+
status,
|
|
146
|
+
publishAt: status === 'published' ? post.published_at : null,
|
|
147
|
+
createdAt: post.created_at,
|
|
148
|
+
updatedAt: post.updated_at,
|
|
149
|
+
authorKey: (postAuthors.get(post.id) ?? [])[0] ?? post.author_id ?? null,
|
|
150
|
+
categoryKeys,
|
|
151
|
+
tagKeys: tagIds,
|
|
152
|
+
featuredImage: url(post.feature_image),
|
|
153
|
+
template: 'default',
|
|
154
|
+
seo: {
|
|
155
|
+
meta_title: seo.meta_title || null,
|
|
156
|
+
meta_description: seo.meta_description || null,
|
|
157
|
+
og_title: seo.og_title || null,
|
|
158
|
+
og_description: seo.og_description || null,
|
|
159
|
+
og_image: url(seo.og_image),
|
|
160
|
+
twitter_title: seo.twitter_title || null,
|
|
161
|
+
twitter_description: seo.twitter_description || null,
|
|
162
|
+
twitter_image: url(seo.twitter_image),
|
|
163
|
+
canonical_url: post.canonical_url || null,
|
|
164
|
+
noindex: false
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
if (post.feature_image && seo.feature_image_alt) {
|
|
168
|
+
const featured = url(post.feature_image);
|
|
169
|
+
if (featured)
|
|
170
|
+
site.media.push({ url: featured, alt: seo.feature_image_alt });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
site.categories = [...primaryCategories.values()];
|
|
174
|
+
if (gated)
|
|
175
|
+
notes.push(`${gated} post(s) were members-only or paid in Ghost; there is no content gating here, so they are imported as ordinary posts`);
|
|
176
|
+
if (skipped)
|
|
177
|
+
notes.push(`${skipped} post(s) with an unrecognised status were not imported`);
|
|
178
|
+
if (unresolvedUrls)
|
|
179
|
+
notes.push(`${unresolvedUrls} image URL(s) used __GHOST_URL__; pass --url https://your-ghost-site to resolve them`);
|
|
180
|
+
return site;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The Markdown inside a Mobiledoc document's Markdown card, if it has one.
|
|
184
|
+
*
|
|
185
|
+
* Ghost 1–3 posts written in the Markdown editor are a single such card. Used
|
|
186
|
+
* only when the export has no `html` for a post (hand-trimmed exports, some
|
|
187
|
+
* migration tools), since the rendered HTML includes every other card too.
|
|
188
|
+
*/
|
|
189
|
+
export function markdownCard(mobiledoc) {
|
|
190
|
+
try {
|
|
191
|
+
const doc = typeof mobiledoc === 'string' ? JSON.parse(mobiledoc) : mobiledoc;
|
|
192
|
+
const parts = (doc?.cards ?? [])
|
|
193
|
+
.filter(([name]) => name === 'markdown' || name === 'card-markdown')
|
|
194
|
+
.map(([, payload]) => payload?.markdown)
|
|
195
|
+
.filter(Boolean);
|
|
196
|
+
return parts.length ? parts.join('\n\n') : null;
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
}
|