generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from famous-smoke/52-related-articles
Add related articles
- Loading branch information
Showing
5 changed files
with
63 additions
and
24 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,7 @@ | ||
.sidebar-related-articles a::before { | ||
content: url('/best-cigars-guide/icons/external-link.svg'); | ||
display: inline-block; | ||
width: 12px; | ||
height: 12px; | ||
padding-right: 0.5em; | ||
} |
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,33 @@ | ||
export default async function decorate(block) { | ||
const links = block.querySelectorAll(':scope > div'); | ||
if (!links || links.length === 0) { | ||
return; | ||
} | ||
|
||
const wrap = document.createElement('div'); | ||
wrap.className = 'sidebar-related-articles'; | ||
|
||
const heading = document.createElement('h3'); | ||
heading.textContent = 'Related Articles'; | ||
wrap.append(heading); | ||
|
||
const list = document.createElement('ul'); | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const link of links) { | ||
const el = document.createElement('li'); | ||
|
||
const linkEl = document.createElement('a'); | ||
linkEl.textContent = link.firstElementChild.textContent; | ||
linkEl.href = link.lastElementChild.textContent; | ||
linkEl.target = '_blank'; | ||
el.appendChild(linkEl); | ||
|
||
list.appendChild(el); | ||
} | ||
|
||
wrap.append(list); | ||
|
||
const sidebar = document.querySelector('.sidebar-wrapper > div.sidebar'); | ||
sidebar.append(wrap); | ||
block.remove(); | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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