© Joe Attardi 2020
J. AttardiUsing Gatsby and Netlify CMShttps://doi.org/10.1007/978-1-4842-6297-9_13

13. The Editorial Workflow

Joe Attardi1 
(1)
Billerica, MA, USA
 

Authoring content in Netlify CMS is fairly straightforward. When you publish your changes, they are immediately committed to the repository’s master branch and deployed to the live site. This is fine for small, individually owned sites, but for larger sites, this may not be ideal. There is no approval process for new content; it goes live immediately.

For such sites wanting better editorial control, Netlify CMS supports what is called the editorial workflow . With the editorial workflow, content is saved as a draft. Another user can review the content and approve the changes, at which point it will go live.

Note

At the time of writing, the editorial workflow is only officially supported for GitHub repositories. Support for GitLab and Bitbucket repositories is currently in a beta testing phase.

Enabling the editorial workflow

The editorial workflow is enabled by making a small change to the CMS configuration file. Open the file static/admin/config.yml and make the changes indicated in Listing 13-1.
backend:
  name: git-gateway
  branch: master
media_folder: static/img
public_folder: /img
publish_mode: editorial_workflow
collections:
  - name: "blog"
    label: "Blog"
    folder: "src/blog"
    create: true
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
    fields:
      - name: "contentKey"
        widget: "hidden"
        default: "blog"
      - label: "Title"
        name: "title"
        widget: "string"
      - label: "Publish Date"
        name: "date"
        widget: "datetime"
      - label: "Body"
        name: "body"
        widget: "markdown"
  - name: "pages"
    label: "Pages"
    files:
      - file: "src/pageData/index.md"
        label: "Index Page"
        name: "index-page"
        fields:
          - name: "contentKey"
            widget: "hidden"
            default: "indexPage"
          - label: "Tagline"
            name: "tagline"
            widget: "string"
          - label: "Hero Image"
            name: "heroImage"
            widget: "image"
      - file: "src/pageData/menu.md"
        label: "Menu"
        name: "menu"
        fields:
          - name: "contentKey"
            widget: "hidden"
            default: "menu"
          - label: "Title"
            name: "title"
            widget: "string"
          - label: "Categories"
            label_singular: "Category"
            name: "categories"
            widget: "list"
            fields:
              - label: "Name"
                name: "name"
                widget: "string"
              - label: "Items"
                label_singular: "Item"
                name: "items"
                widget: "list"
                fields:
                  - label: "Name"
                    name: "name"
                    widget: "string"
                  - label: "Description"
                    name: "description"
                    widget: "text"
                  - label: "Price"
                    name: "price"
                    widget: "string"
Listing 13-1

Enabling the editorial workflow

Adding some new content

To start the editorial workflow, let’s first add some new content. Start the development server by running gatsby develop, then open the CMS at http://localhost:8000/admin.

We’ll add a new category and product to the menu. Go to “Pages,” then click “Menu” to open the coffee shop menu. From the menu page, click “Add category.”

For the name, enter “Bakery”. Next, under “Items,” click “Add item.” Enter the following details:
  • Name: Blueberry Muffin

  • Description: Made with farm fresh blueberries

  • Price: $3.99

In the upper right corner, you might notice that this time, the “Published” button did not change to “Publish.” Instead, there’s a new “Save” button at the top of the page, as shown in Figure 13-1.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig1_HTML.jpg
Figure 13-1

The editor showing the “Save” button

To save the new changes, click this “Save” button. We have now triggered the editorial workflow. There are a few new buttons at the top of the page now, shown in Figure 13-2.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig2_HTML.jpg
Figure 13-2

The new buttons in the CMS

Let’s take a look at what happened behind the scenes.

Viewing the pull request

When this draft change was saved, a new branch was created in the Git repository, the changes were saved to that branch, then a pull request was opened for that branch against the master branch.

A pull request is a request to merge, or pull, a set of changes from one branch into another. The changes can be viewed in the GitHub web interface, and code review comments can be left. Open your browser, and go to your coffee-shop repository on GitHub – https://github.com/<your-username>/coffee-shop.

If you look at the tabs at the top of the repository page, you’ll see that there is one pull request. Click the “Pull requests” tab to view the open pull requests screen. You should see a pull request for the changes we just made, as shown in Figure 13-3.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig3_HTML.jpg
Figure 13-3

The pull requests tab, showing our open pull request

Click the title of the pull request to open it. You’ll see some more detailed information about the pull request, as shown in Figure 13-4.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig4_HTML.jpg
Figure 13-4

The pull request details

If you click the “Files changed” tab, you will see a view showing the differences between the master branch and our draft changes, as shown in Figure 13-5.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig5_HTML.jpg
Figure 13-5

The “Files changed” tab of the pull request

In this view, we can see the new menu category that we added and the single item we added as well.

Back on the “Conversation” tab, you will see that the pull request currently has a netlify-cms/draft label applied to it. This means the changes are still in draft status. You can make further changes in the CMS user interface, and when they are saved, they will be added to this pull request .

Viewing the preview

One of the nice things about the editorial workflow is that it publishes a preview version of the site containing your changes so that you can see them in a live version of the site before the site is published. In your browser, return to the CMS application and go to the menu page. At the top of the screen, you will see a link that says, “Check for Preview.”

Click that link, and after a moment, it will be replaced with another link that says, “View Preview.” Click the “View Preview” link. A new browser tab will open showing the coffee shop site. If you look at the URL, though, it will be different. Instead of https://<your-site-name>.netlify.app, it will be something like https://deploy-preview-1--<your-site-name>.netlify.app. The preview is deployed to a separate URL so that it can be viewed without updating the main live site.

From this preview, click “Menu” in the navigation menu at the top right. You will be taken to the menu page which will include the new Bakery category that we added, as shown in Figure 13-6.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig6_HTML.jpg
Figure 13-6

The menu page in the preview site

Updating the status

Let’s go back to the CMS. At the top of the screen is also a button labeled “Set status.” Click that button, and you will be presented with a dropdown menu of different status options. As we saw when viewing the pull request, this change is currently in “Draft” status. The menu is shown in Figure 13-7.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig7_HTML.jpg
Figure 13-7

The status options

Next, click “In review” to update the status. If you return to the pull request on GitHub, you’ll see that the label now reads netlify-cms/pending_review. We can view the changes and add review comments. Click the “Files changed” tab again, where you will see the difference view.

If you hover over a line of text in this view, you will see a blue button with a plus sign appear, as shown in Figure 13-8.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig8_HTML.jpg
Figure 13-8

The blue plus button

If you click that button, you will be presented with a form where you can add a comment for that line. Enter some text, then click the green “Start a review” button, as shown in Figure 13-9.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig9_HTML.jpg
Figure 13-9

Adding a comment

At the top of the page, you will see a new green button labeled “Finish your review.” Click that, and you will see a form for finishing the review, as shown in Figure 13-10. There is a radio button labeled “Approve,” but we are unable to click it because a pull request author cannot approve their own pull request. In a normal situation, another member of the team would view and approve this pull request.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig10_HTML.jpg
Figure 13-10

Finishing a review. We cannot approve our own pull request

Finishing up

Let’s imagine another member of our team has approved the pull request. Go back to the CMS, open the menu page, and change the status to “Ready.”
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig11_HTML.jpg
Figure 13-11

Setting the status to “Ready”

If you go back to the pull request, you will see again that it has a new label: netlify-cms/pending_publish. This means that all changes have been approved and it is ready to be published. We can do that now by going back to the CMS and clicking “Publish,” then “Publish now,” as we normally would.

You may be asked to confirm that you want to publish this entry. Click “OK” to continue with publishing. The status in the top right of the page will change to “Published” after a short delay.

Go back to the pull request one more time. You will see that it is now in a “Merged” state and the branch has automatically been deleted, as shown in Figure 13-12.
../images/502348_1_En_13_Chapter/502348_1_En_13_Fig12_HTML.jpg
Figure 13-12

The now-closed pull request

Summary

The editorial workflow allows greater control over the publishing of content. It provides an opportunity for changes to be reviewed by peers before it is published to the live site. The process goes as follows:
  • The author makes the desired changes and saves them.

  • The changes are saved to a temporary branch in the Git repository.

  • A pull request is opened, and the changes are in the “Draft” status.

  • A live preview of the changes is deployed on a subdomain of the site on Netlify.

  • Once all changes have been made, the changes are set to “In review” status.

  • Other team members can go to the pull request on GitHub and add their comments, request changes, or approve the changes as is.

  • The changes are set to “Ready” status.

  • The changes are published.

  • The pull request is merged, and the temporary branch is deleted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.60