Skip to content

Commit

Permalink
Merge pull request #6 from kuasha420/master
Browse files Browse the repository at this point in the history
InnerContent, Modernize Underlying Libraries and Update Dependencies
  • Loading branch information
u12206050 authored Dec 25, 2020
2 parents e0459c5 + 32ea611 commit 919f7fe
Show file tree
Hide file tree
Showing 72 changed files with 314 additions and 627 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ typings/


# OSX
.DS_Store
.DS_Store

# Generated Builds
dist/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"trailingComma": "none",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"quoteProps": "as-needed",
"semi": false
}
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ Using [LazyBlocks](https://wordpress.org/plugins/lazy-blocks/) to create custom

The frontend can either be a ReactJS App or [Gatsby](https://gatsbyjs.org/) Headless site.


[View Demo](https://gatsby-gutenberg.netlify.com/)


## Prerequisites

In order for this to work we'll need to get the Gutenberg data as JSON from WP via REST.

The following code exposes a new field on posts and pages called `blocks`. It can be added either via a plugin or in your theme's `functions.php` file

```
```php
<?php

add_action(
Expand Down Expand Up @@ -52,12 +50,21 @@ add_action(

### Install

`npm install react-gutenberg --save`
Install react-gutenberg and it's peer dependencies

`yarn add react-gutenberg @loadable/component`

`npm i react-gutenberg @loadable/component`

To include your own custom components: `npm install @loadable/component @types/loadable__component --save`
for consumption in Typescript Project, also add `@types/loadable__component` as a dev dependency

`yarn add -D @types/loadable__component`

`npm i --dev @types/loadable__component`

### ReactJS Example
```

```tsx
import WPGBlocks from 'react-gutenberg'

Expand Down Expand Up @@ -98,15 +105,13 @@ import WPGBlocks from 'react-gutenberg'

### Gatsby Example

```
import * as React from "react"
import { graphql } from "gatsby"
import WPGBlocks from "react-gutenberg"
import { IWPGBlock } from "react-gutenberg/src/types"
```tsx
import * as React from 'react'
import { graphql } from 'gatsby'
import WPGBlocks from 'react-gutenberg'
import { IWPGBlock } from 'react-gutenberg/src/types'

const Loading = () => (
<div class="loading"></div>
)
const Loading = () => <div class="loading"></div>

interface IPost {
wordpress_id: number
Expand All @@ -115,7 +120,7 @@ interface IPost {
blocks: IWPGBlock[]
}

const Post: React.SFC<{data: { post: IPost }}> = ({ data }) => {
const Post: React.FC<{ data: { post: IPost } }> = ({ data }) => {
const { id, title, blocks } = data.post

return (
Expand All @@ -131,18 +136,18 @@ const Post: React.SFC<{data: { post: IPost }}> = ({ data }) => {
export default Post

export const pageQuery = graphql`
fragment WPPost on wordpress__POST{
wordpress_id
id
title
excerpt
fragment WPPost on wordpress__POST {
wordpress_id
id
title
excerpt
slug
type
date
categories {
name
slug
type
date
categories {
name
slug
}
}
}
fragment Blocks on wordpress__POSTBlocks {
Expand Down Expand Up @@ -255,7 +260,6 @@ To do this you should **lazy import** all your custom blocks into one file say `

To support SSR, we use [`loadable`](https://www.smooth-code.com/open-source/loadable-components/docs/getting-started/). Install it: `npm install @loadable/component @types/loadable__component --save`


```
// src/blocks/index.tsx
import loadable from '@loadable/component'
Expand Down Expand Up @@ -284,7 +288,7 @@ Example of a custom component for `core/paragraph` block:
import { IWPGBlock } from 'react-gutenberg/'
import * as React from 'react'
const CustomParagraphBlock:React.SFC<IWPGBlock> = (props) => {
const CustomParagraphBlock:React.FC<IWPGBlock> = (props) => {
const {
attrs,
innerHTML } = props
Expand All @@ -297,8 +301,6 @@ const CustomParagraphBlock:React.SFC<IWPGBlock> = (props) => {
export default CustomParagraphBlock
```



## Why?

For most people it might be fine just taking the raw html from the REST response; `content.rendered`, but I realized that some components I need to make more interactive.
Expand Down
11 changes: 0 additions & 11 deletions dist/blocks/common/audio.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/audio.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/cover.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/cover.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/file.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/file.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/gallery.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/gallery.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/heading.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/heading.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/image.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/image.js.map

This file was deleted.

25 changes: 0 additions & 25 deletions dist/blocks/common/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/index.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/list.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/list.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/paragraph.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/paragraph.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/quote.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/quote.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/common/video.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/common/video.js.map

This file was deleted.

11 changes: 0 additions & 11 deletions dist/blocks/format/code.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/format/code.js.map

This file was deleted.

23 changes: 0 additions & 23 deletions dist/blocks/format/html.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/blocks/format/html.js.map

This file was deleted.

Loading

0 comments on commit 919f7fe

Please sign in to comment.