Skip to content

Instantly share code, notes, and snippets.

@Lane
Last active May 1, 2020 00:05
Show Gist options
  • Save Lane/4b48ebbb701ca3a0a9ebf7dd97e61462 to your computer and use it in GitHub Desktop.
Save Lane/4b48ebbb701ca3a0a9ebf7dd97e61462 to your computer and use it in GitHub Desktop.
sample netlify cms index file
backend:
name: github
repo: EvictionLab/eviction-lab-website
branch: cms-dev
media_folder: "static/uploads" # Folder where user uploaded files should go
publish_mode: editorial_workflow
public_folder: "/uploads" # The src attribute for uploaded media will begin with /images/uploads
collections:
- name: "weekly-reports" # Used in routes, e.g., /admin/collections/blog
identifier_field: "h1"
label: "Weekly Reports" # Used in the UI
folder: "/content/weekly-reports" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
editor:
preview: false
preview_path: weekly-reports/{{slug}}
fields: # The fields for each document, usually in front matter
- {label: "City Name", name: "h1", widget: "string"}
- {label: "Created Date", name: "date", widget: "datetime"}
- {label: "Body", name: "body", widget: "markdown", buttons: ["bold", "italic", "link", "bulleted-list", "numbered-list"]}
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Content Manager</title>
<!-- Include the styles for the Netlify CMS UI, after your own styles -->
<link rel="stylesheet" href="https://unpkg.com/netlify-cms@^2.9.1/dist/cms.css" />
</head>
<body>
<!-- Include the script that builds the page and powers Netlify CMS -->
<script src="https://unpkg.com/netlify-cms@^2.9.1/dist/netlify-cms.js"></script>
<script>
CMS.registerEditorComponent({
id: "test1",
label: "Test Component 1",
fields: [
{
name: 'param1',
label: 'Param One',
widget: 'string',
},
{
name: 'param2',
label: 'Param Two',
widget: 'string',
},
{
name: 'body',
label: 'Section Content',
widget: 'markdown'
}
],
pattern: /{{%[\s]*component_one[\s]*param1="(.*)"[\s]*param2="(.*)"[\s]*%}}([\S\s]*?){{%\/[\s]*component_one[\s]*%}}/,
fromBlock: function(match) {
return {
param1: match[1],
param2: match[2],
body: match[3]
};
},
toBlock: function(obj) {
return '\n\n{{% component_one param1="' + obj.param1 + '" param2="' + obj.param2 + '" %}}\n\n' +
obj.body + '\n\n' +
'{{%/ component_one %}}' + '\n\n';
},
toPreview: function(obj) {
return obj.body;
}
});
CMS.registerEditorComponent({
id: "test2",
label: "Test Component 2",
fields: [
{
name: 'param1',
label: 'Param One',
widget: 'string',
},
{
name: 'param2',
label: 'Param Two',
widget: 'string',
},
{
name: 'body',
label: 'Section Content',
widget: 'markdown'
}
],
pattern: /{{%[\s]*component_two[\s]*param1="(.*)"[\s]*param2="(.*)"[\s]*%}}([\S\s]*?){{%\/[\s]*component_two[\s]*%}}/,
fromBlock: function(match) {
return {
param1: match[1],
param2: match[2],
body: match[3]
};
},
toBlock: function(obj) {
return '\n\n{{% component_two param1="' + obj.param1 + '" param2="' + obj.param2 + '" %}}\n\n' +
obj.body + '\n\n' +
'{{%/ component_two %}}' + '\n\n';
},
toPreview: function(obj) {
return obj.body;
}
});
</script>
</body>
</html>

{{% component_one param1="first_component_param1" param2="first_component_param2" %}}

This is my body

  1. a list of items
  2. is in here

{{%/ component_one %}}

{{% component_two param1="second_component_param1" param2="second_component_param2" %}}

Another section

  1. another list
  2. of items

{{%/ component_two %}}

{{% component_one param1="first_component_param1" param2="first_component_param2" %}}

This is my body

  1. a list of items
  2. is in here

{{%/ component_one %}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment