Skip to content

Commit

Permalink
Promise.all for getLinkData() (github#25863)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe authored Mar 4, 2022
1 parent af9dbd3 commit 0d8bd53
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/get-link-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@ export default async (
return await processLink(rawLinks, context, option)
}

const links = []

for (const link of rawLinks) {
const linkObj = await processLink(link, context, option)
if (!linkObj) {
continue
} else {
links.push(linkObj)
}
}
const links = (
await Promise.all(rawLinks.map((link) => processLink(link, context, option)))
).filter(Boolean)

return links
}

const processLink = async (link, context, option) => {
async function processLink(link, context, option) {
const opts = { textOnly: true, encodeEntities: true }
// Parse the link in case it includes Liquid conditionals
const linkPath = await renderContent(link.href || link, context, opts)
Expand Down

0 comments on commit 0d8bd53

Please sign in to comment.