diff --git a/local.db b/local.db new file mode 100644 index 0000000000..fb2b86b99f Binary files /dev/null and b/local.db differ diff --git a/local.db-shm b/local.db-shm new file mode 100644 index 0000000000..b5961191ac Binary files /dev/null and b/local.db-shm differ diff --git a/local.db-wal b/local.db-wal new file mode 100644 index 0000000000..1ed801d1e5 Binary files /dev/null and b/local.db-wal differ diff --git a/packages/studiocms_devapps/package.json b/packages/studiocms_devapps/package.json index 3d9578537d..f37ea6049e 100644 --- a/packages/studiocms_devapps/package.json +++ b/packages/studiocms_devapps/package.json @@ -44,7 +44,8 @@ "cheerio": "^1.0.0", "@types/cheerio": "^0.22.35", "turndown": "^7.2.0", - "@types/turndown": "^5.0.5" + "@types/turndown": "^5.0.5", + "html-entities": "^2.5.2" }, "peerDependencies": { "@astrojs/db": "catalog:min", diff --git a/packages/studiocms_devapps/src/routes/wp-api-importer.ts b/packages/studiocms_devapps/src/routes/wp-api-importer.ts index 56436f8371..4f4a433e58 100644 --- a/packages/studiocms_devapps/src/routes/wp-api-importer.ts +++ b/packages/studiocms_devapps/src/routes/wp-api-importer.ts @@ -21,7 +21,7 @@ export const POST: APIRoute = async ({ request }: APIContext) => { }); } - if (typeof url !== 'string' || typeof type !== 'string' || typeof useBlogPlugin !== 'string') { + if (typeof url !== 'string' || typeof type !== 'string') { return new Response(null, { status: 400, statusText: 'Bad Request', @@ -32,12 +32,14 @@ export const POST: APIRoute = async ({ request }: APIContext) => { }); } + const useBlogPluginValue = useBlogPlugin === 'true'; + switch (type) { case 'pages': await importPagesFromWPAPI(url); break; case 'posts': - await importPostsFromWPAPI(url, useBlogPlugin === 'true'); + await importPostsFromWPAPI(url, useBlogPluginValue); break; default: throw new Error('Invalid import type'); diff --git a/packages/studiocms_devapps/src/utils/wp-api/converters.ts b/packages/studiocms_devapps/src/utils/wp-api/converters.ts index 14bf37a7d0..6ed38a7771 100644 --- a/packages/studiocms_devapps/src/utils/wp-api/converters.ts +++ b/packages/studiocms_devapps/src/utils/wp-api/converters.ts @@ -1,5 +1,6 @@ import path from 'node:path'; import Config from 'virtual:studiocms-devapps/wp-api/configPath'; +import { decode } from 'html-entities'; import TurndownService from 'turndown'; import type { Page, Post } from '../../schema/wp-api'; import type { PageContent, PageData } from './index'; @@ -16,12 +17,11 @@ export const ConvertToPageData = (page: unknown): PageData => { const pageData: PageData = { id: crypto.randomUUID(), title: data.title.rendered, - description: stripHtml(data.excerpt.rendered), + description: decode(stripHtml(data.excerpt.rendered)), slug: data.slug, publishedAt: new Date(data.date_gmt), updatedAt: new Date(data.modified_gmt), showOnNav: false, - heroImage: '', contentLang: 'default', package: 'studiocms', }; @@ -68,12 +68,11 @@ export const ConvertToPostData = (post: unknown, useBlogPkg: boolean): PageData const pageData: PageData = { id: crypto.randomUUID(), title: data.title.rendered, - description: stripHtml(data.excerpt.rendered), + description: decode(stripHtml(data.excerpt.rendered)), slug: data.slug, publishedAt: new Date(data.date_gmt), updatedAt: new Date(data.modified_gmt), showOnNav: false, - heroImage: '', contentLang: 'default', package: pkg, }; diff --git a/packages/studiocms_devapps/src/utils/wp-api/index.ts b/packages/studiocms_devapps/src/utils/wp-api/index.ts index ca7691f8ea..9484a1a87a 100644 --- a/packages/studiocms_devapps/src/utils/wp-api/index.ts +++ b/packages/studiocms_devapps/src/utils/wp-api/index.ts @@ -57,8 +57,11 @@ export const importPagesFromWPAPI = async (endpoint: string) => { const url = apiEndpoint(endpoint, 'pages'); const pages: Page[] = await fetchAll(url); + console.log('pages', pages.length); + try { for (const page of pages) { + console.log('importing page:', page.title.rendered); await importPage(page); } } catch (error) { @@ -94,10 +97,16 @@ const importPost = async (post: unknown, useBlogPkg: boolean) => { export const importPostsFromWPAPI = async (endpoint: string, useBlogPkg: boolean) => { const url = apiEndpoint(endpoint, 'posts'); + + console.log('fetching posts from:', url.origin); + const posts: Page[] = await fetchAll(url); + console.log('posts', posts.length); + try { for (const post of posts) { + console.log('importing post:', post.title.rendered); await importPost(post, useBlogPkg); } } catch (error) { diff --git a/playgrounds/node/public/wp-import/pages/RS-Restore-screen-1.png b/playgrounds/node/public/wp-import/pages/RS-Restore-screen-1.png new file mode 100644 index 0000000000..0a614cebe9 Binary files /dev/null and b/playgrounds/node/public/wp-import/pages/RS-Restore-screen-1.png differ diff --git a/playgrounds/node/public/wp-import/pages/lazyload-fallback.gif b/playgrounds/node/public/wp-import/pages/lazyload-fallback.gif new file mode 100644 index 0000000000..a6522ca954 Binary files /dev/null and b/playgrounds/node/public/wp-import/pages/lazyload-fallback.gif differ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 346055b595..0234d9c223 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -662,6 +662,9 @@ importers: cheerio: specifier: ^1.0.0 version: 1.0.0 + html-entities: + specifier: ^2.5.2 + version: 2.5.2 turndown: specifier: ^7.2.0 version: 7.2.0