Skip to content

Commit

Permalink
Enfoce lowercase on destination countries except first letter of each…
Browse files Browse the repository at this point in the history
… word
  • Loading branch information
blgo committed Jun 10, 2018
1 parent f6db307 commit 521c8a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
21 changes: 12 additions & 9 deletions site/static/admin/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
backend:
name: git-gateway
branch: master
# name: github
# repo: blgo/test
# branch: master

publish_mode: editorial_workflow
media_folder: "site/static/img/"
Expand All @@ -15,9 +18,9 @@ collections: # A list of collections the CMS should be able to edit
value: en
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string", tagname: "h1"}
- {label: "Description", name: "description", widget: "string", tagname: "h1", required: false}
- {label: "Country of destination", name: "destinations", widget: "string" , required: true}
- {label: "Title", name: "title", widget: "string", required: true}
- {label: "Description", name: "description", widget: "string", required: false}
- {label: "Country of destination", name: "destinations", widget: "capitalisefirst" , required: true}
- {label: "Heading - Image filename", name: "featured", widget: "string", required: false}
- {label: "Images provider", name: "featuredpath", widget: "hidden", default: "cloudinary" }
- {label: "Body", name: "body", widget: "markdown", required: false}
Expand All @@ -37,9 +40,9 @@ collections: # A list of collections the CMS should be able to edit
extension: "pl.md"
format: "frontmatter"
fields: # The fields each document in this collection have
- {label: "Title", name: "title", widget: "string", tagname: "h1"}
- {label: "Description", name: "description", widget: "string", tagname: "h1", required: false}
- {label: "Country of destination", name: "destinations", widget: "string" , required: true}
- {label: "Title", name: "title", widget: "string", required: true}
- {label: "Description", name: "description", widget: "string", required: false}
- {label: "Country of destination", name: "destinations", widget: "capitalisefirst" , required: true}
- {label: "Heading - Image filename", name: "featured", widget: "string", required: false}
- {label: "Images provider", name: "featuredpath", widget: "hidden", default: "cloudinary" }
- {label: "Body", name: "body", widget: "markdown", required: false}
Expand All @@ -48,19 +51,19 @@ collections: # A list of collections the CMS should be able to edit
- {label: "author", name: "author", widget: "hidden", default: "Kitty R."}
- {label: "featured path", name: "featuredpath", widget: "hidden", default: "cloudinary"}
- {label: "featured alt", name: "featuredalt", widget: "hidden", default: "Image hosted by Cloudinary"}
- {label: "Language", name: "language", widget: "hidden", default: "pl"}
- {label: "Language", name: "language", widget: "hidden", default: "en"}
- label: "About Pages"
name: "pages"
files:
- name: "enabout"
- name: "enabout"
label: "English About page"
file: "site/content/about/_index.md"
description: "About page in English"
fields:
- {label: "Title", name: "title", widget: "string", tagname: "h1"}
- {label: "Body", name: "body", widget: "markdown", required: false}
- {label: "Publish Date", name: "date", widget: "datetime"}
- name: "plabout"
- name: "plabout"
label: "Polish About page"
file: "site/content/about/_index.pl.md"
description: "About page in Polish"
Expand Down
46 changes: 45 additions & 1 deletion site/static/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<body>
<script src="https://unpkg.com/netlify-cms@^1.3.1/dist/cms.js"></script>
<script>

// Clousinary support for embedded images editor widget

CMS.registerEditorComponent({
id: "facybox",
label: "Cloudinary Fancybox",
Expand All @@ -32,7 +35,10 @@
'<img src="https://res.cloudinary.com/dkdpqgjhi/image/upload/c_scale,w_600/' + obj.public_id + '" alt="The link to the image is broken, check the filename"/> <div> ' + obj.caption + ' </div>'
);
}
});
});

// Youtube editor widget

CMS.registerEditorComponent({
id: "youtube",
label: "Youtube",
Expand All @@ -52,6 +58,44 @@
);
}
});

// Custom Widget collection to capitalise first letter of the word

// Takes each word and makes the first letter upper case, the rest are made lower case
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}

var CapitaliseFirstOnly = createClass({
handleChange: function(e) {
this.props.onChange(toTitleCase(e.target.value));
},

render: function() {
var value = this.props.value;
var id = this.props.forID;
var classgroup = this.props.classNameWrapper;
return h('input', {
type: 'text',
value : value,
class: classgroup,
id: id,
onChange: this.handleChange,
name: name
});
}
});

var CapitalisePreview = createClass({
render: function() {
return h('h1',{className: "nc-widgetPreview"}, this.props.value);
}
});

CMS.registerWidget('capitalisefirst', CapitaliseFirstOnly, CapitalisePreview);

</script>
</body>
</html>

0 comments on commit 521c8a9

Please sign in to comment.