generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.author { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |