1.1.72 • Published 2 years ago

react-netlifycms v1.1.72

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React NetlifyCMS with Identity Widget

yarn add react-netlifycms

collections.ts

import { CmsCollection } from 'react-netlifycms';
import { TinyMCEField } from './widgets/TinyMCEWidget';

export const collections: CmsCollection[] = [
  {
    name: 'post',
    label: 'Post',
    folder: 'blog',
    create: true,
    fields: [
      { label: 'Published', name: 'published', widget: 'boolean' },
      { label: 'Title', name: 'title', widget: 'string' },
      { label: 'Publish Date', name: 'date', widget: 'datetime' },
      { label: 'Body', name: 'body', widget: 'editor' } as TinyMCEField,
      { label: 'Authors', name: 'authors', widget: 'list' },
    ],
  },
]

Page (admin.tsx)

import React from 'react';
import dynamic from 'next/dynamic';
import { collections } from '../admin/collections'
import { PostPreview } from '../admin/previews/PostPreview'
import { TinyMCEWidget } from '../admin/widgets/TinyMCEWidget';

const NetlifyCMS = dynamic(() => import('react-netlifycms'), {
  ssr: false,
});

export default function AdminPage() {
  return (
    <NetlifyCMS
      cms={{
        backend: {
          name: 'git-gateway',
          branch: 'master',
        },
        media_folder: 'public/uploads',
        public_folder: '/uploads',
        collections,
        local_backend: process.env.NODE_ENV !== 'production',
        load_config_file: false,

        onLoad: (cms) => {
          cms.registerPreviewTemplate('post', PostPreview);
          cms.registerWidget('editor', TinyMCEWidget);
        },
      }}
    />
  );
}

Custom Preview (PostPreview.tsx)

import React from 'react';
import { Preview } from 'react-netlifycms';
import { PostTemplate } from '~/components/templates/Post';

interface Post {
  published:boolean;
  title: string;
  date: Date;
  body: string;
  authors: string[];
}

export const PostPreview = Preview<Post>(post) => {
  return <PostTemplate post={post} />;
};

Custom Widget

import React from 'react';
import { Editor, IAllProps } from '@tinymce/tinymce-react';
import { Widget, WidgetParams } from 'react-netlifycms';

type TinyMCEWidgetProps = IAllProps['init'] & {
  apiKey?: string;
};

export const TinyMCEWidget = Widget<string, TinyMCEWidgetProps>(
  ({ onChange, value, params: { apiKey, ...init } }) => {
    return (
      <Editor
        apiKey={apiKey}
        value={value}
        init={init}
        onEditorChange={(content) => onChange(content)}
      />
    );
  }
);

export type TinyCmsField = WidgetParams<TinyMCEWidgetProps, 'editor'>;

Access admin in dev mode

yarn add -D concurrently netlify-cms-proxy-server

edit dev script in package.json

{
  "scripts": {
    "dev": "concurrently \"next dev\" \"netlify-cms-proxy-server\""
  }
}

run

yarn dev
1.1.70

2 years ago

1.1.72

2 years ago

1.1.71

2 years ago

1.1.69

2 years ago

1.1.68

2 years ago

1.1.52

2 years ago

1.1.56

2 years ago

1.1.55

2 years ago

1.1.54

2 years ago

1.1.53

2 years ago

1.1.59

2 years ago

1.1.58

2 years ago

1.1.57

2 years ago

1.1.63

2 years ago

1.1.62

2 years ago

1.1.61

2 years ago

1.1.60

2 years ago

1.1.67

2 years ago

1.1.66

2 years ago

1.1.65

2 years ago

1.1.64

2 years ago

1.1.51

2 years ago

1.1.50

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.38

2 years ago

1.1.37

2 years ago

1.1.36

2 years ago

1.1.35

2 years ago

1.1.39

2 years ago

1.1.41

2 years ago

1.1.40

2 years ago

1.1.45

2 years ago

1.1.44

2 years ago

1.1.43

2 years ago

1.1.42

2 years ago

1.1.49

2 years ago

1.1.48

2 years ago

1.1.47

2 years ago

1.1.46

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.30

2 years ago

1.1.31

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.23

3 years ago

1.1.22

3 years ago

1.1.24

3 years ago

1.1.19

3 years ago

1.1.21

3 years ago

1.1.20

3 years ago

1.1.9

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.18

3 years ago

1.1.17

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.0.4

3 years ago

1.1.2

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago