Last active
April 23, 2019 22:37
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script> | |
<script> | |
window.addEventListener("load", populateFolders); | |
async function populateFolders() { | |
try { | |
let response = await new GitHub().getRepo("ukparliament", "ontologies").getTree("master"); | |
response.data.tree.filter(isOntologyFolder).forEach(addFolder); | |
} | |
catch(e) { | |
if(e.response.status === 403) { | |
showModal("GitHub rate limit exceeded."); | |
} | |
else { | |
throw e; | |
} | |
} | |
} | |
function convertForm() { | |
if(form.checkValidity()) { | |
url.value = convertToRdfXml(url.value); | |
} else { | |
showModal("URL missing"); | |
} | |
} | |
function convertToLode(url) { | |
return `extract?url=${encodeURIComponent(url)}`; | |
} | |
function convertToRdfXml(url) { | |
return `http://www.easyrdf.org/converter?uri=${encodeURIComponent(url)}&out=rdfxml&raw=1`; | |
} | |
function convertToOntologyUrl(name) { | |
return `https://ukparliament.github.io/ontologies/${name}/${name}-ontology.ttl`; | |
} | |
function populate() { | |
url.value = convertToOntologyUrl(folders.value); | |
} | |
function generateLinks() { | |
for(var option of folders.options) { | |
generateLink(option.text); | |
} | |
} | |
function generateLink(name) { | |
return links.appendChild(createLink(name)); | |
} | |
function download(name) { | |
let link = generateLink(name); | |
link.download = `${name}.html`; | |
link.click(); | |
} | |
function downloadAll() { | |
for(let option of folders.options) { | |
download(option.text); | |
} | |
} | |
function createLink(name) { | |
let link = document.createElement("a"); | |
link.style.display = "block"; | |
link.innerText = name; | |
link.href = convertToLode(convertToRdfXml(convertToOntologyUrl(name))); | |
link.target = "_blank"; | |
return link; | |
} | |
function showModal(text) { | |
message.innerText = text; | |
dialog.showModal(); | |
} | |
function addLink(folder) { | |
let name = folder.path; | |
let link = document.createElement("a"); | |
document.body.appendChild(link); | |
link.style.display = "block"; | |
link.download = name; | |
link.href = `extract?url=${encodeURIComponent(`http://www.easyrdf.org/converter?uri=${encodeURIComponent(`https://ukparliament.github.io/ontologies/${name}/${name}-ontology.ttl`)}&out=rdfxml&raw=1`)}`; | |
link.innerText = name; | |
link.click(); | |
} | |
function isOntologyFolder(folder) { | |
return /^[a-z-]+$/.test(folder.path); | |
} | |
function addFolder(folder) { | |
let option = document.createElement("option"); | |
option.text = folder.path; | |
folders.add(option); | |
} | |
</script> | |
</head> | |
<body> | |
<fieldset> | |
<legend>github/ukparliament/ontologies</legend> | |
<label for="folders">Folders</label> | |
<select id="folders"></select> | |
<button onclick="generateLink(folders.value)">Generate link</button> | |
<button onclick="download(folders.value)">Download</button> | |
<button onclick="generateLinks()">Generate all links</button> | |
<button onclick="downloadAll()">Download all</button> | |
<button onclick="populate()">Populate form</button> | |
</fieldset> | |
<fieldset> | |
<legend>Anything</legend> | |
<form id="form" action="extract"> | |
<label for="url">URL</label> | |
<input id="url" name="url" required> | |
<button type="button" onclick="convertForm()">Convert</button> | |
<button type="reset">Clear</button> | |
<button>Navigate</button> | |
</form> | |
</fieldset> | |
<fieldset id="links"> | |
<legend>Generated links</legend> | |
</fieldset> | |
<dialog id="dialog" style="text-align: center"> | |
<form method="dialog"> | |
<div id="message"></div> | |
<hr> | |
<button>Close</button> | |
</form> | |
</dialog> | |
</body> | |
</html> |
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
LODE custom homepage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment