Added small git history
This commit is contained in:
1
gatsby-browser.js
Normal file
1
gatsby-browser.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import "./src/styles/global.css"
|
||||||
53
src/pages/history.js
Normal file
53
src/pages/history.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import React from "react"
|
||||||
|
import Header from "../components/header"
|
||||||
|
|
||||||
|
const GIT_NAME = "creyD"
|
||||||
|
const GIT_REPO = "urban_website"
|
||||||
|
const GIT_URL =
|
||||||
|
"https://api.github.com/repos/" + GIT_NAME + "/" + GIT_REPO + "/events"
|
||||||
|
const GIT_COMMIT_URL =
|
||||||
|
"https://github.com/" + GIT_NAME + "/" + GIT_REPO + "/commit/"
|
||||||
|
|
||||||
|
|
||||||
|
// Adds Git History to the site
|
||||||
|
function addGitHistory(data) {
|
||||||
|
for (var push in data) {
|
||||||
|
for (var commit in data[push]["payload"]["commits"]) {
|
||||||
|
var new_li = document.createElement("li")
|
||||||
|
var url = GIT_COMMIT_URL + data[push]["payload"]["commits"][commit].sha
|
||||||
|
new_li.innerHTML =
|
||||||
|
data[push]["payload"]["commits"][commit].author.name +
|
||||||
|
" committed " +
|
||||||
|
getDate(data[push].created_at) +
|
||||||
|
": " +
|
||||||
|
data[push]["payload"]["commits"][commit].message +
|
||||||
|
" <a href=" +
|
||||||
|
url +
|
||||||
|
" target='_blanc'>(Link)</a>"
|
||||||
|
document.getElementById("log").appendChild(new_li)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send HTTP request to the GitHub API to get information about this repo
|
||||||
|
const Http = new XMLHttpRequest()
|
||||||
|
Http.open("GET", GIT_URL)
|
||||||
|
Http.send()
|
||||||
|
|
||||||
|
// If the API responds call the addGitHistory function
|
||||||
|
Http.onreadystatechange = function() {
|
||||||
|
if (this.readyState === 4 && this.status === 200) {
|
||||||
|
addGitHistory(JSON.parse(Http.responseText))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<Header headline="git log" />
|
||||||
|
<p>
|
||||||
|
You can see the full commit history{" "}
|
||||||
|
<a href="https://github.com/creyD/urban_website/commits/master">here</a>.
|
||||||
|
</p>
|
||||||
|
<ul id="log"></ul>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
3
src/styles/global.css
Normal file
3
src/styles/global.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
html {
|
||||||
|
background-color: lightgrey;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user