mirror of
https://github.com/kingomarnajjar/gatsby-starter-netlify-cms.git
synced 2026-07-25 22:27:24 +10:00
split backend modules into their own files
This commit is contained in:
parent
0db0bde647
commit
9755306f07
5 changed files with 81 additions and 64 deletions
10
cms/cms.js
Normal file
10
cms/cms.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import CMS from 'netlify-cms';
|
||||
|
||||
import AboutPagePreview from './components/AboutPagePreview';
|
||||
import BlogPostPreview from './components/BlogPostPreview';
|
||||
import ProductPagePreview from './components/ProductPagePreview';
|
||||
|
||||
CMS.registerPreviewStyle('/styles.css');
|
||||
CMS.registerPreviewTemplate('about', AboutPagePreview);
|
||||
CMS.registerPreviewTemplate('products', ProductPagePreview);
|
||||
CMS.registerPreviewTemplate('blog', BlogPostPreview);
|
||||
64
cms/cms.jsx
64
cms/cms.jsx
|
|
@ -1,64 +0,0 @@
|
|||
import React from 'react';
|
||||
import CMS from 'netlify-cms';
|
||||
|
||||
import { AboutPageTemplate } from '../src/templates/about-page';
|
||||
import { ProductPageTemplate } from '../src/templates/product-page';
|
||||
import { BlogPostTemplate } from '../src/templates/blog-post';
|
||||
|
||||
const AboutPagePreview = ({ entry, widgetFor }) =>
|
||||
<AboutPageTemplate title={entry.getIn(['data', 'title'])} content={widgetFor('body')} />;
|
||||
|
||||
const BlogPostPreview = ({ entry, widgetFor }) => (
|
||||
<BlogPostTemplate
|
||||
content={widgetFor('body')}
|
||||
description={entry.getIn(['data', 'description'])}
|
||||
title={entry.getIn(['data', 'title'])}
|
||||
/>
|
||||
);
|
||||
|
||||
const ProductPagePreview = ({ entry, getAsset }) => {
|
||||
const entryBlurbs = entry.getIn(['data', 'intro', 'blurbs']);
|
||||
const blurbs = entryBlurbs ? entryBlurbs.toJS() : [];
|
||||
|
||||
const entryTestimonials = entry.getIn(['data', 'testimonials']);
|
||||
const testimonials = entryTestimonials ? entryTestimonials.toJS() : [];
|
||||
|
||||
const entryPricingPlans = entry.getIn(['data', 'pricing', 'plans']);
|
||||
const pricingPlans = entryPricingPlans ? entryPricingPlans.toJS() : [];
|
||||
|
||||
return (<ProductPageTemplate
|
||||
image={entry.getIn(['data', 'image'])}
|
||||
title={entry.getIn(['data', 'title'])}
|
||||
heading={entry.getIn(['data', 'heading'])}
|
||||
description={entry.getIn(['data', 'description'])}
|
||||
intro={{ blurbs }}
|
||||
main={{
|
||||
heading: entry.getIn(['data', 'main', 'heading']),
|
||||
description: entry.getIn(['data', 'main', 'description']),
|
||||
image1: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image1', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image1', 'alt']),
|
||||
},
|
||||
image2: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image2', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image2', 'alt']),
|
||||
},
|
||||
image3: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image3', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image3', 'alt']),
|
||||
},
|
||||
}}
|
||||
fullImage={entry.getIn(['data', 'full_image'])}
|
||||
testimonials={testimonials}
|
||||
pricing={{
|
||||
heading: entry.getIn(['data', 'pricing', 'heading']),
|
||||
description: entry.getIn(['data', 'pricing', 'description']),
|
||||
plans: pricingPlans,
|
||||
}}
|
||||
/>);
|
||||
};
|
||||
|
||||
CMS.registerPreviewStyle('/styles.css');
|
||||
CMS.registerPreviewTemplate('about', AboutPagePreview);
|
||||
CMS.registerPreviewTemplate('products', ProductPagePreview);
|
||||
CMS.registerPreviewTemplate('blog', BlogPostPreview);
|
||||
9
cms/components/AboutPagePreview.jsx
Normal file
9
cms/components/AboutPagePreview.jsx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react';
|
||||
|
||||
import { AboutPageTemplate } from '../../src/templates/about-page';
|
||||
|
||||
const AboutPagePreview = ({ entry, widgetFor }) => (
|
||||
<AboutPageTemplate title={entry.getIn(['data', 'title'])} content={widgetFor('body')} />
|
||||
);
|
||||
|
||||
export default AboutPagePreview;
|
||||
13
cms/components/BlogPostPreview.jsx
Normal file
13
cms/components/BlogPostPreview.jsx
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import React from 'react';
|
||||
|
||||
import { BlogPostTemplate } from '../../src/templates/blog-post';
|
||||
|
||||
const BlogPostPreview = ({ entry, widgetFor }) => (
|
||||
<BlogPostTemplate
|
||||
content={widgetFor('body')}
|
||||
description={entry.getIn(['data', 'description'])}
|
||||
title={entry.getIn(['data', 'title'])}
|
||||
/>
|
||||
);
|
||||
|
||||
export default BlogPostPreview;
|
||||
49
cms/components/ProductPagePreview.jsx
Normal file
49
cms/components/ProductPagePreview.jsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import React from 'react';
|
||||
|
||||
import { ProductPageTemplate } from '../../src/templates/product-page';
|
||||
|
||||
const ProductPagePreview = ({ entry, getAsset }) => {
|
||||
const entryBlurbs = entry.getIn(['data', 'intro', 'blurbs']);
|
||||
const blurbs = entryBlurbs ? entryBlurbs.toJS() : [];
|
||||
|
||||
const entryTestimonials = entry.getIn(['data', 'testimonials']);
|
||||
const testimonials = entryTestimonials ? entryTestimonials.toJS() : [];
|
||||
|
||||
const entryPricingPlans = entry.getIn(['data', 'pricing', 'plans']);
|
||||
const pricingPlans = entryPricingPlans ? entryPricingPlans.toJS() : [];
|
||||
|
||||
return (
|
||||
<ProductPageTemplate
|
||||
image={entry.getIn(['data', 'image'])}
|
||||
title={entry.getIn(['data', 'title'])}
|
||||
heading={entry.getIn(['data', 'heading'])}
|
||||
description={entry.getIn(['data', 'description'])}
|
||||
intro={{ blurbs }}
|
||||
main={{
|
||||
heading: entry.getIn(['data', 'main', 'heading']),
|
||||
description: entry.getIn(['data', 'main', 'description']),
|
||||
image1: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image1', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image1', 'alt']),
|
||||
},
|
||||
image2: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image2', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image2', 'alt']),
|
||||
},
|
||||
image3: {
|
||||
image: getAsset(entry.getIn(['data', 'main', 'image3', 'image'])),
|
||||
alt: entry.getIn(['data', 'main', 'image3', 'alt']),
|
||||
},
|
||||
}}
|
||||
fullImage={entry.getIn(['data', 'full_image'])}
|
||||
testimonials={testimonials}
|
||||
pricing={{
|
||||
heading: entry.getIn(['data', 'pricing', 'heading']),
|
||||
description: entry.getIn(['data', 'pricing', 'description']),
|
||||
plans: pricingPlans,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProductPagePreview;
|
||||
Loading…
Add table
Reference in a new issue