netlify-cms-react-starter/cms/cms.js
Eric Jinks 7b4780c581
0.4.0 (#20)
* Improve reusability of Meta component

* Rename page prop to fields on pages / posts

* Update config.yml with meta object for each item
2018-06-06 14:36:47 +10:00

57 lines
1.7 KiB
JavaScript

import React from 'react'
import '../src/globalStyles.css'
import data from '../src/data.json'
import Home from '../src/views/Home'
import About from '../src/views/About'
import Contact from '../src/views/Contact'
import Blog from '../src/views/Blog'
import SinglePost from '../src/views/SinglePost'
console.log('React version', React.version)
const CMS = window.CMS
CMS.registerPreviewStyle(
'https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css'
)
CMS.registerPreviewStyle('/admin/cms.bundle.css')
const getDocument = (collection, name) =>
data[collection] && data[collection].filter(page => page.name === name)[0]
const getDocuments = (collection, name) => data[collection]
const globalSettings = getDocument('settings', 'global')
const posts = getDocuments('posts')
// Preview Templates
CMS.registerPreviewTemplate('home-page', ({ entry }) => (
<Home fields={entry.toJS().data} />
))
CMS.registerPreviewTemplate('about-page', ({ entry }) => (
<About fields={entry.toJS().data} />
))
CMS.registerPreviewTemplate('contact-page', ({ entry }) => (
<Contact fields={entry.toJS().data} siteTitle={globalSettings.siteTitle} />
))
CMS.registerPreviewTemplate('blog-page', ({ entry }) => (
<Blog fields={entry.toJS().data} posts={posts} />
))
CMS.registerPreviewTemplate('posts', ({ entry }) => (
<SinglePost fields={entry.toJS().data} />
))
// Return to home when user logging out
window.netlifyIdentity.on('logout', function () {
document.location.href = '/'
})
// Log netlifySiteURL if editing on localhost
if (
window.location.hostname === 'localhost' &&
window.localStorage.getItem('netlifySiteURL')
) {
console.log(
`%cnetlifySiteURL: ${window.localStorage.getItem('netlifySiteURL')}`,
'color: hotpink; font-size: 15px'
)
}