Skip to content

Instantly share code, notes, and snippets.

@mipmip
Created June 5, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mipmip/4c477fdf12eb50a858e2df243a4ee576 to your computer and use it in GitHub Desktop.
Save mipmip/4c477fdf12eb50a858e2df243a4ee576 to your computer and use it in GitHub Desktop.
Custom publish button inside Netlify CMS
<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>
@derit
Copy link

derit commented Dec 19, 2019

this is can replace default publish button?

@mipmip
Copy link
Author

mipmip commented Dec 23, 2019

yes

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