Compare commits
41 commits
Author | SHA1 | Date | |
---|---|---|---|
319fcc398b |
|||
185ae2921e |
|||
ed9a968b1c |
|||
18e1a5ea71 |
|||
87ec17fbc6 |
|||
76ddf1d01b |
|||
56a78d5d2a |
|||
3d2792afa5 |
|||
c592874ce5 |
|||
ae4d43b437 |
|||
1040def4cc |
|||
d3f676d03c |
|||
31b01ad395 |
|||
a4c1995561 |
|||
5908965aef |
|||
4520e0c9d4 |
|||
7d95234fa3 |
|||
86eaf1ded5 |
|||
919b3717f8 |
|||
284c76225a |
|||
5026eb74f1 |
|||
a6f5d1d1cd |
|||
8282f1e0a4 |
|||
b1cf9859fa |
|||
f0b2df2fab |
|||
e5df8b942b |
|||
3405232bc5 |
|||
9e64691845 |
|||
2a4e12940f |
|||
73a676d5e1 |
|||
85abcd93af |
|||
e00d2d92f0 |
|||
41545f264c |
|||
dc51bb91cc |
|||
![]() |
204a33ccdb |
||
35d2adaba7 |
|||
![]() |
73b8dab636 |
||
6bfb8e1c74 |
|||
d4c28afdd2 |
|||
f6585fa5d5 |
|||
58614c3113 |
5 changed files with 6125 additions and 995 deletions
56
build.js
56
build.js
|
@ -1,28 +1,36 @@
|
|||
const fs = require('fs');
|
||||
const path = `./node_modules/@tabler/icons/icons/filled/`;
|
||||
const fileNames = fs.readdirSync(path);
|
||||
const object = {};
|
||||
import { readdirSync, readFileSync, writeFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const ICONS_DIR = path.join('node_modules', '@tabler', 'icons', 'icons', 'outline')
|
||||
const CONTENTS = {
|
||||
HEAD: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" stroke-width=\"2\" stroke=\"currentColor\" fill=\"none\" stroke-linecap=\"round\" stroke-linejoin=\"round\">",
|
||||
TAIL: "</svg>",
|
||||
};
|
||||
HEAD: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">`,
|
||||
TAIL: '</svg>'
|
||||
}
|
||||
const object = {}
|
||||
|
||||
try {
|
||||
const fileNames = readdirSync(ICONS_DIR)
|
||||
|
||||
fileNames.forEach((filename) => {
|
||||
const contents = fs
|
||||
.readFileSync(path + filename)
|
||||
.toString()
|
||||
.trimEnd();
|
||||
const lines = contents.split("\n");
|
||||
const guts = lines
|
||||
.slice(1, lines.length - 1)
|
||||
.join("")
|
||||
.replace(/\ \ /g, "");
|
||||
if (object) object[filename.slice(0, -4)] = guts;
|
||||
});
|
||||
const filePath = path.join(ICONS_DIR, filename)
|
||||
const contents = readFileSync(filePath, 'utf8').trim()
|
||||
|
||||
fs.writeFileSync(
|
||||
"./icons.js",
|
||||
`// Generated by build.js at ${new Date().toISOString()}\n\nmodule.exports = ${JSON.stringify(
|
||||
{...object, HEAD: CONTENTS['HEAD'], TAIL: CONTENTS['TAIL']}
|
||||
)};\n`
|
||||
);
|
||||
const guts = contents
|
||||
.replace(/^<svg[^>]*>/, '')
|
||||
.replace(/<\/svg>$/, '')
|
||||
.replace(/\s{2,}/g, ' ')
|
||||
|
||||
object[filename.slice(0, -4)] = guts
|
||||
})
|
||||
|
||||
const output = `// Generated by build.js at ${new Date().toISOString()}
|
||||
|
||||
export default ${JSON.stringify({ ...object, HEAD: CONTENTS.HEAD, TAIL: CONTENTS.TAIL }, null, 2)};
|
||||
`
|
||||
|
||||
writeFileSync('./icons.js', output)
|
||||
|
||||
console.log('Icons successfully generated and saved to icons.js!')
|
||||
} catch (err) {
|
||||
console.error('Error processing icons:', err)
|
||||
}
|
4970
icons.js
4970
icons.js
File diff suppressed because one or more lines are too long
1996
package-lock.json
generated
1996
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"name": "@cdransf/eleventy-tabler-icons-filled",
|
||||
"version": "1.2.0",
|
||||
"version": "2.13.2",
|
||||
"description": "Shortcodes to add filled Tabler icons to your Eleventy projects",
|
||||
"type": "module",
|
||||
"main": "tablericons.js",
|
||||
"files": [
|
||||
"tablericons.js",
|
||||
|
@ -18,21 +19,21 @@
|
|||
"tabler-icons"
|
||||
],
|
||||
"author": {
|
||||
"email": "coryd@hey.com",
|
||||
"email": "hi@coryd.dev",
|
||||
"name": "Cory Dransfeldt",
|
||||
"url": "https://coryd.dev"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/cdransf/eleventy-tabler-icons-filled.git"
|
||||
"url": "git+https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled.git"
|
||||
},
|
||||
"homepage": "https://github.com/cdransf/eleventy-tabler-icons-filled#readme",
|
||||
"homepage": "https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cdransf/eleventy-tabler-icons-filled/issues"
|
||||
"url": "https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@11ty/eleventy": "^2.0.1",
|
||||
"@tabler/icons": "^3.2.0"
|
||||
"@11ty/eleventy": "^3.1.2",
|
||||
"@tabler/icons": "^3.34.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,55 +1,58 @@
|
|||
const ICONS = require("./icons");
|
||||
import ICONS from './icons.js';
|
||||
|
||||
const initialConfig = {
|
||||
className: "",
|
||||
errorOnMissing: false,
|
||||
};
|
||||
const tablericons = (eleventyConfig, config = {}) => {
|
||||
const { className = '', errorOnMissing = false } = config;
|
||||
|
||||
module.exports = function tablericons(eleventyConfig, config = initialConfig) {
|
||||
function tablericons(context = this, name, alt) {
|
||||
const renderIcon = (context = {}, name, alt = '', attrs = {}) => {
|
||||
const contents = ICONS[name];
|
||||
if (!contents) {
|
||||
const message = `No tablericons found for name "${name}"`;
|
||||
if (config.errorOnMissing) {
|
||||
handleMissingIcon(name, context.page?.inputPath);
|
||||
return '';
|
||||
}
|
||||
|
||||
return `${buildHead(alt, className, name, attrs)}${contents}${ICONS.TAIL}`;
|
||||
};
|
||||
|
||||
const handleMissingIcon = (name, inputPath) => {
|
||||
const message = `No tablericon found for name '${name}'`;
|
||||
if (errorOnMissing) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
console.warn(message + ` in ${context.page.inputPath}`);
|
||||
return "";
|
||||
}
|
||||
console.warn(`${message}${inputPath ? ` in ${inputPath}` : ''}`);
|
||||
}
|
||||
};
|
||||
|
||||
if (!contents) return "";
|
||||
|
||||
return `${head(alt, config.className, name)}${contents}${
|
||||
ICONS.TAIL
|
||||
}`;
|
||||
}
|
||||
|
||||
eleventyConfig.addShortcode("tablericon-filled", function (name, alt, attrs) {
|
||||
return tablericons(this, name, alt, attrs);
|
||||
eleventyConfig.addShortcode('tablericon', function (name, alt, attrs) {
|
||||
return renderIcon(this, name, alt, attrs);
|
||||
});
|
||||
};
|
||||
|
||||
function head(alt, className, iconName, attrs) {
|
||||
let output = ICONS.HEAD.slice(0, -1); // Open tag
|
||||
if (!alt) output += ` aria-hidden="true"`;
|
||||
const buildHead = (alt = '', className = '', iconName, attrs = {}) => {
|
||||
let output = `${ICONS.HEAD.slice(0, -1)} aria-hidden="true"`;
|
||||
|
||||
if (className) output += ` class="${className}"`;
|
||||
output += ` data-tablericon-name="${iconName}"`;
|
||||
|
||||
if (attrs) {
|
||||
if (typeof attrs === "string") {
|
||||
if (typeof attrs === 'string') {
|
||||
output += ` ${attrs}`;
|
||||
} else {
|
||||
Object.entries(attrs).forEach(([property, value]) => {
|
||||
if (property && value) {
|
||||
output += ` ${property}="${value}"`;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (attrs && typeof attrs === 'object') {
|
||||
output += Object.entries(attrs)
|
||||
.map(([key, val]) => (key && val ? ` ${key}="${val}"` : ''))
|
||||
.join('');
|
||||
}
|
||||
|
||||
output += ">"; // Close tag
|
||||
if (alt) output += `<title>${alt}</title>`;
|
||||
return `${output}>`;
|
||||
};
|
||||
|
||||
return output;
|
||||
export function renderTablerIcon(name, alt = '', attrs = {}, options = {}) {
|
||||
const context = { page: { inputPath: options.inputPath || '' } };
|
||||
const contents = ICONS[name];
|
||||
if (!contents) {
|
||||
console.warn(`No tablericon found for name '${name}'${options.inputPath ? ` in ${options.inputPath}` : ''}`);
|
||||
return '';
|
||||
}
|
||||
|
||||
return `${buildHead(alt, options.className || '', name, attrs)}${contents}${ICONS.TAIL}`;
|
||||
}
|
||||
|
||||
export default tablericons;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue