mirror of
				https://github.com/Mibew/simple-icons.git
				synced 2025-11-04 12:25:08 +03:00 
			
		
		
		
	Finished v1 node builder script
This commit is contained in:
		
							parent
							
								
									09183fe2d5
								
							
						
					
					
						commit
						463d5025ec
					
				
							
								
								
									
										31
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -34,4 +34,33 @@
 | 
			
		||||
.Spotlight-V100
 | 
			
		||||
.Trashes
 | 
			
		||||
ehthumbs.db
 | 
			
		||||
Thumbs.db
 | 
			
		||||
Thumbs.db
 | 
			
		||||
 | 
			
		||||
# Logs
 | 
			
		||||
logs
 | 
			
		||||
*.log
 | 
			
		||||
npm-debug.log*
 | 
			
		||||
 | 
			
		||||
# Runtime data
 | 
			
		||||
pids
 | 
			
		||||
*.pid
 | 
			
		||||
*.seed
 | 
			
		||||
 | 
			
		||||
# Directory for instrumented libs generated by jscoverage/JSCover
 | 
			
		||||
lib-cov
 | 
			
		||||
 | 
			
		||||
# Coverage directory used by tools like istanbul
 | 
			
		||||
coverage
 | 
			
		||||
 | 
			
		||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
 | 
			
		||||
.grunt
 | 
			
		||||
 | 
			
		||||
# node-waf configuration
 | 
			
		||||
.lock-wscript
 | 
			
		||||
 | 
			
		||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
 | 
			
		||||
build/Release
 | 
			
		||||
 | 
			
		||||
# Dependency directory
 | 
			
		||||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
 | 
			
		||||
node_modules
 | 
			
		||||
							
								
								
									
										67
									
								
								build.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								build.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,67 @@
 | 
			
		||||
// Get JSON from source file
 | 
			
		||||
var source = require('./simple-icons.json');
 | 
			
		||||
 | 
			
		||||
// Loop through icons
 | 
			
		||||
for (var i = 0; i < source.icons.length; i++) {
 | 
			
		||||
 | 
			
		||||
    var hex = source.icons[i].hex;
 | 
			
		||||
 | 
			
		||||
    // Add red, green and blue values to the JSON object
 | 
			
		||||
    var red   = parseInt(hex.substr(0,2), 16) / 255;
 | 
			
		||||
    var green = parseInt(hex.substr(2,2), 16) / 255;
 | 
			
		||||
    var blue  = parseInt(hex.substr(4,2), 16) / 255;
 | 
			
		||||
 | 
			
		||||
    // Add hue to the JSON object
 | 
			
		||||
    var max = Math.max(red, green, blue);
 | 
			
		||||
    var min = Math.min(red, green, blue);
 | 
			
		||||
    var delta = max - min;
 | 
			
		||||
    if (delta === 0) {
 | 
			
		||||
        var hue = 0;
 | 
			
		||||
    } else {
 | 
			
		||||
        if (max === red) {
 | 
			
		||||
            var hue = ((green - blue) / delta) * 60;
 | 
			
		||||
            if (hue < 0) {
 | 
			
		||||
                hue += 360;
 | 
			
		||||
            }
 | 
			
		||||
        } else if (max === green) {
 | 
			
		||||
            var hue = (((blue - red) / delta) + 2) * 60;
 | 
			
		||||
        } else {
 | 
			
		||||
            var hue = (((red - green) / delta) + 4) * 60;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    source.icons[i].hue = hue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Sort icons by hue
 | 
			
		||||
source.icons.sort(function(a, b) {
 | 
			
		||||
    return parseFloat(b.hue) - parseFloat(a.hue);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Read header and footer content into variables
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
function readFile(path, callback) {
 | 
			
		||||
    try {
 | 
			
		||||
        var filename = require.resolve(path);
 | 
			
		||||
        fs.readFile(filename, 'utf8', callback);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        callback(e);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
var fs = require('fs');
 | 
			
		||||
var header = fs.readFileSync('./src/header.html', 'utf8');
 | 
			
		||||
var footer = fs.readFileSync('./src/footer.html', 'utf8');
 | 
			
		||||
 | 
			
		||||
// Build tiles content
 | 
			
		||||
var main = "";
 | 
			
		||||
for (var i = 0; i < source.icons.length; i++) {
 | 
			
		||||
    main += "<li class=\"tiles__item\" style=\"background-color:#" + source.icons[i].hex + "\">" + source.icons[i].title + "<br>#" + source.icons[i].hex + "</li>";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Put all content together and export to index.html
 | 
			
		||||
var htmlOutput = header + main + footer;
 | 
			
		||||
fs.writeFile("./index.html", htmlOutput, function(err) {
 | 
			
		||||
    if(err) {
 | 
			
		||||
        return console.log(err);
 | 
			
		||||
    }
 | 
			
		||||
    console.log("The file was saved!");
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										100
									
								
								index.html
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								index.html
									
									
									
									
									
								
							@ -4,7 +4,7 @@
 | 
			
		||||
    <meta charset="utf-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
    <title>Simple Icons</title>
 | 
			
		||||
    <link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
 | 
			
		||||
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400">
 | 
			
		||||
    <style>
 | 
			
		||||
        html {
 | 
			
		||||
            font-size: 16px;
 | 
			
		||||
@ -45,27 +45,39 @@
 | 
			
		||||
            margin: 1.5rem;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
        .hero {
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            margin: 0 auto;
 | 
			
		||||
            max-width: 21rem;
 | 
			
		||||
            padding: 3rem;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
        .tiles {
 | 
			
		||||
            display: flex;
 | 
			
		||||
            flex-wrap: wrap;
 | 
			
		||||
            list-style: none;
 | 
			
		||||
            margin: 1.25rem;
 | 
			
		||||
            margin: -0.25rem 1.25rem;
 | 
			
		||||
            padding: 0;
 | 
			
		||||
        }
 | 
			
		||||
        .tiles__item {
 | 
			
		||||
        .tiles li {
 | 
			
		||||
            box-sizing: border-box;
 | 
			
		||||
            background: #333;
 | 
			
		||||
            border: 0.25rem solid #FFF;
 | 
			
		||||
            color: #FFF;
 | 
			
		||||
            padding: 1.5rem;
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            padding: 0.75rem 1.5rem;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
            width: 100%;
 | 
			
		||||
        }
 | 
			
		||||
        @media (min-width: 600px) { .tiles__item { width: 50%; } }
 | 
			
		||||
        @media (min-width: 800px) { .tiles__item { width: 33.333%; } }
 | 
			
		||||
        @media (min-width: 1000px) { .tiles__item { width: 25% } }
 | 
			
		||||
        @media (min-width: 1200px) { .tiles__item { width: 20% } }
 | 
			
		||||
        @media (min-width: 1500px) { .tiles__item { width: 16.666% } }
 | 
			
		||||
        @media (min-width: 1800px) { .tiles__item { width: 12.5% } }
 | 
			
		||||
        @media (min-width: 600px) { .tiles li { width: 50%; } }
 | 
			
		||||
        @media (min-width: 800px) { .tiles li { width: 33.333%; } }
 | 
			
		||||
        @media (min-width: 1000px) { .tiles li { width: 25% } }
 | 
			
		||||
        @media (min-width: 1200px) { .tiles li { width: 20% } }
 | 
			
		||||
        @media (min-width: 1500px) { .tiles li { width: 16.666% } }
 | 
			
		||||
        @media (min-width: 1800px) { .tiles li { width: 12.5% } }
 | 
			
		||||
        .footer {
 | 
			
		||||
            margin: 3rem;
 | 
			
		||||
        }
 | 
			
		||||
@ -86,75 +98,11 @@
 | 
			
		||||
        <p class="navbar__text">Share on <a href="#">Facebook</a> & <a href="#">Twitter</a></p>
 | 
			
		||||
    </header>
 | 
			
		||||
    <main role="main">
 | 
			
		||||
        <ul class="tiles">
 | 
			
		||||
            <li class="tiles__item" data-colour="5AB552">
 | 
			
		||||
                Event Store
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="tiles__item" data-colour="3B5998">
 | 
			
		||||
                Facebook
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="tiles__item" data-colour="55ACEE">
 | 
			
		||||
                Twitter
 | 
			
		||||
            </li>
 | 
			
		||||
            <li class="tiles__item" data-colour="CD201F">
 | 
			
		||||
                YouTube
 | 
			
		||||
            </li>
 | 
			
		||||
        </ul>
 | 
			
		||||
        <p class="hero">A set of SVG icons for popular brands. Download them from <a href="https://github.com/danleech/simple-icons">GitHub</a>.</p>
 | 
			
		||||
        <ul class="tiles"><li class="tiles__item" style="background-color:#3B5998">Facebook<br>#3B5998</li><li class="tiles__item" style="background-color:#55ACEE">Twitter<br>#55ACEE</li><li class="tiles__item" style="background-color:#009CDB">Bath ASU<br>#009CDB</li><li class="tiles__item" style="background-color:#0B0C0C">GOV.UK<br>#0B0C0C</li><li class="tiles__item" style="background-color:#5AB552">Event Store<br>#5AB552</li><li class="tiles__item" style="background-color:#CD201F">YouTube<br>#CD201F</li><li class="tiles__item" style="background-color:#000000">MediaTemple<br>#000000</li>        </ul>
 | 
			
		||||
    </main>
 | 
			
		||||
    <footer class="footer" role="contentinfo">
 | 
			
		||||
        <p>Distributed for free by Dan Leech under the Free Art License. Company logos in icons are copyright of their respective owners. <a href="#">Coffee fund donations</a> are greatly appreciated!</p>
 | 
			
		||||
    </footer>
 | 
			
		||||
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
 | 
			
		||||
    <script>
 | 
			
		||||
        $(document).ready(function() {
 | 
			
		||||
            $(".tiles__item").each(function () {
 | 
			
		||||
 | 
			
		||||
                // Get colour attribute as a string
 | 
			
		||||
                var hex = $(this).data('colour') + "";
 | 
			
		||||
                console.log(hex);
 | 
			
		||||
 | 
			
		||||
                // Set tile background colour
 | 
			
		||||
                $(this).css('background', "#" + hex);
 | 
			
		||||
 | 
			
		||||
                // Calculate RGB values from hex
 | 
			
		||||
                var red = parseInt(hex.substr(0,2), 16) / 255;
 | 
			
		||||
                var green = parseInt(hex.substr(2,2), 16) / 255;
 | 
			
		||||
                var blue = parseInt(hex.substr(4,2), 16) / 255;
 | 
			
		||||
 | 
			
		||||
                var maxRGB = Math.max(red, green, blue);
 | 
			
		||||
                var minRGB = Math.min(red, green, blue);
 | 
			
		||||
                var delta = maxRGB - minRGB;
 | 
			
		||||
 | 
			
		||||
                if (delta === 0) {
 | 
			
		||||
                    var hue = 0;
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (maxRGB === red) {
 | 
			
		||||
                        var hue = ((green - blue) / delta);
 | 
			
		||||
                        hue *= 60;
 | 
			
		||||
                        if (hue < 0) {
 | 
			
		||||
                            hue += 360;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else if (maxRGB === green) {
 | 
			
		||||
                        var hue = (((blue - red) / delta) + 2);
 | 
			
		||||
                        hue *= 60;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        hue = (((red - green) / delta) + 4);
 | 
			
		||||
                        hue *= 60;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Set data attribute for hue
 | 
			
		||||
                this.setAttribute('data-hue', hue);
 | 
			
		||||
 | 
			
		||||
                // Sort by hue
 | 
			
		||||
                $(".tiles__item").sort(sort_li) // sort elements
 | 
			
		||||
                    .appendTo('.tiles'); // append again to the list
 | 
			
		||||
                // sort function callback
 | 
			
		||||
                function sort_li(a, b){
 | 
			
		||||
                    return ($(b).data('hue')) > ($(a).data('hue')) ? 1 : -1;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										32
									
								
								simple-icons.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								simple-icons.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
{
 | 
			
		||||
    "icons": [
 | 
			
		||||
        {
 | 
			
		||||
            "title": "Bath ASU",
 | 
			
		||||
            "hex": "009CDB"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "Event Store",
 | 
			
		||||
            "hex": "5AB552"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "Facebook",
 | 
			
		||||
            "hex": "3B5998"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "GOV.UK",
 | 
			
		||||
            "hex": "0B0C0C"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "MediaTemple",
 | 
			
		||||
            "hex": "000000"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "Twitter",
 | 
			
		||||
            "hex": "55ACEE"
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
            "title": "YouTube",
 | 
			
		||||
            "hex": "CD201F"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								src/footer.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/footer.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
        </ul>
 | 
			
		||||
    </main>
 | 
			
		||||
    <footer class="footer" role="contentinfo">
 | 
			
		||||
        <p>Distributed for free by Dan Leech under the Free Art License. Company logos in icons are copyright of their respective owners. <a href="#">Coffee fund donations</a> are greatly appreciated!</p>
 | 
			
		||||
    </footer>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										102
									
								
								src/header.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								src/header.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,102 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="utf-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
    <title>Simple Icons</title>
 | 
			
		||||
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400">
 | 
			
		||||
    <style>
 | 
			
		||||
        html {
 | 
			
		||||
            font-size: 16px;
 | 
			
		||||
        }
 | 
			
		||||
        body {
 | 
			
		||||
            color: #666;
 | 
			
		||||
            font-family: Lato, sans-serif;
 | 
			
		||||
            -webkit-font-feature-settings: "dlig", "kern", "liga";
 | 
			
		||||
                    font-feature-settings: "dlig", "kern", "liga";
 | 
			
		||||
            -webkit-font-smoothing: antialiased;
 | 
			
		||||
            font-weight: 400;
 | 
			
		||||
            line-height: 1.5rem;
 | 
			
		||||
            margin: 0;
 | 
			
		||||
            -moz-osx-font-smoothing: grayscale;
 | 
			
		||||
        }
 | 
			
		||||
        a {
 | 
			
		||||
            color: #333;
 | 
			
		||||
        }
 | 
			
		||||
        a:focus, a:hover {
 | 
			
		||||
            color: #999;
 | 
			
		||||
        }
 | 
			
		||||
        .navbar {
 | 
			
		||||
            background: #EEE;
 | 
			
		||||
            display: flex;
 | 
			
		||||
            justify-content: space-between;
 | 
			
		||||
        }
 | 
			
		||||
        .title {
 | 
			
		||||
            font-size: 1rem;
 | 
			
		||||
            font-weight: 400;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            margin: 0;
 | 
			
		||||
            padding: 1.5rem;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
        .navbar__text {
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            margin: 1.5rem;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
        .hero {
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            margin: 0 auto;
 | 
			
		||||
            max-width: 21rem;
 | 
			
		||||
            padding: 3rem;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
        .tiles {
 | 
			
		||||
            display: flex;
 | 
			
		||||
            flex-wrap: wrap;
 | 
			
		||||
            list-style: none;
 | 
			
		||||
            margin: -0.25rem 1.25rem;
 | 
			
		||||
            padding: 0;
 | 
			
		||||
        }
 | 
			
		||||
        .tiles li {
 | 
			
		||||
            box-sizing: border-box;
 | 
			
		||||
            background: #333;
 | 
			
		||||
            border: 0.25rem solid #FFF;
 | 
			
		||||
            color: #FFF;
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            padding: 0.75rem 1.5rem;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
            width: 100%;
 | 
			
		||||
        }
 | 
			
		||||
        @media (min-width: 600px) { .tiles li { width: 50%; } }
 | 
			
		||||
        @media (min-width: 800px) { .tiles li { width: 33.333%; } }
 | 
			
		||||
        @media (min-width: 1000px) { .tiles li { width: 25% } }
 | 
			
		||||
        @media (min-width: 1200px) { .tiles li { width: 20% } }
 | 
			
		||||
        @media (min-width: 1500px) { .tiles li { width: 16.666% } }
 | 
			
		||||
        @media (min-width: 1800px) { .tiles li { width: 12.5% } }
 | 
			
		||||
        .footer {
 | 
			
		||||
            margin: 3rem;
 | 
			
		||||
        }
 | 
			
		||||
        .footer p {
 | 
			
		||||
            font-size: 0.75rem;
 | 
			
		||||
            letter-spacing: 0.05rem;
 | 
			
		||||
            margin: 0 auto;
 | 
			
		||||
            max-width: 31.5rem;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            text-transform: uppercase;
 | 
			
		||||
        }
 | 
			
		||||
    </style>
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
    <header class="navbar" role="banner">
 | 
			
		||||
        <h1 class="title">Simple Icons</h1>
 | 
			
		||||
        <p class="navbar__text">Share on <a href="#">Facebook</a> & <a href="#">Twitter</a></p>
 | 
			
		||||
    </header>
 | 
			
		||||
    <main role="main">
 | 
			
		||||
        <p class="hero">A set of SVG icons for popular brands. Download them from <a href="https://github.com/danleech/simple-icons">GitHub</a>.</p>
 | 
			
		||||
        <ul class="tiles">
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user