Compare commits

..

No commits in common. "main" and "v1.16" have entirely different histories.
main ... v1.16

5 changed files with 978 additions and 6104 deletions

View file

@ -1,36 +1,28 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs' const fs = require('fs');
import path from 'path' const path = `./node_modules/@tabler/icons/icons/filled/`;
const fileNames = fs.readdirSync(path);
const ICONS_DIR = path.join('node_modules', '@tabler', 'icons', 'icons', 'outline') const object = {};
const CONTENTS = { 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">`, 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>' TAIL: "</svg>",
} };
const object = {}
try { fileNames.forEach((filename) => {
const fileNames = readdirSync(ICONS_DIR) 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;
});
fileNames.forEach((filename) => { fs.writeFileSync(
const filePath = path.join(ICONS_DIR, filename) "./icons.js",
const contents = readFileSync(filePath, 'utf8').trim() `// Generated by build.js at ${new Date().toISOString()}\n\nmodule.exports = ${JSON.stringify(
{...object, HEAD: CONTENTS['HEAD'], TAIL: CONTENTS['TAIL']}
const guts = contents )};\n`
.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

File diff suppressed because one or more lines are too long

1964
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,7 @@
{ {
"name": "@cdransf/eleventy-tabler-icons-filled", "name": "@cdransf/eleventy-tabler-icons-filled",
"version": "2.13.1", "version": "1.16.0",
"description": "Shortcodes to add filled Tabler icons to your Eleventy projects", "description": "Shortcodes to add filled Tabler icons to your Eleventy projects",
"type": "module",
"main": "tablericons.js", "main": "tablericons.js",
"files": [ "files": [
"tablericons.js", "tablericons.js",
@ -25,15 +24,15 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled.git" "url": "git+https://github.com/cdransf/eleventy-tabler-icons-filled.git"
}, },
"homepage": "https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled#readme", "homepage": "https://github.com/cdransf/eleventy-tabler-icons-filled#readme",
"bugs": { "bugs": {
"url": "https://git.apps.coryd.dev/cdransf/eleventy-tabler-icons-filled/issues" "url": "https://github.com/cdransf/eleventy-tabler-icons-filled/issues"
}, },
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@11ty/eleventy": "v3.0.0", "@11ty/eleventy": "^2.0.1",
"@tabler/icons": "^3.34.0" "@tabler/icons": "^3.18.0"
} }
} }

View file

@ -1,58 +1,55 @@
import ICONS from './icons.js'; const ICONS = require("./icons");
const tablericons = (eleventyConfig, config = {}) => { const initialConfig = {
const { className = '', errorOnMissing = false } = config; className: "",
errorOnMissing: false,
};
const renderIcon = (context = {}, name, alt = '', attrs = {}) => { module.exports = function tablericons(eleventyConfig, config = initialConfig) {
function tablericons(context = this, name, alt) {
const contents = ICONS[name]; const contents = ICONS[name];
if (!contents) { if (!contents) {
handleMissingIcon(name, context.page?.inputPath); const message = `No tablericons found for name "${name}"`;
return ''; if (config.errorOnMissing) {
throw new Error(message);
} else {
console.warn(message + ` in ${context.page.inputPath}`);
return "";
}
} }
return `${buildHead(alt, className, name, attrs)}${contents}${ICONS.TAIL}`; if (!contents) return "";
};
const handleMissingIcon = (name, inputPath) => { return `${head(alt, config.className, name)}${contents}${
const message = `No tablericon found for name '${name}'`; ICONS.TAIL
if (errorOnMissing) { }`;
throw new Error(message); }
} else {
console.warn(`${message}${inputPath ? ` in ${inputPath}` : ''}`);
}
};
eleventyConfig.addShortcode('tablericon', function (name, alt, attrs) { eleventyConfig.addShortcode("tablericon-filled", function (name, alt, attrs) {
return renderIcon(this, name, alt, attrs); return tablericons(this, name, alt, attrs);
}); });
}; };
const buildHead = (alt = '', className = '', iconName, attrs = {}) => { function head(alt, className, iconName, attrs) {
let output = `${ICONS.HEAD.slice(0, -1)} aria-hidden="true"`; let output = ICONS.HEAD.slice(0, -1); // Open tag
if (!alt) output += ` aria-hidden="true"`;
if (className) output += ` class="${className}"`; if (className) output += ` class="${className}"`;
output += ` data-tablericon-name="${iconName}"`; output += ` data-tablericon-name="${iconName}"`;
if (typeof attrs === 'string') { if (attrs) {
output += ` ${attrs}`; if (typeof attrs === "string") {
} else if (attrs && typeof attrs === 'object') { output += ` ${attrs}`;
output += Object.entries(attrs) } else {
.map(([key, val]) => (key && val ? ` ${key}="${val}"` : '')) Object.entries(attrs).forEach(([property, value]) => {
.join(''); if (property && value) {
output += ` ${property}="${value}"`;
}
});
}
} }
return `${output}>`; output += ">"; // Close tag
}; if (alt) output += `<title>${alt}</title>`;
export function renderTablerIcon(name, alt = '', attrs = {}, options = {}) { return output;
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;