docs: Update Docs: Guides “hugo” (#3863)

This commit is contained in:
SHARAD RAJ 2020-06-07 18:34:06 +05:30 committed by GitHub
parent 2b7a3c38d4
commit 2114fe1857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View File

@ -198,4 +198,49 @@ Create a file `layouts/blog/single.html`, and put the following content in there
</html>
```
You can see this basic template includes all the fields you've specified in your Netlify CMS `config.yml` file. You can access any custom front-matter fields with `.Params.<field-name>`!
You can see this basic template includes all the fields you've specified in your Netlify CMS `config.yml` file. You can access any custom front-matter fields with `.Params.<field-name>`!
### Using Hugo shortcodes in the Markdown Editor
Using `registerEditorComponent` we can register a block level component for the Markdown editor. You can use it to add Hugo's inbuilt shortcodes like `gist`,`youtube` and others as block components to the markdown editor.
You can refer to [registering editor components](https://www.netlifycms.org/docs/custom-widgets/#registereditorcomponent) for a getting started guide or for creating your own editor components.
**Example**
```javascript
CMS.registerEditorComponent({
id: "gist",
label: "Gist",
fields: [{
name: "username",
label: "Github Username",
widget: "string"
},
{
name: "gid",
label: "Gist ID",
widget: "string"
},
],
pattern: /{{< gist ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) >}}/,
fromBlock: function(match) {
return {
username: match[1],
gid: match[2],
};
},
toBlock: function(obj) {
return `{{< gist ${obj.username} ${obj.gid} >}}`;
},
toPreview: function(obj) {
return `{{< gist ${obj.username} ${obj.gid} >}}`;
},
});
```
**Result**
![Gist](/img/hugo_shortcode_gist.png "Gist")
For getting started quickly you can refer to this amazing prebuilt resource of [hugo shortcodes editor components](https://github.com/sharadcodes/hugo-shortcodes-netlify-cms)!

View File

@ -11,7 +11,7 @@ site_url: https://www.netlifycms.org
publish_mode: editorial_workflow
media_folder: website/static/img
public_folder: img
public_folder: /img
docs_collection: &docs_collection
folder: website/content/docs

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB