emdash 0.0.0-b → 0.0.2
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/README.md +87 -43
- package/dist/adapters-BLMa4JGD.d.mts +106 -0
- package/dist/adapters-BLMa4JGD.d.mts.map +1 -0
- package/dist/apply-Bjfq_b4-.mjs +1293 -0
- package/dist/apply-Bjfq_b4-.mjs.map +1 -0
- package/dist/astro/index.d.mts +51 -0
- package/dist/astro/index.d.mts.map +1 -0
- package/dist/astro/index.mjs +1336 -0
- package/dist/astro/index.mjs.map +1 -0
- package/dist/astro/middleware/auth.d.mts +31 -0
- package/dist/astro/middleware/auth.d.mts.map +1 -0
- package/dist/astro/middleware/auth.mjs +654 -0
- package/dist/astro/middleware/auth.mjs.map +1 -0
- package/dist/astro/middleware/redirect.d.mts +22 -0
- package/dist/astro/middleware/redirect.d.mts.map +1 -0
- package/dist/astro/middleware/redirect.mjs +63 -0
- package/dist/astro/middleware/redirect.mjs.map +1 -0
- package/dist/astro/middleware/request-context.d.mts +18 -0
- package/dist/astro/middleware/request-context.d.mts.map +1 -0
- package/dist/astro/middleware/request-context.mjs +1310 -0
- package/dist/astro/middleware/request-context.mjs.map +1 -0
- package/dist/astro/middleware/setup.d.mts +20 -0
- package/dist/astro/middleware/setup.d.mts.map +1 -0
- package/dist/astro/middleware/setup.mjs +47 -0
- package/dist/astro/middleware/setup.mjs.map +1 -0
- package/dist/astro/middleware.d.mts +13 -0
- package/dist/astro/middleware.d.mts.map +1 -0
- package/dist/astro/middleware.mjs +1613 -0
- package/dist/astro/middleware.mjs.map +1 -0
- package/dist/astro/types.d.mts +250 -0
- package/dist/astro/types.d.mts.map +1 -0
- package/dist/astro/types.mjs +1 -0
- package/dist/base64-MBPo9ozB.mjs +59 -0
- package/dist/base64-MBPo9ozB.mjs.map +1 -0
- package/dist/byline-CL847F26.mjs +213 -0
- package/dist/byline-CL847F26.mjs.map +1 -0
- package/dist/bylines-C2a-2TGt.mjs +136 -0
- package/dist/bylines-C2a-2TGt.mjs.map +1 -0
- package/dist/chunk-ClPoSABd.mjs +21 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +3909 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client/cf-access.d.mts +60 -0
- package/dist/client/cf-access.d.mts.map +1 -0
- package/dist/client/cf-access.mjs +179 -0
- package/dist/client/cf-access.mjs.map +1 -0
- package/dist/client/index.d.mts +398 -0
- package/dist/client/index.d.mts.map +1 -0
- package/dist/client/index.mjs +346 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/config-CKE8p9xM.mjs +55 -0
- package/dist/config-CKE8p9xM.mjs.map +1 -0
- package/dist/connection-B4zVnQIa.mjs +40 -0
- package/dist/connection-B4zVnQIa.mjs.map +1 -0
- package/dist/content-D6C2WsZC.mjs +824 -0
- package/dist/content-D6C2WsZC.mjs.map +1 -0
- package/dist/db/index.d.mts +4 -0
- package/dist/db/index.mjs +62 -0
- package/dist/db/index.mjs.map +1 -0
- package/dist/db/libsql.d.mts +11 -0
- package/dist/db/libsql.d.mts.map +1 -0
- package/dist/db/libsql.mjs +17 -0
- package/dist/db/libsql.mjs.map +1 -0
- package/dist/db/postgres.d.mts +11 -0
- package/dist/db/postgres.d.mts.map +1 -0
- package/dist/db/postgres.mjs +30 -0
- package/dist/db/postgres.mjs.map +1 -0
- package/dist/db/sqlite.d.mts +11 -0
- package/dist/db/sqlite.d.mts.map +1 -0
- package/dist/db/sqlite.mjs +16 -0
- package/dist/db/sqlite.mjs.map +1 -0
- package/dist/default-Cyi4aAxu.mjs +81 -0
- package/dist/default-Cyi4aAxu.mjs.map +1 -0
- package/dist/dialect-helpers-B9uSp2GJ.mjs +90 -0
- package/dist/dialect-helpers-B9uSp2GJ.mjs.map +1 -0
- package/dist/error-Cxz0tQeO.mjs +27 -0
- package/dist/error-Cxz0tQeO.mjs.map +1 -0
- package/dist/index-C1xF3OGh.d.mts +4527 -0
- package/dist/index-C1xF3OGh.d.mts.map +1 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +30 -0
- package/dist/load-yOOlckBj.mjs +28 -0
- package/dist/load-yOOlckBj.mjs.map +1 -0
- package/dist/loader-fz8Q_3EO.mjs +447 -0
- package/dist/loader-fz8Q_3EO.mjs.map +1 -0
- package/dist/manifest-schema-Dcl0R6nM.mjs +184 -0
- package/dist/manifest-schema-Dcl0R6nM.mjs.map +1 -0
- package/dist/media/index.d.mts +26 -0
- package/dist/media/index.d.mts.map +1 -0
- package/dist/media/index.mjs +55 -0
- package/dist/media/index.mjs.map +1 -0
- package/dist/media/local-runtime.d.mts +39 -0
- package/dist/media/local-runtime.d.mts.map +1 -0
- package/dist/media/local-runtime.mjs +133 -0
- package/dist/media/local-runtime.mjs.map +1 -0
- package/dist/media-DqHVh136.mjs +200 -0
- package/dist/media-DqHVh136.mjs.map +1 -0
- package/dist/mode-C2EzN1uE.mjs +23 -0
- package/dist/mode-C2EzN1uE.mjs.map +1 -0
- package/dist/page/index.d.mts +140 -0
- package/dist/page/index.d.mts.map +1 -0
- package/dist/page/index.mjs +416 -0
- package/dist/page/index.mjs.map +1 -0
- package/dist/placeholder-CmGAmqeO.d.mts +276 -0
- package/dist/placeholder-CmGAmqeO.d.mts.map +1 -0
- package/dist/placeholder-SmpOx-_v.mjs +243 -0
- package/dist/placeholder-SmpOx-_v.mjs.map +1 -0
- package/dist/plugin-utils.d.mts +58 -0
- package/dist/plugin-utils.d.mts.map +1 -0
- package/dist/plugin-utils.mjs +78 -0
- package/dist/plugin-utils.mjs.map +1 -0
- package/dist/plugins/adapt-sandbox-entry.d.mts +22 -0
- package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -0
- package/dist/plugins/adapt-sandbox-entry.mjs +113 -0
- package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -0
- package/dist/query-CS_iSj34.mjs +460 -0
- package/dist/query-CS_iSj34.mjs.map +1 -0
- package/dist/redirect-DIfIni3r.mjs +329 -0
- package/dist/redirect-DIfIni3r.mjs.map +1 -0
- package/dist/registry-D_w5HW4G.mjs +863 -0
- package/dist/registry-D_w5HW4G.mjs.map +1 -0
- package/dist/request-context.d.mts +49 -0
- package/dist/request-context.d.mts.map +1 -0
- package/dist/request-context.mjs +43 -0
- package/dist/request-context.mjs.map +1 -0
- package/dist/runner-C0hCbYnD.mjs +1412 -0
- package/dist/runner-C0hCbYnD.mjs.map +1 -0
- package/dist/runner-EAtf0ZIe.d.mts +27 -0
- package/dist/runner-EAtf0ZIe.d.mts.map +1 -0
- package/dist/runtime.d.mts +26 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +42 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/search-DG603UrT.mjs +9211 -0
- package/dist/search-DG603UrT.mjs.map +1 -0
- package/dist/seed/index.d.mts +3 -0
- package/dist/seed/index.mjs +15 -0
- package/dist/seo/index.d.mts +70 -0
- package/dist/seo/index.d.mts.map +1 -0
- package/dist/seo/index.mjs +70 -0
- package/dist/seo/index.mjs.map +1 -0
- package/dist/storage/local.d.mts +39 -0
- package/dist/storage/local.d.mts.map +1 -0
- package/dist/storage/local.mjs +166 -0
- package/dist/storage/local.mjs.map +1 -0
- package/dist/storage/s3.d.mts +32 -0
- package/dist/storage/s3.d.mts.map +1 -0
- package/dist/storage/s3.mjs +175 -0
- package/dist/storage/s3.mjs.map +1 -0
- package/dist/tokens-DpgrkrXK.mjs +171 -0
- package/dist/tokens-DpgrkrXK.mjs.map +1 -0
- package/dist/transport-BFGblqwG.d.mts +42 -0
- package/dist/transport-BFGblqwG.d.mts.map +1 -0
- package/dist/transport-yxiQsi8I.mjs +418 -0
- package/dist/transport-yxiQsi8I.mjs.map +1 -0
- package/dist/types-BRuPJGdV.d.mts +102 -0
- package/dist/types-BRuPJGdV.d.mts.map +1 -0
- package/dist/types-C4-fAxN3.d.mts +182 -0
- package/dist/types-C4-fAxN3.d.mts.map +1 -0
- package/dist/types-CMMN0pNg.mjs +31 -0
- package/dist/types-CMMN0pNg.mjs.map +1 -0
- package/dist/types-CUBbjgmP.mjs +16 -0
- package/dist/types-CUBbjgmP.mjs.map +1 -0
- package/dist/types-DRjfYOEv.d.mts +426 -0
- package/dist/types-DRjfYOEv.d.mts.map +1 -0
- package/dist/types-DY5zk5HN.mjs +73 -0
- package/dist/types-DY5zk5HN.mjs.map +1 -0
- package/dist/types-DaNLHo_T.d.mts +184 -0
- package/dist/types-DaNLHo_T.d.mts.map +1 -0
- package/dist/types-DvhsUmSJ.d.mts +1111 -0
- package/dist/types-DvhsUmSJ.d.mts.map +1 -0
- package/dist/validate-CpBtVMsD.d.mts +378 -0
- package/dist/validate-CpBtVMsD.d.mts.map +1 -0
- package/dist/validate-CqRJb_xU.mjs +97 -0
- package/dist/validate-CqRJb_xU.mjs.map +1 -0
- package/dist/validate-O7PWmlnq.mjs +328 -0
- package/dist/validate-O7PWmlnq.mjs.map +1 -0
- package/locals.d.ts +46 -0
- package/package.json +233 -19
- package/src/api/authorize.ts +63 -0
- package/src/api/csrf.ts +48 -0
- package/src/api/error.ts +99 -0
- package/src/api/errors.ts +445 -0
- package/src/api/escape.ts +9 -0
- package/src/api/handlers/api-tokens.ts +240 -0
- package/src/api/handlers/comments.ts +314 -0
- package/src/api/handlers/content.ts +1315 -0
- package/src/api/handlers/dashboard.ts +205 -0
- package/src/api/handlers/device-flow.ts +684 -0
- package/src/api/handlers/index.ts +163 -0
- package/src/api/handlers/manifest.ts +158 -0
- package/src/api/handlers/marketplace.ts +930 -0
- package/src/api/handlers/media.ts +207 -0
- package/src/api/handlers/menus.ts +493 -0
- package/src/api/handlers/oauth-authorization.ts +429 -0
- package/src/api/handlers/oauth-clients.ts +349 -0
- package/src/api/handlers/oauth-user-lookup.ts +39 -0
- package/src/api/handlers/plugins.ts +254 -0
- package/src/api/handlers/redirects.ts +360 -0
- package/src/api/handlers/revision.ts +145 -0
- package/src/api/handlers/schema.ts +534 -0
- package/src/api/handlers/sections.ts +289 -0
- package/src/api/handlers/seo.ts +115 -0
- package/src/api/handlers/settings.ts +49 -0
- package/src/api/handlers/snapshot.ts +350 -0
- package/src/api/handlers/taxonomies.ts +523 -0
- package/src/api/index.ts +6 -0
- package/src/api/openapi/document.ts +2368 -0
- package/src/api/openapi/index.ts +1 -0
- package/src/api/parse.ts +139 -0
- package/src/api/redirect.ts +14 -0
- package/src/api/rev.ts +67 -0
- package/src/api/schemas/auth.ts +112 -0
- package/src/api/schemas/bylines.ts +85 -0
- package/src/api/schemas/comments.ts +117 -0
- package/src/api/schemas/common.ts +89 -0
- package/src/api/schemas/content.ts +191 -0
- package/src/api/schemas/import.ts +52 -0
- package/src/api/schemas/index.ts +17 -0
- package/src/api/schemas/media.ts +116 -0
- package/src/api/schemas/menus.ts +111 -0
- package/src/api/schemas/redirects.ts +155 -0
- package/src/api/schemas/schema.ts +203 -0
- package/src/api/schemas/search.ts +63 -0
- package/src/api/schemas/sections.ts +67 -0
- package/src/api/schemas/settings.ts +63 -0
- package/src/api/schemas/setup.ts +37 -0
- package/src/api/schemas/taxonomies.ts +113 -0
- package/src/api/schemas/users.ts +96 -0
- package/src/api/schemas/widgets.ts +80 -0
- package/src/api/site-url.ts +25 -0
- package/src/api/types.ts +82 -0
- package/src/astro/index.ts +27 -0
- package/src/astro/integration/index.ts +303 -0
- package/src/astro/integration/routes.ts +834 -0
- package/src/astro/integration/runtime.ts +338 -0
- package/src/astro/integration/virtual-modules.ts +469 -0
- package/src/astro/integration/vite-config.ts +335 -0
- package/src/astro/middleware/auth.ts +743 -0
- package/src/astro/middleware/redirect.ts +89 -0
- package/src/astro/middleware/request-context.ts +129 -0
- package/src/astro/middleware/setup.ts +89 -0
- package/src/astro/middleware.ts +398 -0
- package/src/astro/routes/PluginRegistry.tsx +15 -0
- package/src/astro/routes/admin.astro +81 -0
- package/src/astro/routes/api/admin/allowed-domains/[domain].ts +112 -0
- package/src/astro/routes/api/admin/allowed-domains/index.ts +108 -0
- package/src/astro/routes/api/admin/api-tokens/[id].ts +40 -0
- package/src/astro/routes/api/admin/api-tokens/index.ts +68 -0
- package/src/astro/routes/api/admin/bylines/[id]/index.ts +87 -0
- package/src/astro/routes/api/admin/bylines/index.ts +72 -0
- package/src/astro/routes/api/admin/comments/[id]/status.ts +116 -0
- package/src/astro/routes/api/admin/comments/[id].ts +64 -0
- package/src/astro/routes/api/admin/comments/bulk.ts +42 -0
- package/src/astro/routes/api/admin/comments/counts.ts +30 -0
- package/src/astro/routes/api/admin/comments/index.ts +46 -0
- package/src/astro/routes/api/admin/hooks/exclusive/[hookName].ts +91 -0
- package/src/astro/routes/api/admin/hooks/exclusive/index.ts +51 -0
- package/src/astro/routes/api/admin/oauth-clients/[id].ts +110 -0
- package/src/astro/routes/api/admin/oauth-clients/index.ts +71 -0
- package/src/astro/routes/api/admin/plugins/[id]/disable.ts +39 -0
- package/src/astro/routes/api/admin/plugins/[id]/enable.ts +39 -0
- package/src/astro/routes/api/admin/plugins/[id]/index.ts +38 -0
- package/src/astro/routes/api/admin/plugins/[id]/uninstall.ts +48 -0
- package/src/astro/routes/api/admin/plugins/[id]/update.ts +59 -0
- package/src/astro/routes/api/admin/plugins/index.ts +32 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/icon.ts +61 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/index.ts +33 -0
- package/src/astro/routes/api/admin/plugins/marketplace/[id]/install.ts +62 -0
- package/src/astro/routes/api/admin/plugins/marketplace/index.ts +38 -0
- package/src/astro/routes/api/admin/plugins/updates.ts +28 -0
- package/src/astro/routes/api/admin/themes/marketplace/[id]/index.ts +33 -0
- package/src/astro/routes/api/admin/themes/marketplace/[id]/thumbnail.ts +61 -0
- package/src/astro/routes/api/admin/themes/marketplace/index.ts +45 -0
- package/src/astro/routes/api/admin/users/[id]/disable.ts +69 -0
- package/src/astro/routes/api/admin/users/[id]/enable.ts +48 -0
- package/src/astro/routes/api/admin/users/[id]/index.ts +146 -0
- package/src/astro/routes/api/admin/users/[id]/send-recovery.ts +72 -0
- package/src/astro/routes/api/admin/users/index.ts +66 -0
- package/src/astro/routes/api/auth/dev-bypass.ts +139 -0
- package/src/astro/routes/api/auth/invite/accept.ts +52 -0
- package/src/astro/routes/api/auth/invite/complete.ts +84 -0
- package/src/astro/routes/api/auth/invite/index.ts +99 -0
- package/src/astro/routes/api/auth/logout.ts +40 -0
- package/src/astro/routes/api/auth/magic-link/send.ts +89 -0
- package/src/astro/routes/api/auth/magic-link/verify.ts +71 -0
- package/src/astro/routes/api/auth/me.ts +60 -0
- package/src/astro/routes/api/auth/oauth/[provider]/callback.ts +219 -0
- package/src/astro/routes/api/auth/oauth/[provider].ts +119 -0
- package/src/astro/routes/api/auth/passkey/[id].ts +124 -0
- package/src/astro/routes/api/auth/passkey/index.ts +54 -0
- package/src/astro/routes/api/auth/passkey/options.ts +82 -0
- package/src/astro/routes/api/auth/passkey/register/options.ts +86 -0
- package/src/astro/routes/api/auth/passkey/register/verify.ts +115 -0
- package/src/astro/routes/api/auth/passkey/verify.ts +66 -0
- package/src/astro/routes/api/auth/signup/complete.ts +85 -0
- package/src/astro/routes/api/auth/signup/request.ts +77 -0
- package/src/astro/routes/api/auth/signup/verify.ts +53 -0
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +312 -0
- package/src/astro/routes/api/content/[collection]/[id]/compare.ts +28 -0
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +54 -0
- package/src/astro/routes/api/content/[collection]/[id]/duplicate.ts +61 -0
- package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +33 -0
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +107 -0
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +56 -0
- package/src/astro/routes/api/content/[collection]/[id]/restore.ts +54 -0
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +31 -0
- package/src/astro/routes/api/content/[collection]/[id]/schedule.ts +101 -0
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +140 -0
- package/src/astro/routes/api/content/[collection]/[id]/translations.ts +30 -0
- package/src/astro/routes/api/content/[collection]/[id]/unpublish.ts +56 -0
- package/src/astro/routes/api/content/[collection]/[id].ts +137 -0
- package/src/astro/routes/api/content/[collection]/index.ts +59 -0
- package/src/astro/routes/api/content/[collection]/trash.ts +33 -0
- package/src/astro/routes/api/dashboard.ts +32 -0
- package/src/astro/routes/api/dev/emails.ts +36 -0
- package/src/astro/routes/api/import/probe.ts +47 -0
- package/src/astro/routes/api/import/wordpress/analyze.ts +510 -0
- package/src/astro/routes/api/import/wordpress/execute.ts +283 -0
- package/src/astro/routes/api/import/wordpress/media.ts +338 -0
- package/src/astro/routes/api/import/wordpress/prepare.ts +181 -0
- package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +393 -0
- package/src/astro/routes/api/import/wordpress-plugin/analyze.ts +111 -0
- package/src/astro/routes/api/import/wordpress-plugin/callback.ts +58 -0
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +347 -0
- package/src/astro/routes/api/manifest.ts +62 -0
- package/src/astro/routes/api/mcp.ts +124 -0
- package/src/astro/routes/api/media/[id]/confirm.ts +93 -0
- package/src/astro/routes/api/media/[id].ts +145 -0
- package/src/astro/routes/api/media/file/[key].ts +79 -0
- package/src/astro/routes/api/media/providers/[providerId]/[itemId].ts +86 -0
- package/src/astro/routes/api/media/providers/[providerId]/index.ts +111 -0
- package/src/astro/routes/api/media/providers/index.ts +30 -0
- package/src/astro/routes/api/media/upload-url.ts +137 -0
- package/src/astro/routes/api/media.ts +190 -0
- package/src/astro/routes/api/menus/[name]/items.ts +87 -0
- package/src/astro/routes/api/menus/[name]/reorder.ts +33 -0
- package/src/astro/routes/api/menus/[name].ts +65 -0
- package/src/astro/routes/api/menus/index.ts +47 -0
- package/src/astro/routes/api/oauth/authorize.ts +412 -0
- package/src/astro/routes/api/oauth/device/authorize.ts +45 -0
- package/src/astro/routes/api/oauth/device/code.ts +51 -0
- package/src/astro/routes/api/oauth/device/token.ts +69 -0
- package/src/astro/routes/api/oauth/token/refresh.ts +38 -0
- package/src/astro/routes/api/oauth/token/revoke.ts +38 -0
- package/src/astro/routes/api/oauth/token.ts +184 -0
- package/src/astro/routes/api/openapi.json.ts +32 -0
- package/src/astro/routes/api/plugins/[pluginId]/[...path].ts +92 -0
- package/src/astro/routes/api/redirects/404s/index.ts +72 -0
- package/src/astro/routes/api/redirects/404s/summary.ts +33 -0
- package/src/astro/routes/api/redirects/[id].ts +84 -0
- package/src/astro/routes/api/redirects/index.ts +52 -0
- package/src/astro/routes/api/revisions/[revisionId]/index.ts +29 -0
- package/src/astro/routes/api/revisions/[revisionId]/restore.ts +58 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +76 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +52 -0
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +32 -0
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +80 -0
- package/src/astro/routes/api/schema/collections/index.ts +47 -0
- package/src/astro/routes/api/schema/index.ts +109 -0
- package/src/astro/routes/api/schema/orphans/[slug].ts +36 -0
- package/src/astro/routes/api/schema/orphans/index.ts +26 -0
- package/src/astro/routes/api/search/enable.ts +64 -0
- package/src/astro/routes/api/search/index.ts +55 -0
- package/src/astro/routes/api/search/rebuild.ts +72 -0
- package/src/astro/routes/api/search/stats.ts +35 -0
- package/src/astro/routes/api/search/suggest.ts +53 -0
- package/src/astro/routes/api/sections/[slug].ts +84 -0
- package/src/astro/routes/api/sections/index.ts +52 -0
- package/src/astro/routes/api/settings/email.ts +150 -0
- package/src/astro/routes/api/settings.ts +67 -0
- package/src/astro/routes/api/setup/admin-verify.ts +100 -0
- package/src/astro/routes/api/setup/admin.ts +94 -0
- package/src/astro/routes/api/setup/dev-bypass.ts +199 -0
- package/src/astro/routes/api/setup/dev-reset.ts +40 -0
- package/src/astro/routes/api/setup/index.ts +126 -0
- package/src/astro/routes/api/setup/status.ts +122 -0
- package/src/astro/routes/api/snapshot.ts +75 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +95 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +69 -0
- package/src/astro/routes/api/taxonomies/index.ts +59 -0
- package/src/astro/routes/api/themes/preview.ts +77 -0
- package/src/astro/routes/api/typegen.ts +114 -0
- package/src/astro/routes/api/well-known/auth.ts +68 -0
- package/src/astro/routes/api/well-known/oauth-authorization-server.ts +44 -0
- package/src/astro/routes/api/well-known/oauth-protected-resource.ts +37 -0
- package/src/astro/routes/api/widget-areas/[name]/reorder.ts +68 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets/[id].ts +127 -0
- package/src/astro/routes/api/widget-areas/[name]/widgets.ts +80 -0
- package/src/astro/routes/api/widget-areas/[name].ts +87 -0
- package/src/astro/routes/api/widget-areas/index.ts +99 -0
- package/src/astro/routes/api/widget-components.ts +22 -0
- package/src/astro/routes/robots.txt.ts +77 -0
- package/src/astro/routes/sitemap.xml.ts +97 -0
- package/src/astro/storage/adapters.ts +74 -0
- package/src/astro/storage/index.ts +19 -0
- package/src/astro/storage/types.ts +60 -0
- package/src/astro/types.ts +346 -0
- package/src/auth/api-tokens.ts +25 -0
- package/src/auth/challenge-store.ts +80 -0
- package/src/auth/mode.ts +96 -0
- package/src/auth/oauth-state-store.ts +96 -0
- package/src/auth/passkey-config.ts +27 -0
- package/src/auth/rate-limit.ts +158 -0
- package/src/auth/scopes.ts +33 -0
- package/src/auth/types.ts +104 -0
- package/src/aws-sdk.d.ts +100 -0
- package/src/bylines/index.ts +237 -0
- package/src/cleanup.ts +153 -0
- package/src/cli/client-factory.ts +100 -0
- package/src/cli/commands/auth.ts +46 -0
- package/src/cli/commands/bundle-utils.ts +247 -0
- package/src/cli/commands/bundle.ts +609 -0
- package/src/cli/commands/content.ts +442 -0
- package/src/cli/commands/dev.ts +191 -0
- package/src/cli/commands/doctor.ts +211 -0
- package/src/cli/commands/export-seed.ts +630 -0
- package/src/cli/commands/import/wordpress.ts +1056 -0
- package/src/cli/commands/init.ts +192 -0
- package/src/cli/commands/login.ts +547 -0
- package/src/cli/commands/media.ts +165 -0
- package/src/cli/commands/menu.ts +67 -0
- package/src/cli/commands/plugin-init.ts +291 -0
- package/src/cli/commands/plugin-validate.ts +31 -0
- package/src/cli/commands/plugin.ts +33 -0
- package/src/cli/commands/publish.ts +697 -0
- package/src/cli/commands/schema.ts +233 -0
- package/src/cli/commands/search-cmd.ts +54 -0
- package/src/cli/commands/seed.ts +286 -0
- package/src/cli/commands/taxonomy.ts +128 -0
- package/src/cli/commands/types.ts +68 -0
- package/src/cli/credentials.ts +236 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/output.ts +75 -0
- package/src/cli/wxr/parser.ts +969 -0
- package/src/client/cf-access.ts +193 -0
- package/src/client/index.ts +854 -0
- package/src/client/portable-text.ts +413 -0
- package/src/client/transport.ts +200 -0
- package/src/comments/moderator.ts +46 -0
- package/src/comments/notifications.ts +144 -0
- package/src/comments/query.ts +105 -0
- package/src/comments/service.ts +213 -0
- package/src/components/Break.astro +45 -0
- package/src/components/Button.astro +71 -0
- package/src/components/Buttons.astro +49 -0
- package/src/components/Code.astro +59 -0
- package/src/components/Columns.astro +59 -0
- package/src/components/CommentForm.astro +315 -0
- package/src/components/Comments.astro +232 -0
- package/src/components/Cover.astro +128 -0
- package/src/components/EmDashBodyEnd.astro +32 -0
- package/src/components/EmDashBodyStart.astro +32 -0
- package/src/components/EmDashHead.astro +53 -0
- package/src/components/EmDashImage.astro +178 -0
- package/src/components/EmDashMedia.astro +167 -0
- package/src/components/Embed.astro +128 -0
- package/src/components/File.astro +122 -0
- package/src/components/Gallery.astro +93 -0
- package/src/components/HtmlBlock.astro +33 -0
- package/src/components/Image.astro +178 -0
- package/src/components/InlineEditor.astro +27 -0
- package/src/components/InlinePortableTextEditor.tsx +1905 -0
- package/src/components/LiveSearch.astro +614 -0
- package/src/components/PortableText.astro +51 -0
- package/src/components/Pullquote.astro +51 -0
- package/src/components/Table.astro +108 -0
- package/src/components/WidgetArea.astro +22 -0
- package/src/components/WidgetRenderer.astro +72 -0
- package/src/components/index.ts +116 -0
- package/src/components/marks/Link.astro +31 -0
- package/src/components/marks/StrikeThrough.astro +7 -0
- package/src/components/marks/Subscript.astro +7 -0
- package/src/components/marks/Superscript.astro +7 -0
- package/src/components/marks/Underline.astro +7 -0
- package/src/components/widgets/Archives.astro +65 -0
- package/src/components/widgets/Categories.astro +35 -0
- package/src/components/widgets/RecentPosts.astro +51 -0
- package/src/components/widgets/Search.astro +18 -0
- package/src/components/widgets/Tags.astro +38 -0
- package/src/content/converters/index.ts +9 -0
- package/src/content/converters/portable-text-to-prosemirror.ts +385 -0
- package/src/content/converters/prosemirror-to-portable-text.ts +413 -0
- package/src/content/converters/types.ts +120 -0
- package/src/content/index.ts +5 -0
- package/src/database/connection.ts +67 -0
- package/src/database/dialect-helpers.ts +138 -0
- package/src/database/index.ts +5 -0
- package/src/database/migrations/001_initial.ts +170 -0
- package/src/database/migrations/002_media_status.ts +26 -0
- package/src/database/migrations/003_schema_registry.ts +79 -0
- package/src/database/migrations/004_plugins.ts +62 -0
- package/src/database/migrations/005_menus.ts +67 -0
- package/src/database/migrations/006_taxonomy_defs.ts +51 -0
- package/src/database/migrations/007_widgets.ts +42 -0
- package/src/database/migrations/008_auth.ts +194 -0
- package/src/database/migrations/009_user_disabled.ts +27 -0
- package/src/database/migrations/011_sections.ts +65 -0
- package/src/database/migrations/012_search.ts +25 -0
- package/src/database/migrations/013_scheduled_publishing.ts +51 -0
- package/src/database/migrations/014_draft_revisions.ts +72 -0
- package/src/database/migrations/015_indexes.ts +82 -0
- package/src/database/migrations/016_api_tokens.ts +89 -0
- package/src/database/migrations/017_authorization_codes.ts +45 -0
- package/src/database/migrations/018_seo.ts +56 -0
- package/src/database/migrations/019_i18n.ts +618 -0
- package/src/database/migrations/020_collection_url_pattern.ts +23 -0
- package/src/database/migrations/021_remove_section_categories.ts +43 -0
- package/src/database/migrations/022_marketplace_plugin_state.ts +46 -0
- package/src/database/migrations/023_plugin_metadata.ts +33 -0
- package/src/database/migrations/024_media_placeholders.ts +32 -0
- package/src/database/migrations/025_oauth_clients.ts +28 -0
- package/src/database/migrations/026_cron_tasks.ts +49 -0
- package/src/database/migrations/027_comments.ts +87 -0
- package/src/database/migrations/028_drop_author_url.ts +9 -0
- package/src/database/migrations/029_redirects.ts +67 -0
- package/src/database/migrations/030_widen_scheduled_index.ts +48 -0
- package/src/database/migrations/031_bylines.ts +90 -0
- package/src/database/migrations/032_rate_limits.ts +39 -0
- package/src/database/migrations/runner.ts +170 -0
- package/src/database/repositories/audit.ts +294 -0
- package/src/database/repositories/byline.ts +387 -0
- package/src/database/repositories/comment.ts +458 -0
- package/src/database/repositories/content.ts +1144 -0
- package/src/database/repositories/index.ts +30 -0
- package/src/database/repositories/media.ts +347 -0
- package/src/database/repositories/options.ts +150 -0
- package/src/database/repositories/plugin-storage.ts +373 -0
- package/src/database/repositories/redirect.ts +480 -0
- package/src/database/repositories/revision.ts +200 -0
- package/src/database/repositories/seo.ts +176 -0
- package/src/database/repositories/taxonomy.ts +294 -0
- package/src/database/repositories/types.ts +132 -0
- package/src/database/repositories/user.ts +258 -0
- package/src/database/transaction.ts +54 -0
- package/src/database/types.ts +501 -0
- package/src/database/validate.ts +138 -0
- package/src/db/adapters.ts +125 -0
- package/src/db/index.ts +37 -0
- package/src/db/libsql.ts +23 -0
- package/src/db/postgres.ts +30 -0
- package/src/db/sqlite.ts +27 -0
- package/src/emdash-runtime.ts +2096 -0
- package/src/fields/boolean.ts +34 -0
- package/src/fields/datetime.ts +44 -0
- package/src/fields/file.ts +41 -0
- package/src/fields/image.ts +34 -0
- package/src/fields/index.ts +42 -0
- package/src/fields/integer.ts +50 -0
- package/src/fields/json.ts +37 -0
- package/src/fields/multiselect.ts +48 -0
- package/src/fields/number.ts +52 -0
- package/src/fields/portable-text.ts +33 -0
- package/src/fields/reference.ts +29 -0
- package/src/fields/richtext.ts +31 -0
- package/src/fields/select.ts +46 -0
- package/src/fields/slug.ts +38 -0
- package/src/fields/text.ts +55 -0
- package/src/fields/textarea.ts +52 -0
- package/src/fields/types.ts +64 -0
- package/src/i18n/config.ts +68 -0
- package/src/import/index.ts +90 -0
- package/src/import/menus.ts +436 -0
- package/src/import/registry.ts +111 -0
- package/src/import/sections.ts +103 -0
- package/src/import/settings.ts +281 -0
- package/src/import/sources/wordpress-plugin.ts +641 -0
- package/src/import/sources/wordpress-rest.ts +191 -0
- package/src/import/sources/wxr.ts +330 -0
- package/src/import/ssrf.ts +260 -0
- package/src/import/types.ts +418 -0
- package/src/import/utils.ts +412 -0
- package/src/index.ts +481 -0
- package/src/loader.ts +770 -0
- package/src/mcp/server.ts +1463 -0
- package/src/media/index.ts +32 -0
- package/src/media/local-runtime.ts +213 -0
- package/src/media/local.ts +46 -0
- package/src/media/normalize.ts +190 -0
- package/src/media/placeholder.ts +150 -0
- package/src/media/provider-loader.ts +78 -0
- package/src/media/types.ts +279 -0
- package/src/menus/index.ts +324 -0
- package/src/menus/types.ts +112 -0
- package/src/page/context.ts +93 -0
- package/src/page/fragments.ts +89 -0
- package/src/page/index.ts +58 -0
- package/src/page/jsonld.ts +94 -0
- package/src/page/metadata.ts +185 -0
- package/src/page/seo-contributions.ts +136 -0
- package/src/plugin-utils.ts +80 -0
- package/src/plugins/adapt-sandbox-entry.ts +207 -0
- package/src/plugins/context.ts +833 -0
- package/src/plugins/cron.ts +361 -0
- package/src/plugins/define-plugin.ts +259 -0
- package/src/plugins/email-console.ts +73 -0
- package/src/plugins/email.ts +209 -0
- package/src/plugins/hooks.ts +1273 -0
- package/src/plugins/index.ts +193 -0
- package/src/plugins/manager.ts +595 -0
- package/src/plugins/manifest-schema.ts +230 -0
- package/src/plugins/marketplace.ts +460 -0
- package/src/plugins/request-meta.ts +139 -0
- package/src/plugins/routes.ts +302 -0
- package/src/plugins/sandbox/index.ts +18 -0
- package/src/plugins/sandbox/noop.ts +76 -0
- package/src/plugins/sandbox/types.ts +173 -0
- package/src/plugins/scheduler/node.ts +122 -0
- package/src/plugins/scheduler/piggyback.ts +71 -0
- package/src/plugins/scheduler/types.ts +27 -0
- package/src/plugins/state.ts +208 -0
- package/src/plugins/storage-indexes.ts +326 -0
- package/src/plugins/storage-query.ts +240 -0
- package/src/plugins/types.ts +1284 -0
- package/src/preview/helpers.ts +27 -0
- package/src/preview/index.ts +40 -0
- package/src/preview/tokens.ts +279 -0
- package/src/preview/urls.ts +118 -0
- package/src/query.ts +674 -0
- package/src/redirects/patterns.ts +224 -0
- package/src/request-context.ts +67 -0
- package/src/runtime.ts +21 -0
- package/src/schema/index.ts +29 -0
- package/src/schema/query.ts +44 -0
- package/src/schema/registry.ts +965 -0
- package/src/schema/types.ts +276 -0
- package/src/schema/zod-generator.ts +413 -0
- package/src/search/fts-manager.ts +452 -0
- package/src/search/index.ts +26 -0
- package/src/search/query.ts +396 -0
- package/src/search/text-extraction.ts +162 -0
- package/src/search/types.ts +114 -0
- package/src/sections/index.ts +226 -0
- package/src/sections/types.ts +86 -0
- package/src/seed/apply.ts +1141 -0
- package/src/seed/default.ts +86 -0
- package/src/seed/index.ts +28 -0
- package/src/seed/load.ts +35 -0
- package/src/seed/types.ts +341 -0
- package/src/seed/validate.ts +642 -0
- package/src/seo/index.ts +179 -0
- package/src/settings/index.ts +203 -0
- package/src/settings/types.ts +58 -0
- package/src/storage/index.ts +28 -0
- package/src/storage/local.ts +249 -0
- package/src/storage/s3.ts +263 -0
- package/src/storage/types.ts +204 -0
- package/src/taxonomies/index.ts +309 -0
- package/src/taxonomies/types.ts +61 -0
- package/src/ui.ts +75 -0
- package/src/utils/base64.ts +73 -0
- package/src/utils/hash.ts +36 -0
- package/src/utils/sanitize.ts +20 -0
- package/src/utils/slugify.ts +29 -0
- package/src/utils/url.ts +48 -0
- package/src/virtual-modules.d.ts +111 -0
- package/src/visual-editing/editable.ts +108 -0
- package/src/visual-editing/toolbar.ts +1229 -0
- package/src/widgets/components.ts +105 -0
- package/src/widgets/index.ts +131 -0
- package/src/widgets/types.ts +81 -0
|
@@ -0,0 +1,969 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress WXR (WordPress eXtended RSS) parser
|
|
3
|
+
*
|
|
4
|
+
* Uses SAX streaming parser to handle large export files efficiently.
|
|
5
|
+
* WXR is an RSS extension containing WordPress content exports.
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.wordpress.org/plugins/data-storage/wp-xml-rpc/
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Readable } from "node:stream";
|
|
11
|
+
|
|
12
|
+
import sax from "sax";
|
|
13
|
+
|
|
14
|
+
// Regex patterns for WXR parsing
|
|
15
|
+
const PHP_SERIALIZED_STRING_PATTERN = /s:\d+:"([^"]+)"/g;
|
|
16
|
+
const PHP_SERIALIZED_STRING_MATCH_PATTERN = /s:\d+:"([^"]+)"/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parsed WordPress export data
|
|
20
|
+
*/
|
|
21
|
+
export interface WxrData {
|
|
22
|
+
/** Site metadata */
|
|
23
|
+
site: WxrSite;
|
|
24
|
+
/** Posts (including custom post types) */
|
|
25
|
+
posts: WxrPost[];
|
|
26
|
+
/** Media attachments */
|
|
27
|
+
attachments: WxrAttachment[];
|
|
28
|
+
/** Categories */
|
|
29
|
+
categories: WxrCategory[];
|
|
30
|
+
/** Tags */
|
|
31
|
+
tags: WxrTag[];
|
|
32
|
+
/** Authors */
|
|
33
|
+
authors: WxrAuthor[];
|
|
34
|
+
/** All taxonomy terms (including custom taxonomies and nav_menu) */
|
|
35
|
+
terms: WxrTerm[];
|
|
36
|
+
/** Parsed navigation menus */
|
|
37
|
+
navMenus: WxrNavMenu[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface WxrSite {
|
|
41
|
+
title?: string;
|
|
42
|
+
link?: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
language?: string;
|
|
45
|
+
baseSiteUrl?: string;
|
|
46
|
+
baseBlogUrl?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface WxrPost {
|
|
50
|
+
id?: number;
|
|
51
|
+
title?: string;
|
|
52
|
+
link?: string;
|
|
53
|
+
pubDate?: string;
|
|
54
|
+
creator?: string;
|
|
55
|
+
guid?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
content?: string;
|
|
58
|
+
excerpt?: string;
|
|
59
|
+
postDate?: string;
|
|
60
|
+
postDateGmt?: string;
|
|
61
|
+
postModified?: string;
|
|
62
|
+
postModifiedGmt?: string;
|
|
63
|
+
commentStatus?: string;
|
|
64
|
+
pingStatus?: string;
|
|
65
|
+
status?: string;
|
|
66
|
+
postType?: string;
|
|
67
|
+
postName?: string;
|
|
68
|
+
postPassword?: string;
|
|
69
|
+
isSticky?: boolean;
|
|
70
|
+
/** Parent post ID for hierarchical content (pages) */
|
|
71
|
+
postParent?: number;
|
|
72
|
+
/** Menu order for sorting */
|
|
73
|
+
menuOrder?: number;
|
|
74
|
+
categories: string[];
|
|
75
|
+
tags: string[];
|
|
76
|
+
/** Custom taxonomy assignments beyond categories/tags */
|
|
77
|
+
customTaxonomies?: Map<string, string[]>;
|
|
78
|
+
meta: Map<string, string>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface WxrAttachment {
|
|
82
|
+
id?: number;
|
|
83
|
+
title?: string;
|
|
84
|
+
url?: string;
|
|
85
|
+
postDate?: string;
|
|
86
|
+
meta: Map<string, string>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface WxrCategory {
|
|
90
|
+
id?: number;
|
|
91
|
+
nicename?: string;
|
|
92
|
+
name?: string;
|
|
93
|
+
parent?: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface WxrTag {
|
|
98
|
+
id?: number;
|
|
99
|
+
slug?: string;
|
|
100
|
+
name?: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generic taxonomy term (categories, tags, nav_menu, custom taxonomies)
|
|
106
|
+
*/
|
|
107
|
+
export interface WxrTerm {
|
|
108
|
+
id: number;
|
|
109
|
+
taxonomy: string; // 'category', 'post_tag', 'nav_menu', 'genre', etc.
|
|
110
|
+
slug: string;
|
|
111
|
+
name: string;
|
|
112
|
+
parent?: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Navigation menu structure
|
|
118
|
+
*/
|
|
119
|
+
export interface WxrNavMenu {
|
|
120
|
+
id: number;
|
|
121
|
+
name: string; // Menu slug
|
|
122
|
+
label: string; // Menu name
|
|
123
|
+
items: WxrNavMenuItem[];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Navigation menu item
|
|
128
|
+
*/
|
|
129
|
+
export interface WxrNavMenuItem {
|
|
130
|
+
id: number;
|
|
131
|
+
menuId: number;
|
|
132
|
+
parentId?: number;
|
|
133
|
+
sortOrder: number;
|
|
134
|
+
type: "custom" | "post_type" | "taxonomy";
|
|
135
|
+
objectType?: string; // 'page', 'post', 'category'
|
|
136
|
+
objectId?: number;
|
|
137
|
+
url?: string;
|
|
138
|
+
title: string;
|
|
139
|
+
target?: string;
|
|
140
|
+
classes?: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface WxrAuthor {
|
|
144
|
+
id?: number;
|
|
145
|
+
login?: string;
|
|
146
|
+
email?: string;
|
|
147
|
+
displayName?: string;
|
|
148
|
+
firstName?: string;
|
|
149
|
+
lastName?: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Extract string value from a SAX attribute (handles both Tag and QualifiedTag) */
|
|
153
|
+
function attrStr(attr: string | { value: string } | undefined): string {
|
|
154
|
+
if (typeof attr === "string") return attr;
|
|
155
|
+
if (attr && typeof attr === "object" && "value" in attr) return attr.value;
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Type guard for complete WxrTerm (all required fields present) */
|
|
160
|
+
function isCompleteWxrTerm(term: Partial<WxrTerm>): term is WxrTerm {
|
|
161
|
+
return (
|
|
162
|
+
term.id !== undefined &&
|
|
163
|
+
term.taxonomy !== undefined &&
|
|
164
|
+
term.slug !== undefined &&
|
|
165
|
+
term.name !== undefined
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Parse a WordPress WXR export file
|
|
171
|
+
*/
|
|
172
|
+
export function parseWxr(stream: Readable): Promise<WxrData> {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
const parser = sax.createStream(true, { trim: true });
|
|
175
|
+
|
|
176
|
+
const data: WxrData = {
|
|
177
|
+
site: {},
|
|
178
|
+
posts: [],
|
|
179
|
+
attachments: [],
|
|
180
|
+
categories: [],
|
|
181
|
+
tags: [],
|
|
182
|
+
authors: [],
|
|
183
|
+
terms: [],
|
|
184
|
+
navMenus: [],
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Parser state
|
|
188
|
+
let currentPath: string[] = [];
|
|
189
|
+
let currentText = "";
|
|
190
|
+
let currentItem: WxrPost | null = null;
|
|
191
|
+
let currentAttachment: WxrAttachment | null = null;
|
|
192
|
+
let currentCategory: WxrCategory | null = null;
|
|
193
|
+
let currentTag: WxrTag | null = null;
|
|
194
|
+
let currentAuthor: WxrAuthor | null = null;
|
|
195
|
+
let currentTerm: Partial<WxrTerm> | null = null;
|
|
196
|
+
let currentMetaKey = "";
|
|
197
|
+
|
|
198
|
+
// Track nav_menu_item posts for post-processing
|
|
199
|
+
const navMenuItemPosts: WxrPost[] = [];
|
|
200
|
+
// Track menu term IDs by slug for linking items to menus
|
|
201
|
+
const menuTermsBySlug = new Map<string, number>();
|
|
202
|
+
|
|
203
|
+
parser.on("opentag", (node) => {
|
|
204
|
+
const tagName = node.name.toLowerCase();
|
|
205
|
+
currentPath.push(tagName);
|
|
206
|
+
currentText = "";
|
|
207
|
+
|
|
208
|
+
// Start new item
|
|
209
|
+
if (tagName === "item") {
|
|
210
|
+
currentItem = {
|
|
211
|
+
categories: [],
|
|
212
|
+
tags: [],
|
|
213
|
+
customTaxonomies: new Map(),
|
|
214
|
+
meta: new Map(),
|
|
215
|
+
};
|
|
216
|
+
} else if (tagName === "wp:category") {
|
|
217
|
+
currentCategory = {};
|
|
218
|
+
} else if (tagName === "wp:tag") {
|
|
219
|
+
currentTag = {};
|
|
220
|
+
} else if (tagName === "wp:author") {
|
|
221
|
+
currentAuthor = {};
|
|
222
|
+
} else if (tagName === "wp:term") {
|
|
223
|
+
currentTerm = {};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Handle category/tag/custom taxonomy assignment in items
|
|
227
|
+
if (tagName === "category" && currentItem && node.attributes) {
|
|
228
|
+
const domain = attrStr(node.attributes.domain);
|
|
229
|
+
const nicename = attrStr(node.attributes.nicename);
|
|
230
|
+
if (domain === "category" && nicename) {
|
|
231
|
+
currentItem.categories.push(nicename);
|
|
232
|
+
} else if (domain === "post_tag" && nicename) {
|
|
233
|
+
currentItem.tags.push(nicename);
|
|
234
|
+
} else if (domain && nicename && domain !== "category" && domain !== "post_tag") {
|
|
235
|
+
// Custom taxonomy (including nav_menu)
|
|
236
|
+
if (!currentItem.customTaxonomies) {
|
|
237
|
+
currentItem.customTaxonomies = new Map();
|
|
238
|
+
}
|
|
239
|
+
const existing = currentItem.customTaxonomies.get(domain) || [];
|
|
240
|
+
existing.push(nicename);
|
|
241
|
+
currentItem.customTaxonomies.set(domain, existing);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
parser.on("text", (text) => {
|
|
247
|
+
currentText += text;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
parser.on("cdata", (cdata) => {
|
|
251
|
+
currentText += cdata;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
parser.on("closetag", (tagName) => {
|
|
255
|
+
const tag = tagName.toLowerCase();
|
|
256
|
+
const text = currentText.trim();
|
|
257
|
+
|
|
258
|
+
// Site-level metadata (in channel)
|
|
259
|
+
if (currentPath.includes("channel") && !currentItem) {
|
|
260
|
+
switch (tag) {
|
|
261
|
+
case "title":
|
|
262
|
+
if (!data.site.title) data.site.title = text;
|
|
263
|
+
break;
|
|
264
|
+
case "link":
|
|
265
|
+
if (!data.site.link) data.site.link = text;
|
|
266
|
+
break;
|
|
267
|
+
case "description":
|
|
268
|
+
if (!data.site.description) data.site.description = text;
|
|
269
|
+
break;
|
|
270
|
+
case "language":
|
|
271
|
+
data.site.language = text;
|
|
272
|
+
break;
|
|
273
|
+
case "wp:base_site_url":
|
|
274
|
+
data.site.baseSiteUrl = text;
|
|
275
|
+
break;
|
|
276
|
+
case "wp:base_blog_url":
|
|
277
|
+
data.site.baseBlogUrl = text;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Item (post/page/attachment) parsing
|
|
283
|
+
if (currentItem) {
|
|
284
|
+
switch (tag) {
|
|
285
|
+
case "title":
|
|
286
|
+
currentItem.title = text;
|
|
287
|
+
break;
|
|
288
|
+
case "link":
|
|
289
|
+
currentItem.link = text;
|
|
290
|
+
break;
|
|
291
|
+
case "pubdate":
|
|
292
|
+
currentItem.pubDate = text;
|
|
293
|
+
break;
|
|
294
|
+
case "dc:creator":
|
|
295
|
+
currentItem.creator = text;
|
|
296
|
+
break;
|
|
297
|
+
case "guid":
|
|
298
|
+
currentItem.guid = text;
|
|
299
|
+
break;
|
|
300
|
+
case "description":
|
|
301
|
+
currentItem.description = text;
|
|
302
|
+
break;
|
|
303
|
+
case "content:encoded":
|
|
304
|
+
currentItem.content = text;
|
|
305
|
+
break;
|
|
306
|
+
case "excerpt:encoded":
|
|
307
|
+
currentItem.excerpt = text;
|
|
308
|
+
break;
|
|
309
|
+
case "wp:post_id":
|
|
310
|
+
currentItem.id = parseInt(text, 10);
|
|
311
|
+
break;
|
|
312
|
+
case "wp:post_date":
|
|
313
|
+
currentItem.postDate = text;
|
|
314
|
+
break;
|
|
315
|
+
case "wp:post_date_gmt":
|
|
316
|
+
currentItem.postDateGmt = text;
|
|
317
|
+
break;
|
|
318
|
+
case "wp:post_modified":
|
|
319
|
+
currentItem.postModified = text;
|
|
320
|
+
break;
|
|
321
|
+
case "wp:post_modified_gmt":
|
|
322
|
+
currentItem.postModifiedGmt = text;
|
|
323
|
+
break;
|
|
324
|
+
case "wp:comment_status":
|
|
325
|
+
currentItem.commentStatus = text;
|
|
326
|
+
break;
|
|
327
|
+
case "wp:ping_status":
|
|
328
|
+
currentItem.pingStatus = text;
|
|
329
|
+
break;
|
|
330
|
+
case "wp:status":
|
|
331
|
+
currentItem.status = text;
|
|
332
|
+
break;
|
|
333
|
+
case "wp:post_type":
|
|
334
|
+
currentItem.postType = text;
|
|
335
|
+
break;
|
|
336
|
+
case "wp:post_name":
|
|
337
|
+
currentItem.postName = text;
|
|
338
|
+
break;
|
|
339
|
+
case "wp:post_parent":
|
|
340
|
+
currentItem.postParent = parseInt(text, 10);
|
|
341
|
+
break;
|
|
342
|
+
case "wp:menu_order":
|
|
343
|
+
currentItem.menuOrder = parseInt(text, 10);
|
|
344
|
+
break;
|
|
345
|
+
case "wp:post_password":
|
|
346
|
+
currentItem.postPassword = text || undefined;
|
|
347
|
+
break;
|
|
348
|
+
case "wp:is_sticky":
|
|
349
|
+
currentItem.isSticky = text === "1";
|
|
350
|
+
break;
|
|
351
|
+
case "wp:meta_key":
|
|
352
|
+
currentMetaKey = text;
|
|
353
|
+
break;
|
|
354
|
+
case "wp:meta_value":
|
|
355
|
+
if (currentMetaKey) {
|
|
356
|
+
currentItem.meta.set(currentMetaKey, text);
|
|
357
|
+
currentMetaKey = "";
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
case "wp:attachment_url":
|
|
361
|
+
if (currentItem.postType === "attachment") {
|
|
362
|
+
// This is actually an attachment
|
|
363
|
+
currentAttachment = {
|
|
364
|
+
id: currentItem.id,
|
|
365
|
+
title: currentItem.title,
|
|
366
|
+
url: text,
|
|
367
|
+
postDate: currentItem.postDate,
|
|
368
|
+
meta: currentItem.meta,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
break;
|
|
372
|
+
case "item":
|
|
373
|
+
// End of item - categorize and store
|
|
374
|
+
if (currentAttachment) {
|
|
375
|
+
data.attachments.push(currentAttachment);
|
|
376
|
+
currentAttachment = null;
|
|
377
|
+
} else if (currentItem.postType === "nav_menu_item") {
|
|
378
|
+
// Track nav_menu_item posts for post-processing into menus
|
|
379
|
+
navMenuItemPosts.push(currentItem);
|
|
380
|
+
data.posts.push(currentItem);
|
|
381
|
+
} else if (currentItem.postType !== "attachment") {
|
|
382
|
+
// Store all non-attachment post types (posts, pages, custom post types)
|
|
383
|
+
data.posts.push(currentItem);
|
|
384
|
+
}
|
|
385
|
+
currentItem = null;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Category parsing
|
|
391
|
+
if (currentCategory) {
|
|
392
|
+
switch (tag) {
|
|
393
|
+
case "wp:term_id":
|
|
394
|
+
currentCategory.id = parseInt(text, 10);
|
|
395
|
+
break;
|
|
396
|
+
case "wp:category_nicename":
|
|
397
|
+
currentCategory.nicename = text;
|
|
398
|
+
break;
|
|
399
|
+
case "wp:cat_name":
|
|
400
|
+
currentCategory.name = text;
|
|
401
|
+
break;
|
|
402
|
+
case "wp:category_parent":
|
|
403
|
+
currentCategory.parent = text || undefined;
|
|
404
|
+
break;
|
|
405
|
+
case "wp:category_description":
|
|
406
|
+
currentCategory.description = text || undefined;
|
|
407
|
+
break;
|
|
408
|
+
case "wp:category":
|
|
409
|
+
if (currentCategory.name) {
|
|
410
|
+
data.categories.push(currentCategory);
|
|
411
|
+
}
|
|
412
|
+
currentCategory = null;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Tag parsing
|
|
418
|
+
if (currentTag) {
|
|
419
|
+
switch (tag) {
|
|
420
|
+
case "wp:term_id":
|
|
421
|
+
currentTag.id = parseInt(text, 10);
|
|
422
|
+
break;
|
|
423
|
+
case "wp:tag_slug":
|
|
424
|
+
currentTag.slug = text;
|
|
425
|
+
break;
|
|
426
|
+
case "wp:tag_name":
|
|
427
|
+
currentTag.name = text;
|
|
428
|
+
break;
|
|
429
|
+
case "wp:tag_description":
|
|
430
|
+
currentTag.description = text || undefined;
|
|
431
|
+
break;
|
|
432
|
+
case "wp:tag":
|
|
433
|
+
if (currentTag.name) {
|
|
434
|
+
data.tags.push(currentTag);
|
|
435
|
+
}
|
|
436
|
+
currentTag = null;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Author parsing
|
|
442
|
+
if (currentAuthor) {
|
|
443
|
+
switch (tag) {
|
|
444
|
+
case "wp:author_id":
|
|
445
|
+
currentAuthor.id = parseInt(text, 10);
|
|
446
|
+
break;
|
|
447
|
+
case "wp:author_login":
|
|
448
|
+
currentAuthor.login = text;
|
|
449
|
+
break;
|
|
450
|
+
case "wp:author_email":
|
|
451
|
+
currentAuthor.email = text;
|
|
452
|
+
break;
|
|
453
|
+
case "wp:author_display_name":
|
|
454
|
+
currentAuthor.displayName = text;
|
|
455
|
+
break;
|
|
456
|
+
case "wp:author_first_name":
|
|
457
|
+
currentAuthor.firstName = text;
|
|
458
|
+
break;
|
|
459
|
+
case "wp:author_last_name":
|
|
460
|
+
currentAuthor.lastName = text;
|
|
461
|
+
break;
|
|
462
|
+
case "wp:author":
|
|
463
|
+
if (currentAuthor.login) {
|
|
464
|
+
data.authors.push(currentAuthor);
|
|
465
|
+
}
|
|
466
|
+
currentAuthor = null;
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Generic term parsing (wp:term elements - custom taxonomies, nav_menu, etc.)
|
|
472
|
+
if (currentTerm) {
|
|
473
|
+
switch (tag) {
|
|
474
|
+
case "wp:term_id":
|
|
475
|
+
currentTerm.id = parseInt(text, 10);
|
|
476
|
+
break;
|
|
477
|
+
case "wp:term_taxonomy":
|
|
478
|
+
currentTerm.taxonomy = text;
|
|
479
|
+
break;
|
|
480
|
+
case "wp:term_slug":
|
|
481
|
+
currentTerm.slug = text;
|
|
482
|
+
break;
|
|
483
|
+
case "wp:term_name":
|
|
484
|
+
currentTerm.name = text;
|
|
485
|
+
break;
|
|
486
|
+
case "wp:term_parent":
|
|
487
|
+
currentTerm.parent = text || undefined;
|
|
488
|
+
break;
|
|
489
|
+
case "wp:term_description":
|
|
490
|
+
currentTerm.description = text || undefined;
|
|
491
|
+
break;
|
|
492
|
+
case "wp:term":
|
|
493
|
+
if (isCompleteWxrTerm(currentTerm)) {
|
|
494
|
+
data.terms.push(currentTerm);
|
|
495
|
+
// Track nav_menu terms for building menus
|
|
496
|
+
if (currentTerm.taxonomy === "nav_menu") {
|
|
497
|
+
menuTermsBySlug.set(currentTerm.slug, currentTerm.id);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
currentTerm = null;
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
currentPath.pop();
|
|
506
|
+
currentText = "";
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
parser.on("error", (err) => {
|
|
510
|
+
reject(new Error(`XML parsing error: ${err.message}`));
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
parser.on("end", () => {
|
|
514
|
+
// Post-process nav_menu_item posts into structured menus
|
|
515
|
+
data.navMenus = buildNavMenus(navMenuItemPosts, menuTermsBySlug);
|
|
516
|
+
resolve(data);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// Pipe the stream through the parser
|
|
520
|
+
stream.pipe(parser);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Parse a WordPress WXR export from a string
|
|
526
|
+
*
|
|
527
|
+
* Uses the non-streaming SAX parser API for compatibility with
|
|
528
|
+
* environments that don't have Node.js streams (e.g., Cloudflare Workers).
|
|
529
|
+
*/
|
|
530
|
+
export function parseWxrString(xml: string): Promise<WxrData> {
|
|
531
|
+
return new Promise((resolve, reject) => {
|
|
532
|
+
const parser = sax.parser(true, { trim: false, normalize: false });
|
|
533
|
+
|
|
534
|
+
const data: WxrData = {
|
|
535
|
+
site: {},
|
|
536
|
+
posts: [],
|
|
537
|
+
attachments: [],
|
|
538
|
+
categories: [],
|
|
539
|
+
tags: [],
|
|
540
|
+
authors: [],
|
|
541
|
+
terms: [],
|
|
542
|
+
navMenus: [],
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
let currentPath: string[] = [];
|
|
546
|
+
let currentText = "";
|
|
547
|
+
let currentItem: WxrPost | null = null;
|
|
548
|
+
let currentAttachment: WxrAttachment | null = null;
|
|
549
|
+
let currentCategory: WxrCategory | null = null;
|
|
550
|
+
let currentTag: WxrTag | null = null;
|
|
551
|
+
let currentAuthor: WxrAuthor | null = null;
|
|
552
|
+
let currentTerm: Partial<WxrTerm> | null = null;
|
|
553
|
+
let currentMetaKey = "";
|
|
554
|
+
|
|
555
|
+
// Track nav_menu_item posts for post-processing
|
|
556
|
+
const navMenuItemPosts: WxrPost[] = [];
|
|
557
|
+
// Track menu term IDs by slug for linking items to menus
|
|
558
|
+
const menuTermsBySlug = new Map<string, number>();
|
|
559
|
+
|
|
560
|
+
parser.onopentag = (node) => {
|
|
561
|
+
const tag = node.name.toLowerCase();
|
|
562
|
+
currentPath.push(tag);
|
|
563
|
+
currentText = "";
|
|
564
|
+
|
|
565
|
+
// Start new elements
|
|
566
|
+
if (tag === "item") {
|
|
567
|
+
currentItem = {
|
|
568
|
+
categories: [],
|
|
569
|
+
tags: [],
|
|
570
|
+
customTaxonomies: new Map(),
|
|
571
|
+
meta: new Map(),
|
|
572
|
+
};
|
|
573
|
+
} else if (tag === "wp:category") {
|
|
574
|
+
currentCategory = {};
|
|
575
|
+
} else if (tag === "wp:tag") {
|
|
576
|
+
currentTag = {};
|
|
577
|
+
} else if (tag === "wp:author") {
|
|
578
|
+
currentAuthor = {};
|
|
579
|
+
} else if (tag === "wp:term") {
|
|
580
|
+
currentTerm = {};
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Handle category/tag/custom taxonomy assignment in items
|
|
584
|
+
if (tag === "category" && currentItem && node.attributes) {
|
|
585
|
+
const domain = attrStr(node.attributes.domain);
|
|
586
|
+
const nicename = attrStr(node.attributes.nicename);
|
|
587
|
+
if (domain === "category" && nicename) {
|
|
588
|
+
currentItem.categories.push(nicename);
|
|
589
|
+
} else if (domain === "post_tag" && nicename) {
|
|
590
|
+
currentItem.tags.push(nicename);
|
|
591
|
+
} else if (domain && nicename && domain !== "category" && domain !== "post_tag") {
|
|
592
|
+
// Custom taxonomy (including nav_menu)
|
|
593
|
+
if (!currentItem.customTaxonomies) {
|
|
594
|
+
currentItem.customTaxonomies = new Map();
|
|
595
|
+
}
|
|
596
|
+
const existing = currentItem.customTaxonomies.get(domain) || [];
|
|
597
|
+
existing.push(nicename);
|
|
598
|
+
currentItem.customTaxonomies.set(domain, existing);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
parser.ontext = (text) => {
|
|
604
|
+
currentText += text;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
parser.oncdata = (cdata) => {
|
|
608
|
+
currentText += cdata;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
parser.onclosetag = (tagName) => {
|
|
612
|
+
const tag = tagName.toLowerCase();
|
|
613
|
+
const text = currentText.trim();
|
|
614
|
+
|
|
615
|
+
// Site metadata
|
|
616
|
+
if (currentPath.length === 2 && currentPath[0] === "rss") {
|
|
617
|
+
switch (tag) {
|
|
618
|
+
case "title":
|
|
619
|
+
data.site.title = text;
|
|
620
|
+
break;
|
|
621
|
+
case "link":
|
|
622
|
+
data.site.link = text;
|
|
623
|
+
break;
|
|
624
|
+
case "description":
|
|
625
|
+
data.site.description = text;
|
|
626
|
+
break;
|
|
627
|
+
case "language":
|
|
628
|
+
data.site.language = text;
|
|
629
|
+
break;
|
|
630
|
+
case "wp:base_site_url":
|
|
631
|
+
data.site.baseSiteUrl = text;
|
|
632
|
+
break;
|
|
633
|
+
case "wp:base_blog_url":
|
|
634
|
+
data.site.baseBlogUrl = text;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Item (post/page/attachment) parsing
|
|
640
|
+
if (currentItem) {
|
|
641
|
+
switch (tag) {
|
|
642
|
+
case "title":
|
|
643
|
+
currentItem.title = text;
|
|
644
|
+
break;
|
|
645
|
+
case "link":
|
|
646
|
+
currentItem.link = text;
|
|
647
|
+
break;
|
|
648
|
+
case "pubdate":
|
|
649
|
+
currentItem.pubDate = text;
|
|
650
|
+
break;
|
|
651
|
+
case "dc:creator":
|
|
652
|
+
currentItem.creator = text;
|
|
653
|
+
break;
|
|
654
|
+
case "guid":
|
|
655
|
+
currentItem.guid = text;
|
|
656
|
+
break;
|
|
657
|
+
case "description":
|
|
658
|
+
currentItem.description = text;
|
|
659
|
+
break;
|
|
660
|
+
case "content:encoded":
|
|
661
|
+
currentItem.content = text;
|
|
662
|
+
break;
|
|
663
|
+
case "excerpt:encoded":
|
|
664
|
+
currentItem.excerpt = text;
|
|
665
|
+
break;
|
|
666
|
+
case "wp:post_id":
|
|
667
|
+
currentItem.id = parseInt(text, 10);
|
|
668
|
+
break;
|
|
669
|
+
case "wp:post_date":
|
|
670
|
+
currentItem.postDate = text;
|
|
671
|
+
break;
|
|
672
|
+
case "wp:post_date_gmt":
|
|
673
|
+
currentItem.postDateGmt = text;
|
|
674
|
+
break;
|
|
675
|
+
case "wp:post_modified":
|
|
676
|
+
currentItem.postModified = text;
|
|
677
|
+
break;
|
|
678
|
+
case "wp:post_modified_gmt":
|
|
679
|
+
currentItem.postModifiedGmt = text;
|
|
680
|
+
break;
|
|
681
|
+
case "wp:comment_status":
|
|
682
|
+
currentItem.commentStatus = text;
|
|
683
|
+
break;
|
|
684
|
+
case "wp:ping_status":
|
|
685
|
+
currentItem.pingStatus = text;
|
|
686
|
+
break;
|
|
687
|
+
case "wp:post_name":
|
|
688
|
+
currentItem.postName = text;
|
|
689
|
+
break;
|
|
690
|
+
case "wp:status":
|
|
691
|
+
currentItem.status = text;
|
|
692
|
+
break;
|
|
693
|
+
case "wp:post_parent":
|
|
694
|
+
currentItem.postParent = parseInt(text, 10);
|
|
695
|
+
break;
|
|
696
|
+
case "wp:menu_order":
|
|
697
|
+
currentItem.menuOrder = parseInt(text, 10);
|
|
698
|
+
break;
|
|
699
|
+
case "wp:post_type":
|
|
700
|
+
currentItem.postType = text;
|
|
701
|
+
// If it's an attachment, convert to attachment type
|
|
702
|
+
if (text === "attachment") {
|
|
703
|
+
currentAttachment = {
|
|
704
|
+
id: currentItem.id,
|
|
705
|
+
title: currentItem.title,
|
|
706
|
+
url: currentItem.link,
|
|
707
|
+
postDate: currentItem.postDate,
|
|
708
|
+
meta: new Map(),
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
break;
|
|
712
|
+
case "wp:post_password":
|
|
713
|
+
currentItem.postPassword = text || undefined;
|
|
714
|
+
break;
|
|
715
|
+
case "wp:is_sticky":
|
|
716
|
+
currentItem.isSticky = text === "1";
|
|
717
|
+
break;
|
|
718
|
+
case "wp:attachment_url":
|
|
719
|
+
if (currentAttachment) {
|
|
720
|
+
currentAttachment.url = text;
|
|
721
|
+
}
|
|
722
|
+
break;
|
|
723
|
+
case "wp:meta_key":
|
|
724
|
+
currentMetaKey = text;
|
|
725
|
+
break;
|
|
726
|
+
case "wp:meta_value":
|
|
727
|
+
if (currentMetaKey && currentItem.meta) {
|
|
728
|
+
currentItem.meta.set(currentMetaKey, text);
|
|
729
|
+
}
|
|
730
|
+
break;
|
|
731
|
+
case "item":
|
|
732
|
+
// End of item - categorize and store
|
|
733
|
+
if (currentAttachment) {
|
|
734
|
+
data.attachments.push(currentAttachment);
|
|
735
|
+
currentAttachment = null;
|
|
736
|
+
} else if (currentItem.postType === "nav_menu_item") {
|
|
737
|
+
// Track nav_menu_item posts for post-processing into menus
|
|
738
|
+
navMenuItemPosts.push(currentItem);
|
|
739
|
+
data.posts.push(currentItem);
|
|
740
|
+
} else if (currentItem.postType !== "attachment") {
|
|
741
|
+
data.posts.push(currentItem);
|
|
742
|
+
}
|
|
743
|
+
currentItem = null;
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// Category parsing
|
|
749
|
+
if (currentCategory) {
|
|
750
|
+
switch (tag) {
|
|
751
|
+
case "wp:term_id":
|
|
752
|
+
currentCategory.id = parseInt(text, 10);
|
|
753
|
+
break;
|
|
754
|
+
case "wp:category_nicename":
|
|
755
|
+
currentCategory.nicename = text;
|
|
756
|
+
break;
|
|
757
|
+
case "wp:cat_name":
|
|
758
|
+
currentCategory.name = text;
|
|
759
|
+
break;
|
|
760
|
+
case "wp:category_parent":
|
|
761
|
+
currentCategory.parent = text || undefined;
|
|
762
|
+
break;
|
|
763
|
+
case "wp:category_description":
|
|
764
|
+
currentCategory.description = text || undefined;
|
|
765
|
+
break;
|
|
766
|
+
case "wp:category":
|
|
767
|
+
if (currentCategory.name) {
|
|
768
|
+
data.categories.push(currentCategory);
|
|
769
|
+
}
|
|
770
|
+
currentCategory = null;
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// Tag parsing
|
|
776
|
+
if (currentTag) {
|
|
777
|
+
switch (tag) {
|
|
778
|
+
case "wp:term_id":
|
|
779
|
+
currentTag.id = parseInt(text, 10);
|
|
780
|
+
break;
|
|
781
|
+
case "wp:tag_slug":
|
|
782
|
+
currentTag.slug = text;
|
|
783
|
+
break;
|
|
784
|
+
case "wp:tag_name":
|
|
785
|
+
currentTag.name = text;
|
|
786
|
+
break;
|
|
787
|
+
case "wp:tag_description":
|
|
788
|
+
currentTag.description = text || undefined;
|
|
789
|
+
break;
|
|
790
|
+
case "wp:tag":
|
|
791
|
+
if (currentTag.name) {
|
|
792
|
+
data.tags.push(currentTag);
|
|
793
|
+
}
|
|
794
|
+
currentTag = null;
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// Author parsing
|
|
800
|
+
if (currentAuthor) {
|
|
801
|
+
switch (tag) {
|
|
802
|
+
case "wp:author_id":
|
|
803
|
+
currentAuthor.id = parseInt(text, 10);
|
|
804
|
+
break;
|
|
805
|
+
case "wp:author_login":
|
|
806
|
+
currentAuthor.login = text;
|
|
807
|
+
break;
|
|
808
|
+
case "wp:author_email":
|
|
809
|
+
currentAuthor.email = text;
|
|
810
|
+
break;
|
|
811
|
+
case "wp:author_display_name":
|
|
812
|
+
currentAuthor.displayName = text;
|
|
813
|
+
break;
|
|
814
|
+
case "wp:author_first_name":
|
|
815
|
+
currentAuthor.firstName = text;
|
|
816
|
+
break;
|
|
817
|
+
case "wp:author_last_name":
|
|
818
|
+
currentAuthor.lastName = text;
|
|
819
|
+
break;
|
|
820
|
+
case "wp:author":
|
|
821
|
+
if (currentAuthor.login) {
|
|
822
|
+
data.authors.push(currentAuthor);
|
|
823
|
+
}
|
|
824
|
+
currentAuthor = null;
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Generic term parsing (wp:term elements - custom taxonomies, nav_menu, etc.)
|
|
830
|
+
if (currentTerm) {
|
|
831
|
+
switch (tag) {
|
|
832
|
+
case "wp:term_id":
|
|
833
|
+
currentTerm.id = parseInt(text, 10);
|
|
834
|
+
break;
|
|
835
|
+
case "wp:term_taxonomy":
|
|
836
|
+
currentTerm.taxonomy = text;
|
|
837
|
+
break;
|
|
838
|
+
case "wp:term_slug":
|
|
839
|
+
currentTerm.slug = text;
|
|
840
|
+
break;
|
|
841
|
+
case "wp:term_name":
|
|
842
|
+
currentTerm.name = text;
|
|
843
|
+
break;
|
|
844
|
+
case "wp:term_parent":
|
|
845
|
+
currentTerm.parent = text || undefined;
|
|
846
|
+
break;
|
|
847
|
+
case "wp:term_description":
|
|
848
|
+
currentTerm.description = text || undefined;
|
|
849
|
+
break;
|
|
850
|
+
case "wp:term":
|
|
851
|
+
if (isCompleteWxrTerm(currentTerm)) {
|
|
852
|
+
data.terms.push(currentTerm);
|
|
853
|
+
// Track nav_menu terms for building menus
|
|
854
|
+
if (currentTerm.taxonomy === "nav_menu") {
|
|
855
|
+
menuTermsBySlug.set(currentTerm.slug, currentTerm.id);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
currentTerm = null;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
currentPath.pop();
|
|
864
|
+
currentText = "";
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
parser.onerror = (err) => {
|
|
868
|
+
reject(new Error(`XML parsing error: ${err.message}`));
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
parser.onend = () => {
|
|
872
|
+
// Post-process nav_menu_item posts into structured menus
|
|
873
|
+
data.navMenus = buildNavMenus(navMenuItemPosts, menuTermsBySlug);
|
|
874
|
+
resolve(data);
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// Parse the string (non-streaming)
|
|
878
|
+
parser.write(xml).close();
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Build structured navigation menus from nav_menu_item posts
|
|
884
|
+
*/
|
|
885
|
+
function buildNavMenus(
|
|
886
|
+
navMenuItemPosts: WxrPost[],
|
|
887
|
+
menuTermsBySlug: Map<string, number>,
|
|
888
|
+
): WxrNavMenu[] {
|
|
889
|
+
// Group menu items by menu slug
|
|
890
|
+
const menuItemsByMenu = new Map<string, WxrPost[]>();
|
|
891
|
+
|
|
892
|
+
for (const post of navMenuItemPosts) {
|
|
893
|
+
// Get the nav_menu taxonomy assignment to find which menu this item belongs to
|
|
894
|
+
const navMenuSlugs = post.customTaxonomies?.get("nav_menu");
|
|
895
|
+
if (!navMenuSlugs || navMenuSlugs.length === 0) continue;
|
|
896
|
+
|
|
897
|
+
const menuSlug = navMenuSlugs[0];
|
|
898
|
+
if (!menuSlug) continue;
|
|
899
|
+
|
|
900
|
+
const items = menuItemsByMenu.get(menuSlug) || [];
|
|
901
|
+
items.push(post);
|
|
902
|
+
menuItemsByMenu.set(menuSlug, items);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// Build structured menus
|
|
906
|
+
const menus: WxrNavMenu[] = [];
|
|
907
|
+
|
|
908
|
+
for (const [menuSlug, posts] of menuItemsByMenu) {
|
|
909
|
+
const menuId = menuTermsBySlug.get(menuSlug) || 0;
|
|
910
|
+
|
|
911
|
+
// Convert posts to menu items
|
|
912
|
+
const items: WxrNavMenuItem[] = posts.map((post) => {
|
|
913
|
+
const meta = post.meta;
|
|
914
|
+
const menuItemTypeRaw = meta.get("_menu_item_type") || "custom";
|
|
915
|
+
const menuItemType: WxrNavMenuItem["type"] =
|
|
916
|
+
menuItemTypeRaw === "post_type" || menuItemTypeRaw === "taxonomy"
|
|
917
|
+
? menuItemTypeRaw
|
|
918
|
+
: "custom";
|
|
919
|
+
const objectType = meta.get("_menu_item_object");
|
|
920
|
+
const objectIdStr = meta.get("_menu_item_object_id");
|
|
921
|
+
const url = meta.get("_menu_item_url");
|
|
922
|
+
const parentIdStr = meta.get("_menu_item_menu_item_parent");
|
|
923
|
+
const target = meta.get("_menu_item_target");
|
|
924
|
+
const classesStr = meta.get("_menu_item_classes");
|
|
925
|
+
|
|
926
|
+
// Parse classes (stored as serialized PHP array)
|
|
927
|
+
let classes: string | undefined;
|
|
928
|
+
if (classesStr) {
|
|
929
|
+
// Simple extraction of class names from serialized PHP
|
|
930
|
+
const matches = classesStr.match(PHP_SERIALIZED_STRING_PATTERN);
|
|
931
|
+
if (matches) {
|
|
932
|
+
classes = matches
|
|
933
|
+
.map((m) => m.match(PHP_SERIALIZED_STRING_MATCH_PATTERN)?.[1])
|
|
934
|
+
.filter(Boolean)
|
|
935
|
+
.join(" ");
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
return {
|
|
940
|
+
id: post.id || 0,
|
|
941
|
+
menuId,
|
|
942
|
+
parentId: parentIdStr ? parseInt(parentIdStr, 10) || undefined : undefined,
|
|
943
|
+
sortOrder: post.menuOrder || 0,
|
|
944
|
+
type: menuItemType,
|
|
945
|
+
objectType: objectType || undefined,
|
|
946
|
+
objectId: objectIdStr ? parseInt(objectIdStr, 10) : undefined,
|
|
947
|
+
url: url || undefined,
|
|
948
|
+
title: post.title || "",
|
|
949
|
+
target: target || undefined,
|
|
950
|
+
classes: classes || undefined,
|
|
951
|
+
};
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
// Sort items by menu_order
|
|
955
|
+
items.sort((a, b) => a.sortOrder - b.sortOrder);
|
|
956
|
+
|
|
957
|
+
// Find the menu name from the terms
|
|
958
|
+
// For now, use the slug as both name and label; we could enhance this
|
|
959
|
+
// by looking up the actual term name from data.terms
|
|
960
|
+
menus.push({
|
|
961
|
+
id: menuId,
|
|
962
|
+
name: menuSlug,
|
|
963
|
+
label: menuSlug, // Will be enhanced when we have term data
|
|
964
|
+
items,
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
return menus;
|
|
969
|
+
}
|