Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created April 27, 2020 15:39
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 ryanfb/6ffdb5dc3f338f553711a452d2a4136b to your computer and use it in GitHub Desktop.
Save ryanfb/6ffdb5dc3f338f553711a452d2a4136b to your computer and use it in GitHub Desktop.
snippet for setting the last modified date on a GitHub Pages post using the GitHub API
function setModifiedDate() {
if (document.getElementById('last-modified')) {
fetch("https://api.github.com/repos/{{ site.github.owner_name }}/{{ site.github.repository_name }}/commits?path={{ page.path }}")
.then((response) => {
return response.json();
})
.then((commits) => {
var modified = commits[0]['commit']['committer']['date'].slice(0,10);
if(modified != "{{ page.date | date: "%Y-%m-%d" }}") {
document.getElementById('last-modified').textContent = "Last Modified: " + modified;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment