From 2569706a457d10347bf35bd3472ac538edb4bbd4 Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 27 Sep 2023 18:25:46 +0500 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A3=D0=BF=D1=80=D0=BE=D1=89=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20shortcode?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20blob?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eleventy.config.js | 57 ++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index 65dd7aa0f..9ebb2537c 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -177,44 +177,25 @@ module.exports = function(config) { // Теги - config.addNunjucksTag('blob', (nunjucksEngine) => { - return new function() { - this.tags = ['blob']; - - this.parse = function(parser, nodes) { - const token = parser.nextToken(); - - const args = parser.parseSignature(null, true); - parser.advanceAfterBlockEnd(token.value); - - return new nodes.CallExtensionAsync(this, 'run', args); - }; - - this.run = function(context, authorName, callback) { - const blobColors = [1, 2, 3, 4]; - const blobShapes = [1, 2, 3, 4, 5, 6, 7]; - const shapePrefix = 'blob--shape-'; - const colorPrefix = 'blob--color-'; - - const getBlobClass = (basis, array, name) => ( - name.concat(array[basis % array.length]) - ); - - const shapeBasis = authorName.split('').reduce( - (previous, current) => previous + current.charCodeAt(0), 0 - ); - const colorBasis = authorName.length; - - const colorClass = getBlobClass(colorBasis, blobColors, colorPrefix); - const shapeClass = getBlobClass(shapeBasis, blobShapes, shapePrefix); - - callback( - null, new nunjucksEngine.runtime.SafeString( - colorClass.concat(' ', shapeClass) - ) - ); - }; - }(); + config.addNunjucksShortcode('blob', function(authorName) { + const blobColors = [1, 2, 3, 4]; + const blobShapes = [1, 2, 3, 4, 5, 6, 7]; + const shapePrefix = 'blob--shape-'; + const colorPrefix = 'blob--color-'; + + const getBlobClass = (basis, array, name) => ( + name.concat(array[basis % array.length]) + ); + + const shapeBasis = authorName.split('').reduce( + (previous, current) => previous + current.charCodeAt(0), 0 + ); + const colorBasis = authorName.length; + + const colorClass = getBlobClass(colorBasis, blobColors, colorPrefix); + const shapeClass = getBlobClass(shapeBasis, blobShapes, shapePrefix); + + return colorClass.concat(' ', shapeClass); }); // Копирование From 523607f0883628a1628b047a3e65adb3f0f35f0a Mon Sep 17 00:00:00 2001 From: monochromer Date: Wed, 27 Sep 2023 15:18:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A3=D0=BF=D1=80=D0=BE=D1=89=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B4=D0=BE=20`addShortcode=20`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vadim Makeev --- eleventy.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eleventy.config.js b/eleventy.config.js index 9ebb2537c..e8dcbd77e 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -177,7 +177,7 @@ module.exports = function(config) { // Теги - config.addNunjucksShortcode('blob', function(authorName) { + config.addShortcode('blob', function(authorName) { const blobColors = [1, 2, 3, 4]; const blobShapes = [1, 2, 3, 4, 5, 6, 7]; const shapePrefix = 'blob--shape-';