Skip to content

Commit

Permalink
fix urls getting duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
apple1417 committed Apr 1, 2024
1 parent a8509ed commit d30147d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions assets/js/pyproject-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,24 @@ async function load_from_pyproject(url, fields) {

const urls = pyproject?.project?.urls;
if (urls) {
if (!url_box) {
url_box = document.createElement("div");
url_box.classList.add("url-box");
document.querySelector("dl.mod-desc").after(url_box);
}
const new_children = Object.entries(urls).map(([name, url]) => make_link(name, url));

if (new_children.length > 0){
if (!url_box) {
url_box = document.createElement("div");
url_box.classList.add("url-box");
document.querySelector("dl.mod-desc").after(url_box);
}

for (const [name, url] of Object.entries(urls)) {
url_box.appendChild(make_link(name, url));
url_box.replaceChildren(...new_children);

// If `pyproject.project.urls` exists, but is empty
} else {
url_box?.remove();
}

// If `pyproject.project` exists, but `pyproject.project.urls` does not/is empty

// If `pyproject.project` exists, but `pyproject.project.urls` does not
} else if (pyproject?.project) {
url_box?.remove();
}
Expand Down

0 comments on commit d30147d

Please sign in to comment.