feat: add instruction for authenticating Netlify CMS users (#5318)

This commit is contained in:
Trang Le 2021-05-04 15:50:16 +07:00 committed by GitHub
parent 92d8c50272
commit 5aec9dd308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ group: Guides
weight: 30
title: Jekyll
---
## Introduction
This section will help you integrate Netlify CMS with a new or existing Jekyll project.
@ -58,9 +59,11 @@ collections:
- { name: Title }
```
### Setup Backend
### Enable authentication for CMS users
Follow the directions in the docs [to enable Identity and Git Gateway](https://www.netlifycms.org/docs/add-to-your-site/#enable-identity-and-git-gateway) then add the [Identity Widget](https://www.netlifycms.org/docs/add-to-your-site/#add-the-netlify-identity-widget)
Netlify CMS stores content in your online Git repository. Therefore, to make content changes, users need to authenticate with the corresponding Git provider to prove that they have read and write access to that content.
Follow the directions in the Introduction section to [enable Netlify Identity and Git Gateway services](https://www.netlifycms.org/docs/add-to-your-site/#enable-identity-and-git-gateway) for the backend, then [add the Identity widget](https://www.netlifycms.org/docs/add-to-your-site/#add-the-netlify-identity-widget) to render a login portal on the frontend.
## CMS Configuration
@ -86,14 +89,14 @@ collections:
A few things to note.
* We set the `slug` to `'{{year}}-{{month}}-{{day}}-{{slug}}'` because [Jekyll requires this format for blog posts](https://jekyllrb.com/docs/posts/#creating-posts). `year`, `month`, and `day` will be extracted from the `date` field, and `slug` will be generated from the `title` field.
* We added `editor` configuration with a field `preview: false`. This will eliminate the preview pane. Because Jekyll uses Liquid templates, there currently isn't a good way to provide a preview of pages as you update the content.
* The `layout` field default is set to `post` so Jekyll knows to use `_layouts/post.html` when it renders a post. This field is hidden because we want all posts to use the same layout.
* The `date` and `title` field will be used by the `slug` - as noted above, Jekyll relies on the filename to determine a post's publish date, but Netlify CMS does not pull date information from the filename and requires a frontmatter `date` field. **Note** Changing the `date` or `title` fields in Netlify CMS will not update the filename. This has a few implications:
- We set the `slug` to `'{{year}}-{{month}}-{{day}}-{{slug}}'` because [Jekyll requires this format for blog posts](https://jekyllrb.com/docs/posts/#creating-posts). `year`, `month`, and `day` will be extracted from the `date` field, and `slug` will be generated from the `title` field.
- We added `editor` configuration with a field `preview: false`. This will eliminate the preview pane. Because Jekyll uses Liquid templates, there currently isn't a good way to provide a preview of pages as you update the content.
- The `layout` field default is set to `post` so Jekyll knows to use `_layouts/post.html` when it renders a post. This field is hidden because we want all posts to use the same layout.
- The `date` and `title` field will be used by the `slug` - as noted above, Jekyll relies on the filename to determine a post's publish date, but Netlify CMS does not pull date information from the filename and requires a frontmatter `date` field. **Note** Changing the `date` or `title` fields in Netlify CMS will not update the filename. This has a few implications:
* If you change the `date` or `title` fields in Netlify CMS, Jekyll won't notice
* You don't necessarily need to change the `date` and `title` fields for existing posts, but if you don't the filenames and frontmatter will disagree in a way that might be confusing
* If you want to avoid these issues, use a regular Jekyll collection instead of the special `_posts` directory
- If you change the `date` or `title` fields in Netlify CMS, Jekyll won't notice
- You don't necessarily need to change the `date` and `title` fields for existing posts, but if you don't the filenames and frontmatter will disagree in a way that might be confusing
- If you want to avoid these issues, use a regular Jekyll collection instead of the special `_posts` directory
### Author Collection
@ -126,8 +129,8 @@ then update `_layouts/author.html`, `_layouts/post.html` and `staff.html` accord
<h2>Posts</h2>
<ul>
{% assign filtered_posts = site.posts | where: 'author', page.name %} {% for
post in filtered_posts %}
{% assign filtered_posts = site.posts | where: 'author', page.name %} {% for post in
filtered_posts %}
<li>
<a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
</li>
@ -142,10 +145,8 @@ then update `_layouts/author.html`, `_layouts/post.html` and `staff.html` accord
<h1>{{ page.title }}</h1>
<p>
{{ page.date | date_to_string }}
{% assign author = site.authors | where: 'name', page.author | first %}
{% if author %}
- <a href="{{ author.url }}">{{ author.display_name }}</a>
{{ page.date | date_to_string }} {% assign author = site.authors | where: 'name', page.author |
first %} {% if author %} - <a href="{{ author.url }}">{{ author.display_name }}</a>
{% endif %}
</p>
@ -277,21 +278,21 @@ You'll need to update `_includes/navigation.html` accordingly. `{% for item in s
Finally, add the following to the collections array in `config.yml`
```yaml
- name: "config"
label: "Config"
- name: 'config'
label: 'Config'
editor:
preview: false
files:
- label: "Navigation"
name: "navigation"
file: "_data/navigation.yml"
- label: 'Navigation'
name: 'navigation'
file: '_data/navigation.yml'
fields:
- label: "Navigation Items"
name: "items"
widget: "list"
- label: 'Navigation Items'
name: 'items'
widget: 'list'
fields:
- {label: Name, name: name, widget: string}
- {label: Link, name: link, widget: string}
- { label: Name, name: name, widget: string }
- { label: Link, name: link, widget: string }
```
Now you can add, rename, and rearrange the navigation items on your blog.