@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,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a WordPress export (WXR) file into the importer's site shape.
|
|
3
|
+
*
|
|
4
|
+
* WXR is what Tools → Export in wp-admin produces: RSS 2.0 with WordPress's
|
|
5
|
+
* own elements under the `wp:` prefix. It works offline — no API, no
|
|
6
|
+
* credentials, nothing the old site has to still be running for — and it
|
|
7
|
+
* carries what the REST API hides from anonymous callers: drafts, private
|
|
8
|
+
* posts, author addresses, every comment and its moderation state.
|
|
9
|
+
*
|
|
10
|
+
* ## Mapping decisions
|
|
11
|
+
*
|
|
12
|
+
* Status:
|
|
13
|
+
* publish → published (publish_at = post_date_gmt)
|
|
14
|
+
* future → published with a future publish_at, so it goes live on time
|
|
15
|
+
* draft → draft
|
|
16
|
+
* pending → pending (awaiting review, as here)
|
|
17
|
+
* private → draft. There is no "visible to logged-in editors only" state
|
|
18
|
+
* here, and publishing a private post would expose it; a draft
|
|
19
|
+
* keeps it out of public reads and in the editor.
|
|
20
|
+
* trash, auto-draft, inherit (revisions) → not imported.
|
|
21
|
+
*
|
|
22
|
+
* Comments: approved `1` → approved, `0` → pending, `spam` → spam (see the
|
|
23
|
+
* writer for what happens without a spam column), `trash` → not imported.
|
|
24
|
+
* Pingbacks and trackbacks are not imported: they are link notifications from
|
|
25
|
+
* another era, not conversation, and nearly all of them are spam.
|
|
26
|
+
*
|
|
27
|
+
* Content: `content:encoded` is the post as the author saved it, not as the
|
|
28
|
+
* site rendered it, so it goes through `autop` (WordPress adds paragraph tags
|
|
29
|
+
* at display time) and the `[caption]`/`[embed]` shortcodes are expanded.
|
|
30
|
+
* Other shortcodes are left visible for an editor to replace.
|
|
31
|
+
*
|
|
32
|
+
* SEO: Yoast's post meta (`_yoast_wpseo_*`) fills the title, description,
|
|
33
|
+
* canonical, Open Graph and Twitter fields, and its noindex flag.
|
|
34
|
+
*/
|
|
35
|
+
import { parseXml, child, childrenNamed, childText, textOf } from './xml.mjs';
|
|
36
|
+
import { autop, expandShortcodes, plainText, decodeEntities } from './html-to-markdown.mjs';
|
|
37
|
+
const STATUS = { publish: 'published', future: 'published', draft: 'draft', pending: 'pending', private: 'draft' };
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} xml - the WXR file's contents
|
|
40
|
+
* @returns {object} the site shape `importSite` takes, plus `meta` and `notes`
|
|
41
|
+
*/
|
|
42
|
+
export function parseWxr(xml) {
|
|
43
|
+
const doc = parseXml(xml);
|
|
44
|
+
const rss = child(doc, 'rss');
|
|
45
|
+
const channel = child(rss, 'channel');
|
|
46
|
+
if (!channel)
|
|
47
|
+
throw new Error('Not a WordPress export: no <rss><channel>');
|
|
48
|
+
const version = childText(channel, 'wp:wxr_version');
|
|
49
|
+
if (!version)
|
|
50
|
+
throw new Error('Not a WordPress export: no <wp:wxr_version>');
|
|
51
|
+
const notes = [];
|
|
52
|
+
const site = {
|
|
53
|
+
meta: {
|
|
54
|
+
title: childText(channel, 'title'),
|
|
55
|
+
link: childText(channel, 'link'),
|
|
56
|
+
baseUrl: childText(channel, 'wp:base_blog_url') || childText(channel, 'wp:base_site_url'),
|
|
57
|
+
wxrVersion: version
|
|
58
|
+
},
|
|
59
|
+
authors: [],
|
|
60
|
+
categories: [],
|
|
61
|
+
tags: [],
|
|
62
|
+
media: [],
|
|
63
|
+
posts: [],
|
|
64
|
+
comments: [],
|
|
65
|
+
notes
|
|
66
|
+
};
|
|
67
|
+
// Authors are keyed by login, because that is what each item's
|
|
68
|
+
// `dc:creator` names. WordPress ids are kept for comments' `comment_user_id`.
|
|
69
|
+
const loginByWpId = new Map();
|
|
70
|
+
for (const node of childrenNamed(channel, 'wp:author')) {
|
|
71
|
+
const login = childText(node, 'wp:author_login');
|
|
72
|
+
if (!login)
|
|
73
|
+
continue;
|
|
74
|
+
const first = childText(node, 'wp:author_first_name');
|
|
75
|
+
const last = childText(node, 'wp:author_last_name');
|
|
76
|
+
site.authors.push({
|
|
77
|
+
key: login,
|
|
78
|
+
name: childText(node, 'wp:author_display_name') || [first, last].filter(Boolean).join(' ') || login,
|
|
79
|
+
email: childText(node, 'wp:author_email') || null,
|
|
80
|
+
slug: login
|
|
81
|
+
});
|
|
82
|
+
const wpId = childText(node, 'wp:author_id');
|
|
83
|
+
if (wpId)
|
|
84
|
+
loginByWpId.set(wpId, login);
|
|
85
|
+
}
|
|
86
|
+
// Categories. A parent is named by its nicename (slug), which is also each
|
|
87
|
+
// category's key, so hierarchy needs no id lookup.
|
|
88
|
+
for (const node of childrenNamed(channel, 'wp:category')) {
|
|
89
|
+
const slug = decodeURIComponent(childText(node, 'wp:category_nicename'));
|
|
90
|
+
if (!slug)
|
|
91
|
+
continue;
|
|
92
|
+
site.categories.push({
|
|
93
|
+
key: slug,
|
|
94
|
+
slug,
|
|
95
|
+
name: decodeEntities(childText(node, 'wp:cat_name')) || slug,
|
|
96
|
+
description: decodeEntities(childText(node, 'wp:category_description')) || null,
|
|
97
|
+
parentKey: decodeURIComponent(childText(node, 'wp:category_parent')) || null
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
for (const node of childrenNamed(channel, 'wp:tag')) {
|
|
101
|
+
const slug = decodeURIComponent(childText(node, 'wp:tag_slug'));
|
|
102
|
+
if (!slug)
|
|
103
|
+
continue;
|
|
104
|
+
site.tags.push({ key: slug, slug, name: decodeEntities(childText(node, 'wp:tag_name')) || slug });
|
|
105
|
+
}
|
|
106
|
+
const knownCategories = new Set(site.categories.map((c) => c.key));
|
|
107
|
+
const knownTags = new Set(site.tags.map((t) => t.key));
|
|
108
|
+
const items = childrenNamed(channel, 'item');
|
|
109
|
+
// Attachments first: posts refer to them by id through `_thumbnail_id`.
|
|
110
|
+
for (const item of items) {
|
|
111
|
+
if (childText(item, 'wp:post_type') !== 'attachment')
|
|
112
|
+
continue;
|
|
113
|
+
const url = childText(item, 'wp:attachment_url') || childText(item, 'guid');
|
|
114
|
+
if (!url)
|
|
115
|
+
continue;
|
|
116
|
+
const meta = postMeta(item);
|
|
117
|
+
const dims = attachmentDimensions(meta._wp_attachment_metadata);
|
|
118
|
+
site.media.push({
|
|
119
|
+
key: `attachment:${childText(item, 'wp:post_id')}`,
|
|
120
|
+
url,
|
|
121
|
+
alt: decodeEntities(meta._wp_attachment_image_alt || '') || null,
|
|
122
|
+
width: dims.width,
|
|
123
|
+
height: dims.height,
|
|
124
|
+
size: dims.filesize,
|
|
125
|
+
mimeType: null,
|
|
126
|
+
createdAt: gmt(item, 'wp:post_date_gmt', 'wp:post_date')
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
let skippedStatuses = 0;
|
|
130
|
+
let pingbacks = 0;
|
|
131
|
+
let otherTypes = 0;
|
|
132
|
+
for (const item of items) {
|
|
133
|
+
const type = childText(item, 'wp:post_type');
|
|
134
|
+
if (type === 'attachment')
|
|
135
|
+
continue;
|
|
136
|
+
if (type !== 'post' && type !== 'page') {
|
|
137
|
+
// Navigation menu items, reusable blocks, custom post types.
|
|
138
|
+
otherTypes++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const wpStatus = childText(item, 'wp:status');
|
|
142
|
+
const status = STATUS[wpStatus];
|
|
143
|
+
if (!status) {
|
|
144
|
+
skippedStatuses++;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (wpStatus === 'private') {
|
|
148
|
+
notes.push(`"${childText(item, 'title')}" was private in WordPress and is imported as a draft`);
|
|
149
|
+
}
|
|
150
|
+
const id = childText(item, 'wp:post_id');
|
|
151
|
+
const meta = postMeta(item);
|
|
152
|
+
const raw = textOf(child(item, 'content:encoded'));
|
|
153
|
+
const excerptRaw = textOf(child(item, 'excerpt:encoded')).trim();
|
|
154
|
+
const date = gmt(item, 'wp:post_date_gmt', 'wp:post_date');
|
|
155
|
+
const terms = childrenNamed(item, 'category');
|
|
156
|
+
const categoryKeys = [];
|
|
157
|
+
const tagKeys = [];
|
|
158
|
+
for (const term of terms) {
|
|
159
|
+
const slug = decodeURIComponent(term.attrs.nicename || '');
|
|
160
|
+
const name = decodeEntities(textOf(term).trim());
|
|
161
|
+
if (!slug)
|
|
162
|
+
continue;
|
|
163
|
+
// A term used on a post but missing from the channel's term list —
|
|
164
|
+
// WordPress omits terms in some partial exports — is added here.
|
|
165
|
+
if (term.attrs.domain === 'category') {
|
|
166
|
+
if (!knownCategories.has(slug)) {
|
|
167
|
+
knownCategories.add(slug);
|
|
168
|
+
site.categories.push({ key: slug, slug, name: name || slug, description: null, parentKey: null });
|
|
169
|
+
}
|
|
170
|
+
categoryKeys.push(slug);
|
|
171
|
+
}
|
|
172
|
+
else if (term.attrs.domain === 'post_tag') {
|
|
173
|
+
if (!knownTags.has(slug)) {
|
|
174
|
+
knownTags.add(slug);
|
|
175
|
+
site.tags.push({ key: slug, slug, name: name || slug });
|
|
176
|
+
}
|
|
177
|
+
tagKeys.push(slug);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const template = meta._wp_page_template;
|
|
181
|
+
const thumbnail = meta._thumbnail_id;
|
|
182
|
+
site.posts.push({
|
|
183
|
+
key: id,
|
|
184
|
+
type,
|
|
185
|
+
title: decodeEntities(childText(item, 'title')),
|
|
186
|
+
// A draft that was never given a slug has an empty post_name; the
|
|
187
|
+
// writer derives one from the title.
|
|
188
|
+
slug: decodeURIComponent(childText(item, 'wp:post_name')),
|
|
189
|
+
html: autop(expandShortcodes(raw)),
|
|
190
|
+
excerpt: excerptRaw ? plainText(autop(excerptRaw)) : null,
|
|
191
|
+
status,
|
|
192
|
+
publishAt: status === 'published' ? date : null,
|
|
193
|
+
createdAt: date,
|
|
194
|
+
updatedAt: gmt(item, 'wp:post_modified_gmt', 'wp:post_modified') || date,
|
|
195
|
+
authorKey: childText(item, 'dc:creator') || null,
|
|
196
|
+
categoryKeys,
|
|
197
|
+
tagKeys,
|
|
198
|
+
featuredImage: thumbnail ? `attachment:${thumbnail}` : null,
|
|
199
|
+
parentKey: type === 'page' && childText(item, 'wp:post_parent') !== '0' ? childText(item, 'wp:post_parent') || null : null,
|
|
200
|
+
menuOrder: Number(childText(item, 'wp:menu_order')) || 0,
|
|
201
|
+
template: pageTemplate(template),
|
|
202
|
+
seo: yoast(meta)
|
|
203
|
+
});
|
|
204
|
+
for (const node of childrenNamed(item, 'wp:comment')) {
|
|
205
|
+
const approved = childText(node, 'wp:comment_approved');
|
|
206
|
+
const commentType = childText(node, 'wp:comment_type');
|
|
207
|
+
if (commentType === 'pingback' || commentType === 'trackback') {
|
|
208
|
+
pingbacks++;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (approved === 'trash' || approved === 'post-trashed')
|
|
212
|
+
continue;
|
|
213
|
+
const parent = childText(node, 'wp:comment_parent');
|
|
214
|
+
const userId = childText(node, 'wp:comment_user_id');
|
|
215
|
+
site.comments.push({
|
|
216
|
+
key: `${id}:${childText(node, 'wp:comment_id')}`,
|
|
217
|
+
postKey: id,
|
|
218
|
+
parentKey: parent && parent !== '0' ? `${id}:${parent}` : null,
|
|
219
|
+
authorName: decodeEntities(childText(node, 'wp:comment_author')) || null,
|
|
220
|
+
authorEmail: childText(node, 'wp:comment_author_email') || null,
|
|
221
|
+
userKey: userId && userId !== '0' ? loginByWpId.get(userId) ?? null : null,
|
|
222
|
+
html: textOf(child(node, 'wp:comment_content')),
|
|
223
|
+
status: approved === '1' ? 'approved' : approved === 'spam' ? 'spam' : 'pending',
|
|
224
|
+
createdAt: gmt(node, 'wp:comment_date_gmt', 'wp:comment_date')
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (skippedStatuses)
|
|
229
|
+
notes.push(`${skippedStatuses} item(s) in the trash, auto-drafts or revisions were not imported`);
|
|
230
|
+
if (pingbacks)
|
|
231
|
+
notes.push(`${pingbacks} pingback(s)/trackback(s) were not imported`);
|
|
232
|
+
if (otherTypes)
|
|
233
|
+
notes.push(`${otherTypes} item(s) of other types (menu items, blocks, custom post types) were not imported`);
|
|
234
|
+
return site;
|
|
235
|
+
}
|
|
236
|
+
/** `wp:postmeta` as a plain object. */
|
|
237
|
+
function postMeta(item) {
|
|
238
|
+
const meta = {};
|
|
239
|
+
for (const node of childrenNamed(item, 'wp:postmeta')) {
|
|
240
|
+
const key = childText(node, 'wp:meta_key');
|
|
241
|
+
if (key)
|
|
242
|
+
meta[key] = textOf(child(node, 'wp:meta_value'));
|
|
243
|
+
}
|
|
244
|
+
return meta;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* A date field, preferring the GMT one.
|
|
248
|
+
*
|
|
249
|
+
* WordPress stores both; the local one carries no zone, so reading it as UTC
|
|
250
|
+
* is off by the site's offset. It is the fallback only because drafts can
|
|
251
|
+
* have a GMT date of all zeroes.
|
|
252
|
+
*/
|
|
253
|
+
function gmt(node, gmtField, localField) {
|
|
254
|
+
const value = childText(node, gmtField);
|
|
255
|
+
if (value && !value.startsWith('0000'))
|
|
256
|
+
return value;
|
|
257
|
+
const local = childText(node, localField);
|
|
258
|
+
return local && !local.startsWith('0000') ? local : null;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Width, height and size out of `_wp_attachment_metadata`.
|
|
262
|
+
*
|
|
263
|
+
* That value is PHP's `serialize()` format. Unserializing PHP is a known way
|
|
264
|
+
* to get into trouble, and only three integers are wanted, so they are read
|
|
265
|
+
* with a pattern instead: the top-level `width` comes first, before the
|
|
266
|
+
* `sizes` array repeats the key for every thumbnail.
|
|
267
|
+
*/
|
|
268
|
+
export function attachmentDimensions(serialized) {
|
|
269
|
+
const text = String(serialized ?? '');
|
|
270
|
+
const int = (key) => {
|
|
271
|
+
const m = new RegExp(`s:${key.length}:"${key}";i:(\\d+);`).exec(text);
|
|
272
|
+
return m ? Number(m[1]) : null;
|
|
273
|
+
};
|
|
274
|
+
return { width: int('width'), height: int('height'), filesize: int('filesize') };
|
|
275
|
+
}
|
|
276
|
+
/** `page-templates/full-width.php` → `full-width`; WordPress's default → `default`. */
|
|
277
|
+
function pageTemplate(value) {
|
|
278
|
+
if (!value || value === 'default')
|
|
279
|
+
return 'default';
|
|
280
|
+
return value.split('/').pop().replace(/\.php$/, '') || 'default';
|
|
281
|
+
}
|
|
282
|
+
/** Yoast SEO's post meta, mapped onto this CMS's fields. */
|
|
283
|
+
function yoast(meta) {
|
|
284
|
+
const get = (key) => decodeEntities(meta[`_yoast_wpseo_${key}`] ?? '').trim() || null;
|
|
285
|
+
return {
|
|
286
|
+
meta_title: stripYoastVars(get('title')),
|
|
287
|
+
meta_description: stripYoastVars(get('metadesc')),
|
|
288
|
+
canonical_url: get('canonical'),
|
|
289
|
+
og_title: stripYoastVars(get('opengraph-title')),
|
|
290
|
+
og_description: stripYoastVars(get('opengraph-description')),
|
|
291
|
+
og_image: get('opengraph-image'),
|
|
292
|
+
twitter_title: stripYoastVars(get('twitter-title')),
|
|
293
|
+
twitter_description: stripYoastVars(get('twitter-description')),
|
|
294
|
+
twitter_image: get('twitter-image'),
|
|
295
|
+
noindex: meta['_yoast_wpseo_meta-robots-noindex'] === '1'
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Yoast titles are templates (`%%title%% %%sep%% %%sitename%%`). A template
|
|
300
|
+
* means nothing here, and the CMS falls back to the post's own title when the
|
|
301
|
+
* field is empty, so a value that is mostly variables is dropped.
|
|
302
|
+
*/
|
|
303
|
+
function stripYoastVars(value) {
|
|
304
|
+
if (!value || !value.includes('%%'))
|
|
305
|
+
return value;
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode the entities XML itself defines, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* An unknown named entity is left as literal text rather than failing the
|
|
5
|
+
* whole file — WordPress has been known to let ` ` slip into a field it
|
|
6
|
+
* did not wrap in CDATA, and dropping a post over it would be worse.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function decodeXmlEntities(text: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Parse a document into a tree.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} source
|
|
16
|
+
* @returns {{ name: '#document', attrs: {}, children: Array }}
|
|
17
|
+
*/
|
|
18
|
+
export function parseXml(source: string): {
|
|
19
|
+
name: "#document";
|
|
20
|
+
attrs: {};
|
|
21
|
+
children: any[];
|
|
22
|
+
};
|
|
23
|
+
/** The first child element called `name`. */
|
|
24
|
+
export function child(node: any, name: any): any;
|
|
25
|
+
/** Every child element called `name`. */
|
|
26
|
+
export function childrenNamed(node: any, name: any): any;
|
|
27
|
+
/** All the text inside a node, CDATA included. */
|
|
28
|
+
export function textOf(node: any): any;
|
|
29
|
+
/** The trimmed text of the first child called `name`, or ''. */
|
|
30
|
+
export function childText(node: any, name: any): any;
|
|
31
|
+
export class XmlError extends Error {
|
|
32
|
+
constructor(message: any, source: any, index: any);
|
|
33
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small XML parser, for WordPress export (WXR) files and nothing grander.
|
|
3
|
+
*
|
|
4
|
+
* ## Why not a library
|
|
5
|
+
*
|
|
6
|
+
* The project takes no new dependencies, and WXR is a narrow subset of XML:
|
|
7
|
+
* elements, attributes, text, CDATA, comments and a processing instruction at
|
|
8
|
+
* the top. Namespaces appear only as prefixes (`wp:post_id`,
|
|
9
|
+
* `content:encoded`), and nothing in a WXR file needs them resolved to URIs —
|
|
10
|
+
* so names are kept exactly as written and looked up the same way.
|
|
11
|
+
*
|
|
12
|
+
* ## Why it refuses DTDs
|
|
13
|
+
*
|
|
14
|
+
* Entity declarations are how XML parsers get exploited: an internal subset
|
|
15
|
+
* can define an entity that expands a billion times ("billion laughs"), or an
|
|
16
|
+
* external one that reads a file off the importing machine. An export file is
|
|
17
|
+
* input from somewhere else, so a document carrying an internal DTD subset is
|
|
18
|
+
* refused outright, and only the five predefined entities and numeric
|
|
19
|
+
* character references are ever decoded. WordPress never writes a DTD, so a
|
|
20
|
+
* real export never trips this.
|
|
21
|
+
*
|
|
22
|
+
* ## Shape
|
|
23
|
+
*
|
|
24
|
+
* Elements are `{ name, attrs, children }`, text is a plain string in
|
|
25
|
+
* `children`. CDATA becomes text verbatim. Comments and processing
|
|
26
|
+
* instructions are dropped.
|
|
27
|
+
*/
|
|
28
|
+
const PREDEFINED = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'" };
|
|
29
|
+
/** Past this a document is either hostile or broken; WXR nests about six deep. */
|
|
30
|
+
const MAX_DEPTH = 256;
|
|
31
|
+
export class XmlError extends Error {
|
|
32
|
+
constructor(message, source, index) {
|
|
33
|
+
const line = source.slice(0, index).split('\n').length;
|
|
34
|
+
super(`${message} (line ${line})`);
|
|
35
|
+
this.name = 'XmlError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decode the entities XML itself defines, and nothing else.
|
|
40
|
+
*
|
|
41
|
+
* An unknown named entity is left as literal text rather than failing the
|
|
42
|
+
* whole file — WordPress has been known to let ` ` slip into a field it
|
|
43
|
+
* did not wrap in CDATA, and dropping a post over it would be worse.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} text
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
export function decodeXmlEntities(text) {
|
|
49
|
+
return text.replace(/&(#[xX][0-9a-fA-F]{1,6}|#[0-9]{1,7}|[A-Za-z]+);/g, (match, body) => {
|
|
50
|
+
if (body[0] !== '#')
|
|
51
|
+
return PREDEFINED[body] ?? match;
|
|
52
|
+
const code = body[1] === 'x' || body[1] === 'X'
|
|
53
|
+
? parseInt(body.slice(2), 16)
|
|
54
|
+
: parseInt(body.slice(1), 10);
|
|
55
|
+
// Surrogate halves and out-of-range values are not characters.
|
|
56
|
+
if (!code || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff))
|
|
57
|
+
return '�';
|
|
58
|
+
return String.fromCodePoint(code);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse a document into a tree.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} source
|
|
65
|
+
* @returns {{ name: '#document', attrs: {}, children: Array }}
|
|
66
|
+
*/
|
|
67
|
+
export function parseXml(source) {
|
|
68
|
+
const src = String(source).replace(/^/, '');
|
|
69
|
+
const root = { name: '#document', attrs: {}, children: [] };
|
|
70
|
+
const stack = [root];
|
|
71
|
+
let i = 0;
|
|
72
|
+
const top = () => stack[stack.length - 1];
|
|
73
|
+
const expect = (token, from) => {
|
|
74
|
+
const end = src.indexOf(token, from);
|
|
75
|
+
if (end === -1)
|
|
76
|
+
throw new XmlError(`Unterminated construct, expected "${token}"`, src, from);
|
|
77
|
+
return end;
|
|
78
|
+
};
|
|
79
|
+
while (i < src.length) {
|
|
80
|
+
const lt = src.indexOf('<', i);
|
|
81
|
+
if (lt === -1) {
|
|
82
|
+
pushText(top(), decodeXmlEntities(src.slice(i)));
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (lt > i)
|
|
86
|
+
pushText(top(), decodeXmlEntities(src.slice(i, lt)));
|
|
87
|
+
if (src.startsWith('<!--', lt)) {
|
|
88
|
+
i = expect('-->', lt + 4) + 3;
|
|
89
|
+
}
|
|
90
|
+
else if (src.startsWith('<![CDATA[', lt)) {
|
|
91
|
+
const end = expect(']]>', lt + 9);
|
|
92
|
+
pushText(top(), src.slice(lt + 9, end));
|
|
93
|
+
i = end + 3;
|
|
94
|
+
}
|
|
95
|
+
else if (src.startsWith('<?', lt)) {
|
|
96
|
+
i = expect('?>', lt + 2) + 2;
|
|
97
|
+
}
|
|
98
|
+
else if (src.startsWith('<!', lt)) {
|
|
99
|
+
// A DOCTYPE. Skipped if it is only a name; refused if it declares
|
|
100
|
+
// anything, since declarations are what entity expansion attacks use.
|
|
101
|
+
const end = expect('>', lt);
|
|
102
|
+
if (src.slice(lt, end).includes('[')) {
|
|
103
|
+
throw new XmlError('Documents with a DTD internal subset are not accepted', src, lt);
|
|
104
|
+
}
|
|
105
|
+
i = end + 1;
|
|
106
|
+
}
|
|
107
|
+
else if (src[lt + 1] === '/') {
|
|
108
|
+
const end = expect('>', lt);
|
|
109
|
+
const name = src.slice(lt + 2, end).trim();
|
|
110
|
+
const open = top();
|
|
111
|
+
if (open === root || open.name !== name) {
|
|
112
|
+
throw new XmlError(`Unexpected closing tag </${name}>${open === root ? '' : `, expected </${open.name}>`}`, src, lt);
|
|
113
|
+
}
|
|
114
|
+
stack.pop();
|
|
115
|
+
i = end + 1;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const { element, end, selfClosing } = readTag(src, lt);
|
|
119
|
+
top().children.push(element);
|
|
120
|
+
if (!selfClosing) {
|
|
121
|
+
if (stack.length > MAX_DEPTH)
|
|
122
|
+
throw new XmlError('Document nests too deeply', src, lt);
|
|
123
|
+
stack.push(element);
|
|
124
|
+
}
|
|
125
|
+
i = end;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (stack.length > 1) {
|
|
129
|
+
throw new XmlError(`Unclosed element <${top().name}>`, src, src.length);
|
|
130
|
+
}
|
|
131
|
+
return root;
|
|
132
|
+
}
|
|
133
|
+
/** Merge adjacent text, so a field split by CDATA reads as one string. */
|
|
134
|
+
function pushText(parent, text) {
|
|
135
|
+
if (!text)
|
|
136
|
+
return;
|
|
137
|
+
const last = parent.children.length - 1;
|
|
138
|
+
if (typeof parent.children[last] === 'string')
|
|
139
|
+
parent.children[last] += text;
|
|
140
|
+
else
|
|
141
|
+
parent.children.push(text);
|
|
142
|
+
}
|
|
143
|
+
/** Read `<name a="b" c='d'>` or `<name/>` starting at `start`. */
|
|
144
|
+
function readTag(src, start) {
|
|
145
|
+
let i = start + 1;
|
|
146
|
+
const nameMatch = /^[^\s/>]+/.exec(src.slice(i, i + 256));
|
|
147
|
+
if (!nameMatch)
|
|
148
|
+
throw new XmlError('Malformed tag', src, start);
|
|
149
|
+
const name = nameMatch[0];
|
|
150
|
+
const attrs = {};
|
|
151
|
+
i += name.length;
|
|
152
|
+
while (i < src.length) {
|
|
153
|
+
while (/\s/.test(src[i]))
|
|
154
|
+
i++;
|
|
155
|
+
if (src[i] === '>')
|
|
156
|
+
return { element: { name, attrs, children: [] }, end: i + 1, selfClosing: false };
|
|
157
|
+
if (src[i] === '/' && src[i + 1] === '>')
|
|
158
|
+
return { element: { name, attrs, children: [] }, end: i + 2, selfClosing: true };
|
|
159
|
+
const attrMatch = /^([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')/.exec(src.slice(i, i + 65536));
|
|
160
|
+
if (!attrMatch)
|
|
161
|
+
throw new XmlError(`Malformed attribute in <${name}>`, src, i);
|
|
162
|
+
attrs[attrMatch[1]] = decodeXmlEntities(attrMatch[3] ?? attrMatch[4] ?? '');
|
|
163
|
+
i += attrMatch[0].length;
|
|
164
|
+
}
|
|
165
|
+
throw new XmlError(`Unterminated tag <${name}>`, src, start);
|
|
166
|
+
}
|
|
167
|
+
/** The first child element called `name`. */
|
|
168
|
+
export function child(node, name) {
|
|
169
|
+
return node?.children?.find((c) => typeof c !== 'string' && c.name === name);
|
|
170
|
+
}
|
|
171
|
+
/** Every child element called `name`. */
|
|
172
|
+
export function childrenNamed(node, name) {
|
|
173
|
+
return (node?.children ?? []).filter((c) => typeof c !== 'string' && c.name === name);
|
|
174
|
+
}
|
|
175
|
+
/** All the text inside a node, CDATA included. */
|
|
176
|
+
export function textOf(node) {
|
|
177
|
+
if (node === undefined || node === null)
|
|
178
|
+
return '';
|
|
179
|
+
if (typeof node === 'string')
|
|
180
|
+
return node;
|
|
181
|
+
return node.children.map(textOf).join('');
|
|
182
|
+
}
|
|
183
|
+
/** The trimmed text of the first child called `name`, or ''. */
|
|
184
|
+
export function childText(node, name) {
|
|
185
|
+
return textOf(child(node, name)).trim();
|
|
186
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Restore a backup from `basicben-cms backup` into an empty database.
|
|
4
|
+
*
|
|
5
|
+
* npm run migrate # an empty, current schema
|
|
6
|
+
* npm run restore -- backups/basicben-backup-….json.gz --dry-run
|
|
7
|
+
* npm run restore -- backups/basicben-backup-….json.gz --reset-password you@example.com
|
|
8
|
+
*
|
|
9
|
+
* Options:
|
|
10
|
+
* --dry-run do the whole restore in a transaction and roll it
|
|
11
|
+
* back; prints what would be written
|
|
12
|
+
* --force restore into a database that already has content
|
|
13
|
+
* (merges: existing rows matched by slug/email are
|
|
14
|
+
* left alone). Dry-run it first.
|
|
15
|
+
* --s3 KEY read the backup from the backup bucket instead of
|
|
16
|
+
* a local file (same BACKUP_S3_* / S3_* settings)
|
|
17
|
+
* --reset-password EMAIL after restoring, give that account a new random
|
|
18
|
+
* password and print it once
|
|
19
|
+
* --verbose print every row written
|
|
20
|
+
*
|
|
21
|
+
* Accepts `.json` and `.json.gz` (detected from the content, not the name).
|
|
22
|
+
* A `.sqlite` copy is not restored by this script — it is already a database:
|
|
23
|
+
* stop the app and put the file where DATABASE_URL points. See docs/backup.md.
|
|
24
|
+
*
|
|
25
|
+
* Backups carry no password hashes, so every restored account signs in by
|
|
26
|
+
* resetting its password; --reset-password gets one admin in without email.
|
|
27
|
+
*/
|
|
28
|
+
import { readFile } from 'node:fs/promises';
|
|
29
|
+
import { randomBytes } from 'node:crypto';
|
|
30
|
+
import { gunzipSync } from 'node:zlib';
|
|
31
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
32
|
+
import { createS3Adapter } from '@basicbenframework/core/storage';
|
|
33
|
+
import { hashPassword } from '@basicbenframework/core/auth';
|
|
34
|
+
import { parseArgs } from './lib/import-common.mjs';
|
|
35
|
+
import { readExport } from './lib/json-import.mjs';
|
|
36
|
+
import { restoreBackup, isGzip, backupStorageConfig } from './lib/backup.mjs';
|
|
37
|
+
async function load(file, s3Key) {
|
|
38
|
+
if (s3Key) {
|
|
39
|
+
const resolved = backupStorageConfig(process.env);
|
|
40
|
+
if (!resolved)
|
|
41
|
+
throw new Error('--s3 needs BACKUP_S3_BUCKET (or S3_BUCKET) with an access key id and secret.');
|
|
42
|
+
const object = await createS3Adapter(resolved.config).get(s3Key);
|
|
43
|
+
return object.body;
|
|
44
|
+
}
|
|
45
|
+
if (!file)
|
|
46
|
+
throw new Error('Pass the backup file: basicben-cms restore backups/basicben-backup-….json.gz');
|
|
47
|
+
if (/\.sqlite$/.test(file)) {
|
|
48
|
+
throw new Error('That is a SQLite copy, not a JSON backup. Stop the app and copy it to where DATABASE_URL points (docs/backup.md).');
|
|
49
|
+
}
|
|
50
|
+
return readFile(file);
|
|
51
|
+
}
|
|
52
|
+
async function main() {
|
|
53
|
+
const { flags, options, positional } = parseArgs(process.argv.slice(2), {
|
|
54
|
+
flags: ['dry-run', 'force', 'verbose'],
|
|
55
|
+
options: ['s3', 'reset-password']
|
|
56
|
+
});
|
|
57
|
+
const raw = await load(positional[0], options.s3);
|
|
58
|
+
const doc = readExport((isGzip(raw) ? gunzipSync(raw) : raw).toString('utf-8'));
|
|
59
|
+
const db = await getDb();
|
|
60
|
+
// An unmigrated target fails later with "no such table", which reads like
|
|
61
|
+
// a broken backup. Say what is actually wrong.
|
|
62
|
+
try {
|
|
63
|
+
await db.get('SELECT 1 FROM users LIMIT 1');
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
throw new Error('The target database has no schema. Run `npm run migrate` first, then restore.');
|
|
67
|
+
}
|
|
68
|
+
console.log(`Restoring ${options.s3 ? `s3:${options.s3}` : positional[0]} (format v${doc.version}, exported ${doc.exported_at})`);
|
|
69
|
+
if (flags['dry-run'])
|
|
70
|
+
console.log('Dry run — nothing will be written.');
|
|
71
|
+
console.log('');
|
|
72
|
+
const result = await restoreBackup(db, doc, {
|
|
73
|
+
force: flags.force,
|
|
74
|
+
dryRun: flags['dry-run'],
|
|
75
|
+
log: flags.verbose ? console.log : undefined
|
|
76
|
+
});
|
|
77
|
+
console.log(`Accounts\n${result.accounts}\n\nContent\n${result.content}`);
|
|
78
|
+
if (flags['dry-run']) {
|
|
79
|
+
console.log('\nDry run complete. Nothing was written.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (options['reset-password']) {
|
|
83
|
+
const email = String(options['reset-password']).toLowerCase();
|
|
84
|
+
const user = await db.get('SELECT id FROM users WHERE LOWER(email) = ?', [email]);
|
|
85
|
+
if (!user)
|
|
86
|
+
throw new Error(`Restored, but no account has the address ${email}, so no password was set.`);
|
|
87
|
+
// Printed once, to this terminal, and never stored anywhere but as a
|
|
88
|
+
// hash. Change it after signing in.
|
|
89
|
+
const password = randomBytes(15).toString('base64url');
|
|
90
|
+
await db.run('UPDATE users SET password = ? WHERE id = ?', [await hashPassword(password), user.id]);
|
|
91
|
+
console.log(`\nTemporary password for ${email}: ${password}\nSign in and change it from your Profile.`);
|
|
92
|
+
}
|
|
93
|
+
console.log('\nRestore complete. Media files are not part of a backup; they stay in your storage bucket.');
|
|
94
|
+
}
|
|
95
|
+
main().then(() => process.exit(0), (error) => {
|
|
96
|
+
console.error(`\nRestore failed: ${error.message}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Alert({ type = 'error', children }) {
|
|
3
|
+
const styles = {
|
|
4
|
+
error: 'text-red-500 bg-red-500/10',
|
|
5
|
+
success: 'text-emerald-500 bg-emerald-500/10'
|
|
6
|
+
};
|
|
7
|
+
return (_jsx("p", { className: `text-xs p-2 rounded-lg ${styles[type]}`, children: children }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An author's face, or their initial when they have not uploaded one.
|
|
3
|
+
*
|
|
4
|
+
* The initial is the fallback rather than a placeholder image: it is legible at
|
|
5
|
+
* every size, needs no request, and cannot 404. `src` is a resolved URL — the
|
|
6
|
+
* server turns the stored media id into one, because only it knows where files
|
|
7
|
+
* are actually served from.
|
|
8
|
+
*/
|
|
9
|
+
interface AvatarProps {
|
|
10
|
+
name: string;
|
|
11
|
+
src?: string | null;
|
|
12
|
+
size?: 'sm' | 'md' | 'lg';
|
|
13
|
+
}
|
|
14
|
+
export declare function Avatar({ name, src, size }: AvatarProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "./ThemeContext.js";
|
|
3
|
+
export function Avatar({ name, src, size = 'md' }) {
|
|
4
|
+
const { dark } = useTheme();
|
|
5
|
+
const sizes = { sm: 'w-6 h-6 text-xs', md: 'w-8 h-8 text-sm', lg: 'w-12 h-12 text-base' };
|
|
6
|
+
if (src) {
|
|
7
|
+
return (_jsx("img", { src: src, alt: "", className: `${sizes[size]} rounded-full object-cover shrink-0` }));
|
|
8
|
+
}
|
|
9
|
+
return (_jsx("div", { className: `${sizes[size]} shrink-0 rounded-full flex items-center justify-center font-medium ${dark ? 'bg-white text-black' : 'bg-black text-white'}`, children: (name?.[0] || '?').toUpperCase() }));
|
|
10
|
+
}
|