From ba37db91828c9292d24a87269dbfcf1302ae8fd3 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 21 Jan 2022 02:11:40 +0300 Subject: [PATCH] Stack images --- post2Svg.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/post2Svg.js b/post2Svg.js index ca514cf..8c96c1b 100644 --- a/post2Svg.js +++ b/post2Svg.js @@ -1,12 +1,34 @@ -function makeSvg(image) { - image = image.replaceAll('&', '&') +function makeSvg(images) { + const spacing = 50; + const height = images.length * (900 + spacing) + spacing; - return ` + function imageTag(url, n) { + const y = 50 + n * (900 + spacing); + return ``; + } + + let imageTags = ''; + + images.forEach((image, i) => { + imageTags += imageTag(image.url, i); + }) + + return ` - -`; + ${imageTags} +\n`; } export default function(post) { - return makeSvg(post.attachments[0].photo.sizes[0].url) -} \ No newline at end of file + const photoAttachments = post.attachments.filter((attachment) => { + return attachment.photo; + }) + + const images = photoAttachments.map((attachment) => { + return { + url: attachment.photo.sizes[attachment.photo.sizes.length - 1].url.replaceAll('&', '&'), + }; + }); + + return makeSvg(images); +}