Created
June 5, 2018 16:16
-
-
Save mipmip/4c477fdf12eb50a858e2df243a4ee576 to your computer and use it in GitHub Desktop.
Custom publish button inside Netlify CMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<link href="https://unpkg.com/netlify-cms/dist/cms.css" rel="stylesheet"/> | |
</head> | |
<body> | |
<script src="https://unpkg.com/netlify-cms/dist/cms.js"></script> | |
<script> | |
var PublishControl = createClass({ | |
handleClick: function(e) { | |
console.log('jo'); | |
var http = new XMLHttpRequest(); | |
var url = 'https://gitlab.example.com/api/v4/projects/123/trigger/pipeline'; | |
var params = 'token=xxxxxxxxxxxxxxxxx&ref=master'; | |
console.log(params); | |
http.open('POST', url, true); | |
//Send the proper header information along with the request | |
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
http.onreadystatechange = function() {//Call a function when the state changes. | |
if(http.readyState == 4 && http.status == 201) { | |
alert("Publication deployment started. Please check live website after a few minutes."); | |
console.log(http.responseText); | |
} | |
else{ | |
console.log(http.responseText); | |
console.log(http.readyState); | |
console.log(http.status); | |
} | |
} | |
http.send(params); | |
}, | |
render: function() { | |
var value = this.props.value; | |
return h('div', {className: 'nc-controlPane-widget'}, | |
h('input', { type: 'button', className: 'nc-collectionPage-topNewButton', value: 'publish', onClick: this.handleClick }) | |
); | |
} | |
}); | |
var PublishPreview = createClass({ | |
render: function() { | |
return h('input', { type: 'button', value: 'publish', onClick: this.handleClick }); | |
} | |
}); | |
CMS.registerWidget('publish', PublishControl, PublishPreview); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is can replace default publish button?