From ab3bbdabc37ae4ef14044bd6b29c4dfb80254362 Mon Sep 17 00:00:00 2001 From: Nico Schett <52858351+schettn@users.noreply.github.com> Date: Thu, 2 Sep 2021 15:02:39 +0000 Subject: [PATCH] fix: page creaction and esm --- examples/my-gatsby-site/jaen-pages.json | 109 +----------------- packages/jaen-pages/gatsby-config.js | 2 + packages/jaen-pages/gatsby-node.js | 12 +- packages/jaen-pages/package.json | 6 +- .../src/containers/fields/TextField/index.tsx | 2 +- .../src/containers/ui/tabs/PagesTab.tsx | 4 +- packages/jaen-pages/src/contexts/cms.tsx | 2 + .../molecules/PageTree/treeconverter.ts | 5 +- packages/jaen/package.json | 4 +- 9 files changed, 29 insertions(+), 117 deletions(-) diff --git a/examples/my-gatsby-site/jaen-pages.json b/examples/my-gatsby-site/jaen-pages.json index 99990d3c..bf517e53 100644 --- a/examples/my-gatsby-site/jaen-pages.json +++ b/examples/my-gatsby-site/jaen-pages.json @@ -1,108 +1,3 @@ { - "pages": { - "43a26ef0-a5f3-44d2-9bde-49dfc4b8e045": { - "context": { - "createdAt": "2021-09-02T12:14:12.634Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmbugRA1zUQ8YsPJvRWnKtM6UN1vqeetGni8whJYqEQD4f" - }, - "migrations": [ - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmWqvJ3W9mZLDeDsjRz7aKt36QrUM3Dtjb2oZM93r3VTXs", - "createdAt": "2021-09-02T01:16:53.012Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmS4nuKwzGwJ6j1TFK7udd1dpFFCNBEA1CELcYPfDmTTaA", - "createdAt": "2021-09-02T07:33:05.357Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmRM9o95hkbYBRxVieJtfvXT2Ss5LWzp5fJA3MciwupAjg", - "createdAt": "2021-09-02T07:40:21.196Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmRM9o95hkbYBRxVieJtfvXT2Ss5LWzp5fJA3MciwupAjg", - "createdAt": "2021-09-02T07:40:21.196Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmRM9o95hkbYBRxVieJtfvXT2Ss5LWzp5fJA3MciwupAjg", - "createdAt": "2021-09-02T07:40:21.196Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmRM9o95hkbYBRxVieJtfvXT2Ss5LWzp5fJA3MciwupAjg", - "createdAt": "2021-09-02T07:40:21.196Z" - }, - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmacANZVtBznD6Ffjh6JrfYbeX3Z3b4pmSfYmMY4xxHMgt", - "createdAt": "2021-09-02T12:14:12.634Z" - } - ] - }, - "SitePage /dev-404-page/": { - "context": { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmWRihViYAgAzcSVLX27rEFwGWCw5B9Pugy2hRnVLKTChF", - "createdAt": "2021-09-02T07:36:32.733Z" - }, - "migrations": [ - { - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmWRihViYAgAzcSVLX27rEFwGWCw5B9Pugy2hRnVLKTChF", - "createdAt": "2021-09-02T07:36:32.733Z" - } - ] - } - }, - "site": { - "context": { - "createdAt": "2021-09-02T12:07:06.098Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/Qmf8k2MPmgB7Ct8xpdKfBtdVY8Zndd5WWnR5WuBpitTFsm" - }, - "migrations": [ - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmajXaGfM7WC88284oRTXjRi44nPdif4V9isAacmdgF9ih" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmajXaGfM7WC88284oRTXjRi44nPdif4V9isAacmdgF9ih" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmajXaGfM7WC88284oRTXjRi44nPdif4V9isAacmdgF9ih" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmajXaGfM7WC88284oRTXjRi44nPdif4V9isAacmdgF9ih" - }, - { - "createdAt": "2021-09-02T12:07:06.098Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmS4JHDDAt4Mwqb1aCyBUZNaXidn4ZigYehxSo4zQz4hSF" - }, - { - "createdAt": "2021-09-02T12:07:06.098Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmS4JHDDAt4Mwqb1aCyBUZNaXidn4ZigYehxSo4zQz4hSF" - } - ] - }, - "snekFinder": { - "context": { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://cloudflare-ipfs.com/ipfs/QmTkHhTvJzYrEPPo2jCdCCEchGXp7LSisBwv81PDwUF1vx" - }, - "migrations": [ - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://ipfs.io/ipfs/QmTkHhTvJzYrEPPo2jCdCCEchGXp7LSisBwv81PDwUF1vx" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://ipfs.io/ipfs/QmTkHhTvJzYrEPPo2jCdCCEchGXp7LSisBwv81PDwUF1vx" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://ipfs.io/ipfs/QmTkHhTvJzYrEPPo2jCdCCEchGXp7LSisBwv81PDwUF1vx" - }, - { - "createdAt": "2021-09-02T07:40:21.196Z", - "fileUrl": "https://ipfs.io/ipfs/QmTkHhTvJzYrEPPo2jCdCCEchGXp7LSisBwv81PDwUF1vx" - } - ] - } -} \ No newline at end of file + "pages": {} +} diff --git a/packages/jaen-pages/gatsby-config.js b/packages/jaen-pages/gatsby-config.js index 94c451fd..ca2184c0 100644 --- a/packages/jaen-pages/gatsby-config.js +++ b/packages/jaen-pages/gatsby-config.js @@ -1,6 +1,8 @@ require('source-map-support').install() require('ts-node').register({compilerOptions: {esModuleInterop: true}}) +require = require('esm')(module) + const {runMigration, getSiteData} = require('./src/tools/publish/run') runMigration() diff --git a/packages/jaen-pages/gatsby-node.js b/packages/jaen-pages/gatsby-node.js index e50b9a2f..b8f3d42b 100644 --- a/packages/jaen-pages/gatsby-node.js +++ b/packages/jaen-pages/gatsby-node.js @@ -14,10 +14,11 @@ exports.createPages = async ({actions, graphql, cache}, pluginOptions) => { const page = await (await fetch(fileUrl)).json() if (page.template) { + console.log('children', page.children, page.parent) actions.createPage({ path: page.path || `${id}/`, - parent: page.parent, - children: page.children, + parent: page.parent ? page.parent.id : null, + children: page.children.map(child => child.id), component: path.resolve(templates[page.template]), context: { jaenPageContext: { @@ -65,9 +66,16 @@ exports.onCreatePage = async ({cache, page, actions}) => { ...page.context, jaenPageContext: { id, + template: '', + slug: '', ...cachedjaenPageContext, pageMetadata: { title: page.internalComponentName, + description: '', + image: '', + canonical: '', + datePublished: new Date().toISOString(), + isBlogPost: false, ...cachedjaenPageContext?.pageMetadata } } diff --git a/packages/jaen-pages/package.json b/packages/jaen-pages/package.json index e6f8469e..4e4509a2 100644 --- a/packages/jaen-pages/package.json +++ b/packages/jaen-pages/package.json @@ -1,6 +1,6 @@ { "name": "@snek-at/jaen-pages", - "version": "2.0.0-beta.10", + "version": "2.0.0-beta.11", "main": "src/index.js", "types": "src/index.ts", "license": "EUPL-1.2", @@ -15,8 +15,8 @@ "@react-icons/all-files": "^4.1.0", "@reduxjs/toolkit": "^1.6.1", "@snek-at/gatsby-plugin-chakra-ui": "1.0.0-beta.4", - "@snek-at/jaen": "^2.0.0-beta.10", - "@snek-at/jaen-shared-ui": "2.0.0-beta.4", + "@snek-at/jaen": "^2.0.0-beta.11", + "@snek-at/jaen-shared-ui": "2.0.0-beta.5", "@snek-at/snek-finder": "^1.0.0-beta.9", "deepmerge": "^4.2.2", "electron": "^14.0.0", diff --git a/packages/jaen-pages/src/containers/fields/TextField/index.tsx b/packages/jaen-pages/src/containers/fields/TextField/index.tsx index ce7e0c0b..27bb253c 100644 --- a/packages/jaen-pages/src/containers/fields/TextField/index.tsx +++ b/packages/jaen-pages/src/containers/fields/TextField/index.tsx @@ -41,7 +41,7 @@ const TextField: React.FC = ({ const updatedValue = (content as TextBlock | undefined)?.text const contextValue = (getFieldContent( - jaenPageContext.fields[fieldName], + jaenPageContext.fields?.[fieldName], block ) as TextBlock | undefined)?.text diff --git a/packages/jaen-pages/src/containers/ui/tabs/PagesTab.tsx b/packages/jaen-pages/src/containers/ui/tabs/PagesTab.tsx index 9441a4ba..a20b0838 100644 --- a/packages/jaen-pages/src/containers/ui/tabs/PagesTab.tsx +++ b/packages/jaen-pages/src/containers/ui/tabs/PagesTab.tsx @@ -81,7 +81,7 @@ const PagesTab: React.FC<{}> = () => { slug: string, template: string ) => { - const pageId = uuidv4() + const pageId = `SitePage /${uuidv4()}` dispatch( actions.addPage({ pageId, @@ -181,6 +181,8 @@ const PagesTab: React.FC<{}> = () => { allSitePage.nodes ]) + console.log('items', items) + return ( <> = ({ for (const node of allSitePage.nodes) { const jaenPageContext = node.context?.jaenPageContext + + console.log('gogogo page', jaenPageContext?.id || node.id) const id = jaenPageContext?.id || node.id site.allSitePage.nodes[id] = { diff --git a/packages/jaen-shared-ui/src/components/molecules/PageTree/treeconverter.ts b/packages/jaen-shared-ui/src/components/molecules/PageTree/treeconverter.ts index 54370a65..487aa72b 100644 --- a/packages/jaen-shared-ui/src/components/molecules/PageTree/treeconverter.ts +++ b/packages/jaen-shared-ui/src/components/molecules/PageTree/treeconverter.ts @@ -62,12 +62,15 @@ export const resolveChildSlugs = ( rootItemIds: string[], id: string | null ): string[] => { + console.log('children', id, rootItemIds) + const children = id ? items[id].children : rootItemIds const childSlugs = [] for (const siblingId of children) { - const slug = items[siblingId].data.slug + console.log(siblingId, items) + const slug = items[siblingId]?.data?.slug if (slug) { childSlugs.push(slug) diff --git a/packages/jaen/package.json b/packages/jaen/package.json index a33d9c2a..11d71610 100644 --- a/packages/jaen/package.json +++ b/packages/jaen/package.json @@ -1,6 +1,6 @@ { "name": "@snek-at/jaen", - "version": "2.0.0-beta.10", + "version": "2.0.0-beta.11", "main": "index.js", "types": "src/index.ts", "license": "EUPL-1.2", @@ -8,7 +8,7 @@ "@chakra-ui/react": "^1.6.7", "@loadable/component": "^5.15.0", "@snek-at/bridge": "^1.0.0", - "@snek-at/jaen-shared-ui": "2.0.0-beta.4", + "@snek-at/jaen-shared-ui": "2.0.0-beta.5", "gatsby-plugin-compile-es6-packages": "^2.1.1", "gatsby-plugin-emotion": "^6.13.0", "react": "^17.0.2"