Skip to content

Instantly share code, notes, and snippets.

@tmthrgd
Last active September 2, 2016 09:51
Show Gist options
  • Save tmthrgd/7178224 to your computer and use it in GitHub Desktop.
Save tmthrgd/7178224 to your computer and use it in GitHub Desktop.
Parses languages.yml from github/linguist to create css for http://tomthorogood.co.uk/projects/
<!doctype html>
<html lang=en>
<!--
(c) Tom Thorogood 2013
https://tomthorogood.co.uk
Copyright 2013 Tom Thorogood. All rights reserved.
Use of this source code is governed by a
Modified BSD License license that can be found in
the LICENSE file.
-->
<head>
<meta charset=utf-8>
<title>GitHub Language Colors</title>
<style>
html, body, #result {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
html, body {
overflow: hidden;
}
#result {
color: #999;
overflow: auto;
}
#result span {
font-weight: bold;
}
</style>
</head>
<body>
<pre id=result></pre>
<script src=https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.0.2/js-yaml.min.js></script>
<script>
window.ghcallback = function (response) {
if (response.meta.status != 200) {
console.warn && console.warn(response.meta);
document.getElementById("result").innerHTML = response.meta.message;
return;
}
console.log && console.log(response.meta);
var langs = jsyaml.load(response.data.encoding === "base64" ? window.atob(response.data.content.replace(/\n/g, "")) : response.data.content);
var html = [];
for (var lang in langs) {
if (langs[lang].color) {
html.push(".git-repo.language-<span style=color:" + langs[lang].color + " title=\"" + lang + "\">" + lang.replace(/\s+/g, "-").replace(/([#+])/g, "\\$1").toLowerCase() + "</span> { border-color: <span style=color:" + langs[lang].color + ">" + langs[lang].color + "</span>; }");
}
}
document.getElementById("result").innerHTML = html.join("\n");
};
</script>
<script src="https://api.github.com/repos/github/linguist/contents/lib/linguist/languages.yml?callback=ghcallback"></script>
</body>
</html>
Copyright (c) 2013, Tom Thorogood.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Tom Thorogood nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment