From e00edc8b21ad6c8f5210e6d5cc9b116a977e01e2 Mon Sep 17 00:00:00 2001 From: Jonatan Lledo Date: Tue, 7 Feb 2023 14:21:50 +0100 Subject: [PATCH] #281 improve some code smell & more --- scripts/lib-franklin.js | 271 ++++++++++++++++++++++------------------ scripts/scripts.js | 178 +++++++++++++++++--------- templates/config.js | 5 + 3 files changed, 273 insertions(+), 181 deletions(-) create mode 100644 templates/config.js diff --git a/scripts/lib-franklin.js b/scripts/lib-franklin.js index 80744607..f038b227 100644 --- a/scripts/lib-franklin.js +++ b/scripts/lib-franklin.js @@ -99,7 +99,8 @@ export function loadCSS(href, callback) { */ export function getMetadata(name) { const attr = name && name.includes(':') ? 'property' : 'name'; - const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)].map((m) => m.content).join(', '); + const meta = [...document.head.querySelectorAll(`meta[${attr}="${name}"]`)] + .map((m) => m.content).join(', '); return meta || ''; } @@ -114,7 +115,7 @@ export function toClassName(name) { : ''; } -/* +/** * Sanitizes a name for use as a js property name. * @param {string} name The unsanitized name * @returns {string} The camelCased name @@ -123,6 +124,46 @@ export function toCamelCase(name) { return toClassName(name).replace(/-([a-z])/g, (g) => g[1].toUpperCase()); } +/** + * Sanitize the svg text code + * @param {string} svg - raw svg code + * @param {string} iconName + * @returns {string} sanitized svg string + */ +function cleanSVG(svg, iconName) { + if (svg.match(/