chore: initial commit
This commit is contained in:
commit
4ae1f3bdf4
12 changed files with 3902 additions and 0 deletions
55
tablericons.js
Normal file
55
tablericons.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
const ICONS = require("./icons");
|
||||
|
||||
const initialConfig = {
|
||||
className: "",
|
||||
errorOnMissing: false,
|
||||
};
|
||||
|
||||
module.exports = function tablericons(eleventyConfig, config = initialConfig) {
|
||||
function tablericons(context = this, name, alt) {
|
||||
const contents = ICONS[name];
|
||||
if (!contents) {
|
||||
const message = `No tablericons found for name "${name}"`;
|
||||
if (config.errorOnMissing) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
console.warn(message + ` in ${context.page.inputPath}`);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if (!contents) return "";
|
||||
|
||||
return `${head(alt, config.className, name)}${contents}${
|
||||
ICONS.TAIL
|
||||
}`;
|
||||
}
|
||||
|
||||
eleventyConfig.addShortcode("tablericon", function (name, alt, attrs) {
|
||||
return tablericons(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"`;
|
||||
if (className) output += ` class="${className}"`;
|
||||
output += ` data-tablericon-name="${iconName}"`;
|
||||
|
||||
if (attrs) {
|
||||
if (typeof attrs === "string") {
|
||||
output += ` ${attrs}`;
|
||||
} else {
|
||||
Object.entries(attrs).forEach(([property, value]) => {
|
||||
if (property && value) {
|
||||
output += ` ${property}="${value}"`;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
output += ">"; // Close tag
|
||||
if (alt) output += `<title>${alt}</title>`;
|
||||
|
||||
return output;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue