| 1 |
// -------------------------------------------------------------------------- |
| 2 |
// --- Icons Markdown Gallery Generator |
| 3 |
// -------------------------------------------------------------------------- |
| 4 |
|
| 5 |
const path = require('path'); |
| 6 |
const icons = require(path.resolve( process.argv[2] )); |
| 7 |
const index = []; |
| 8 |
const sections = {}; |
| 9 |
|
| 10 |
// --- Indexing & Sectioning ----------------------------------------- |
| 11 |
|
| 12 |
for ( var name in icons ) { |
| 13 |
const icon = icons[name]; |
| 14 |
const section = icon.section || "Others" ; |
| 15 |
if (section != "Others" && index.indexOf(section) < 0) index.push( section ); |
| 16 |
var content = sections[section] ; |
| 17 |
if (!content) sections[section] = content = [] ; |
| 18 |
content.push(name) ; |
| 19 |
} |
| 20 |
|
| 21 |
index.sort(); |
| 22 |
if (sections["Others"]) index.push("Others"); |
| 23 |
|
| 24 |
console.log(); |
| 25 |
|
| 26 |
// --- Gallery (per section) ----------------------------------------- |
| 27 |
|
| 28 |
for ( var s = 0 ; s < index.length ; s++ ) { |
| 29 |
const section = index[s] ; |
| 30 |
console.log( '<hr/>' ); |
| 31 |
console.log(); |
| 32 |
console.log( `## ${section}` ); |
| 33 |
console.log(); |
| 34 |
console.log( ` <div class="database">` ); |
| 35 |
|
| 36 |
const content = sections[section] ; |
| 37 |
content.sort(); |
| 38 |
|
| 39 |
for( var k = 0 ; k < content.length ; k++ ) { |
| 40 |
const name = content[k]; |
| 41 |
const icon = icons[name]; |
| 42 |
const title = icon.title || name ; |
| 43 |
console.log( `<div class="icon-block" title="${title}">`); |
| 44 |
console.log( `<div class="icon-name refname" id="ICON.${name}">${name}</div>` ); |
| 45 |
console.log( `<svg class="icon-svg" viewBox="${icon.viewBox}">` ); |
| 46 |
console.log( `<path d="${icon.path}"/>`); |
| 47 |
console.log( `</svg>` ); |
| 48 |
console.log( `</div>` ); |
| 49 |
} |
| 50 |
console.log( `</div>`); |
| 51 |
console.log(); |
| 52 |
} |
| 53 |
|
| 54 |
// ------------------------------------------------------------------- |