From af9c1291495bfd7cf7a887744fbc866c0bc662ea Mon Sep 17 00:00:00 2001 From: fkakatie Date: Wed, 10 Jan 2024 09:36:41 -0800 Subject: [PATCH 1/2] feat: lightweight quote block --- blocks/quote/quote.css | 29 +++++++++++++++++++++++++++++ blocks/quote/quote.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 blocks/quote/quote.css create mode 100644 blocks/quote/quote.js diff --git a/blocks/quote/quote.css b/blocks/quote/quote.css new file mode 100644 index 00000000..9ccc9adf --- /dev/null +++ b/blocks/quote/quote.css @@ -0,0 +1,29 @@ +.quote blockquote { + margin: 0; +} + +.quote blockquote .quote-quotation { + flex: 1 0 100%; + font-size: 120%; +} + +.quote blockquote .quote-quotation > :first-child { + text-indent: -0.6ch; +} + +.quote blockquote .quote-quotation > :first-child::before, +.quote blockquote .quote-quotation > :last-child::after { + line-height: 0; +} + +.quote blockquote .quote-quotation > :first-child::before { + content: "“"; +} + +.quote blockquote .quote-quotation > :last-child::after { + content: "”"; +} + +.quote blockquote .quote-attribution > :first-child::before { + content: "—"; +} diff --git a/blocks/quote/quote.js b/blocks/quote/quote.js new file mode 100644 index 00000000..d6c51edf --- /dev/null +++ b/blocks/quote/quote.js @@ -0,0 +1,30 @@ +function hasWrapper(el) { + return !!el.firstElementChild && window.getComputedStyle(el.firstElementChild).display === 'block'; +} + +export default async function decorate(block) { + const [quotation, attribution] = [...block.children].map((c) => c.firstElementChild); + const blockquote = document.createElement('blockquote'); + // decorate quotation + quotation.className = 'quote-quotation'; + if (!hasWrapper(quotation)) { + quotation.innerHTML = `

${quotation.innerHTML}

`; + } + blockquote.append(quotation); + // decoration attribution + if (attribution) { + attribution.className = 'quote-attribution'; + if (!hasWrapper(attribution)) { + attribution.innerHTML = `

${attribution.innerHTML}

`; + } + blockquote.append(attribution); + const ems = attribution.querySelectorAll('em'); + ems.forEach((em) => { + const cite = document.createElement('cite'); + cite.innerHTML = em.innerHTML; + em.replaceWith(cite); + }); + } + block.innerHTML = ''; + block.append(blockquote); +} From 09792d1eaa3f1bc1c3a803d43e2bbb6964fbe96a Mon Sep 17 00:00:00 2001 From: fkakatie Date: Thu, 11 Jan 2024 14:33:58 -0800 Subject: [PATCH 2/2] style: match width to video --- blocks/quote/quote.css | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/blocks/quote/quote.css b/blocks/quote/quote.css index 9ccc9adf..e426d89d 100644 --- a/blocks/quote/quote.css +++ b/blocks/quote/quote.css @@ -1,9 +1,10 @@ .quote blockquote { - margin: 0; + margin: 0 auto; + padding: 0 32px; + max-width: 700px; } .quote blockquote .quote-quotation { - flex: 1 0 100%; font-size: 120%; } @@ -24,6 +25,10 @@ content: "”"; } +.quote blockquote .quote-attribution { + text-align: right; +} + .quote blockquote .quote-attribution > :first-child::before { content: "—"; }