Skip to content

Commit

Permalink
wip author block
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaret committed Jan 11, 2024
1 parent 6f35495 commit 0d3f38b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cigaradvisor/blocks/author/author.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.author {
display: flex;
flex-wrap: wrap;
}
30 changes: 30 additions & 0 deletions cigaradvisor/blocks/author/author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Loads an author.
* @param {string} path The path to the author
* @returns {HTMLElement} The root element of the author
*/
async function loadAuthor(path) {
if (path && path.startsWith('/')) {
const resp = await fetch(`${path}.plain.html`);
if (resp.ok) {
const div = document.createElement('div');
div.innerHTML = await resp.text();
return div;
}
}
return null;
}

export default async function decorate(block) {
const link = block.querySelector('a');
const path = link ? link.getAttribute('href') : block.textContent.trim();
block.innerHTML = '';
const author = await loadAuthor(path);
if (author) {
// add updated link to all author articles
const authorName = author.querySelector('h2').innerHTML;
link.textContent = `Show all ${authorName}'s Articles`;
author.append(link);
block.append(author);
}
}

0 comments on commit 0d3f38b

Please sign in to comment.