Skip to content

Commit

Permalink
fix: page creaction and esm
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn authored Sep 2, 2021
1 parent 167a76d commit ab3bbda
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 117 deletions.
109 changes: 2 additions & 107 deletions examples/my-gatsby-site/jaen-pages.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
"pages": {}
}
2 changes: 2 additions & 0 deletions packages/jaen-pages/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
12 changes: 10 additions & 2 deletions packages/jaen-pages/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jaen-pages/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const TextField: React.FC<TextFieldProps> = ({
const updatedValue = (content as TextBlock | undefined)?.text

const contextValue = (getFieldContent(
jaenPageContext.fields[fieldName],
jaenPageContext.fields?.[fieldName],
block
) as TextBlock | undefined)?.text

Expand Down
4 changes: 3 additions & 1 deletion packages/jaen-pages/src/containers/ui/tabs/PagesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const PagesTab: React.FC<{}> = () => {
slug: string,
template: string
) => {
const pageId = uuidv4()
const pageId = `SitePage /${uuidv4()}`
dispatch(
actions.addPage({
pageId,
Expand Down Expand Up @@ -181,6 +181,8 @@ const PagesTab: React.FC<{}> = () => {
allSitePage.nodes
])

console.log('items', items)

return (
<>
<PageExplorer
Expand Down
2 changes: 2 additions & 0 deletions packages/jaen-pages/src/contexts/cms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export const CMSProvider: React.FC<CMSProviderType> = ({

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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/jaen/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"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",
"dependencies": {
"@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"
Expand Down

0 comments on commit ab3bbda

Please sign in to comment.