-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce default home, 404 and error pages (#336)
- Loading branch information
Showing
46 changed files
with
1,079 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
import React from "react"; | ||
import { Helmet } from "react-helmet"; | ||
|
||
export default function GenericErrorPage() { | ||
return ( | ||
<div className="webiny-cms-page"> | ||
<> | ||
<Helmet> | ||
<meta charSet="utf-8" /> | ||
<title>An error occurred.</title> | ||
</Helmet> | ||
<div>An error occurred.</div> | ||
</> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
import React from "react"; | ||
import { Helmet } from "react-helmet"; | ||
|
||
export default function GenericErrorPage() { | ||
return ( | ||
<div> | ||
<> | ||
<Helmet> | ||
<meta charSet="utf-8" /> | ||
<title>Page not found.</title> | ||
</Helmet> | ||
<div>Page not found.</div> | ||
</> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @flow | ||
export { default as GenericErrorPage } from "./GenericErrorPage"; | ||
export { default as GenericNotFoundPage } from "./GenericNotFoundPage"; |
40 changes: 40 additions & 0 deletions
40
packages/webiny-api-cms/src/entities/CmsSettings.entity.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @flow | ||
import { settingsFactory } from "webiny-api/entities"; | ||
|
||
import { Model } from "webiny-model"; | ||
import { EntityModel } from "webiny-entity"; | ||
|
||
const cmsSettingsPagesModelFactory = (settings, { cms: { entities } }) => { | ||
return class CmsSettingsModel extends EntityModel { | ||
constructor() { | ||
super(); | ||
this.setParentEntity(settings); | ||
this.attr("home").entity(entities.Page); | ||
this.attr("notFound").entity(entities.Page); | ||
this.attr("error").entity(entities.Page); | ||
} | ||
}; | ||
}; | ||
|
||
const cmsSettingsModelFactory = (...args) => { | ||
return class CmsSettingsModel extends Model { | ||
constructor() { | ||
super(); | ||
this.attr("pages").model(cmsSettingsPagesModelFactory(...args)); | ||
} | ||
}; | ||
}; | ||
|
||
export const cmsSettingsFactory = (...args) => { | ||
return class CmsSettings extends settingsFactory(...args) { | ||
static key = "cms"; | ||
|
||
data: Object; | ||
load: Function; | ||
|
||
constructor() { | ||
super(); | ||
this.attr("data").model(cmsSettingsModelFactory(this, ...args)); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/webiny-api-cms/src/install/importData/createDefaultPages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// @flow | ||
import { notFound, homepage, error } from "./staticPages"; | ||
|
||
const createDefaultPage = async ({ page, data, category }) => { | ||
page.populate({ ...data, category }); | ||
await page.save(); | ||
|
||
page.published = true; | ||
await page.save(); | ||
|
||
return page; | ||
}; | ||
|
||
const createDefaultPages = async (context: Object, { categories }: Object) => { | ||
const { Page, CmsSettings } = context.cms.entities; | ||
|
||
// Create default pages - demo blog, error, not found and homepage and also assign to settings. | ||
const demoBlogPage = new Page(); | ||
demoBlogPage.populate({ | ||
title: "Demo blog post", | ||
category: categories.blog | ||
}); | ||
await demoBlogPage.save(); | ||
|
||
const cmsSettings = new CmsSettings(); | ||
cmsSettings.data = { | ||
pages: { | ||
home: await createDefaultPage({ | ||
page: new Page(), | ||
data: homepage, | ||
category: categories.static | ||
}), | ||
error: await createDefaultPage({ | ||
page: new Page(), | ||
data: error, | ||
category: categories.static | ||
}), | ||
notFound: await createDefaultPage({ | ||
page: new Page(), | ||
data: notFound, | ||
category: categories.static | ||
}) | ||
} | ||
}; | ||
|
||
await cmsSettings.save(); | ||
}; | ||
|
||
export default createDefaultPages; |
80 changes: 80 additions & 0 deletions
80
packages/webiny-api-cms/src/install/importData/staticPages/error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// @flow | ||
export default { | ||
title: "Error Page", | ||
url: "/error", | ||
content: { | ||
id: "P3NNeXWAk", | ||
data: {}, | ||
settings: {}, | ||
elements: [ | ||
{ | ||
id: "STaGA7c5Jt", | ||
data: {}, | ||
settings: {}, | ||
elements: [ | ||
{ | ||
id: "E0j-dyOuLN", | ||
data: {}, | ||
settings: { style: { margin: "15px", padding: "15px" } }, | ||
elements: [ | ||
{ | ||
id: "iwpwZYraMw", | ||
data: { width: 100 }, | ||
settings: { style: { margin: "20px" } }, | ||
elements: [ | ||
{ | ||
id: "zACl76J1b", | ||
data: { | ||
text: { | ||
object: "value", | ||
document: { | ||
object: "document", | ||
data: {}, | ||
nodes: [ | ||
{ | ||
object: "block", | ||
type: "paragraph", | ||
data: { align: "center" }, | ||
nodes: [ | ||
{ | ||
object: "text", | ||
leaves: [ | ||
{ | ||
object: "leaf", | ||
text: | ||
"Woops, something went wrong! :(", | ||
marks: [] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
settings: { style: { padding: "20px" } }, | ||
elements: [], | ||
path: "0.0.0.0.0", | ||
type: "cms-element-text" | ||
} | ||
], | ||
path: "0.0.0.0", | ||
type: "cms-element-column" | ||
} | ||
], | ||
path: "0.0.0", | ||
type: "cms-element-row" | ||
} | ||
], | ||
path: "0.0", | ||
type: "cms-element-block" | ||
} | ||
], | ||
path: "0", | ||
type: "cms-element-document" | ||
}, | ||
settings: { | ||
general: { layout: "static" } | ||
} | ||
}; |
Oops, something went wrong.