Fix custom-svg webc component
This commit is contained in:
parent
943e7c6eea
commit
c0a23b6a5a
1 changed files with 6 additions and 5 deletions
|
|
@ -1,10 +1,11 @@
|
||||||
<!-- by Ryan Mulligan: https://github.com/hexagoncircle/start-me-up/blob/main/src/_includes/inline-svg.webc -->
|
<!-- by Ryan Mulligan: https://github.com/hexagoncircle/start-me-up/blob/main/src/_includes/inline-svg.webc -->
|
||||||
|
|
||||||
<script webc:type="render" webc:is="template">
|
<script webc:type="render" webc:is="template">
|
||||||
const Image = require('@11ty/eleventy-img');
|
export default async function () {
|
||||||
const {optimize} = require('svgo');
|
const {default: slugify} = await import('slugify');
|
||||||
|
const {default: Image} = await import('@11ty/eleventy-img');
|
||||||
|
const {optimize} = await import('svgo');
|
||||||
|
|
||||||
module.exports = async function () {
|
|
||||||
const meta = await Image(this.src, {
|
const meta = await Image(this.src, {
|
||||||
formats: ['svg'],
|
formats: ['svg'],
|
||||||
dryRun: true
|
dryRun: true
|
||||||
|
|
@ -19,7 +20,7 @@
|
||||||
|
|
||||||
for (const prop in this.webc.attributes) {
|
for (const prop in this.webc.attributes) {
|
||||||
if (!excludeAttributes.includes(prop)) {
|
if (!excludeAttributes.includes(prop)) {
|
||||||
const attribute = this.slugify(prop, {decamelize: true});
|
const attribute = slugify(prop, {lower: true, strict: true, remove: /[*+~.()'"!:@]/g});
|
||||||
const value = this.webc.attributes[prop];
|
const value = this.webc.attributes[prop];
|
||||||
|
|
||||||
arr.push({[attribute]: value});
|
arr.push({[attribute]: value});
|
||||||
|
|
@ -41,5 +42,5 @@
|
||||||
const result = optimize(svgContents, {plugins});
|
const result = optimize(svgContents, {plugins});
|
||||||
|
|
||||||
return result.data;
|
return result.data;
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue