Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed code changes in news #1277

Merged
merged 10 commits into from
Nov 24, 2023
2 changes: 1 addition & 1 deletion blocks/embed/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function embedAdobeIndesign(url) {
</div>`;
}

const loadEmbed = (block, link) => {
export const loadEmbed = (block, link) => {
if (block.classList.contains('embed-is-loaded')) {
return;
}
Expand Down
30 changes: 18 additions & 12 deletions templates/news/news.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { formatDate } from '../../scripts/scripts.js';
import { loadEmbed } from '../../blocks/embed/embed.js';
import {
div, i, span,
} from '../../scripts/dom-helpers.js';

import {
getMetadata, buildBlock,
Expand All @@ -14,9 +18,7 @@ function decorateTitle(parentElem, titleElem) {
function decorateCite(parentElem) {
const dt = getMetadata('publication-date');
if (dt) {
const cite = document.createElement('cite');
cite.classList.add('event-date');
cite.innerHTML = formatDate(dt);
const cite = span({ class: 'event-date' }, formatDate(dt));
parentElem.append(cite);
}
}
Expand Down Expand Up @@ -46,34 +48,37 @@ function decorateReadMore(linkElem) {
linkElem.setAttribute('target', '_blank');
linkElem.setAttribute('rel', 'noopener noreferrer');

const extLinkBtn = document.createElement('i');
extLinkBtn.classList.add('fa', 'fa-external-link');
extLinkBtn.setAttribute('aria-hidden', 'true');

const extLinkBtn = i({ class: 'fa fa-external-link', 'aria-hidden': 'true' });
linkElem.append(extLinkBtn);
}
}

function decorateEmbed(elems) {
elems.forEach((elem) => {
const embedUrl = elem.querySelector('a');
loadEmbed(elem, embedUrl.href);
embedUrl.remove();
});
}

export function decorateAutoBlock(content) {
if (!content) {
return;
}

const contentWrapper = document.createElement('span');
contentWrapper.classList.add('event-container');
const contentWrapper = span({ class: 'event-container' });

decorateTitle(contentWrapper, content.querySelector('h1'));
decorateCite(contentWrapper);

const hasLeftCol = content.querySelector('p:first-child picture');
const pic = document.createElement('div');
const pic = div();
if (hasLeftCol) {
pic.classList.add('left-col');
contentWrapper.append(pic);
}

const txt = document.createElement('div');
txt.classList.add('right-col');
const txt = div({ class: 'right-col' });

let isInleftCol = hasLeftCol;
[...content.children].forEach((child) => {
Expand All @@ -88,6 +93,7 @@ export function decorateAutoBlock(content) {
contentWrapper.append(txt);
content.append(contentWrapper);

decorateEmbed(contentWrapper.querySelectorAll('.embed'));
decorateStrong(contentWrapper.querySelectorAll('.right-col p > strong'));
decorateCaption(contentWrapper.querySelectorAll('.left-col p > picture'));
decorateCaption(contentWrapper.querySelectorAll('.right-col p > picture'));
Expand Down