Created
April 27, 2020 15:39
-
-
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
This file contains 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
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