function get_articles(single = false) { var articles; axios.get("http://136.145.231.32:8080/") .then(response => { articles = response.data; if (single) { let artName = articles[articles.length - 1]; let artNameNoExt = artName.substr(0, artName.lastIndexOf()) || artName; axios.get(`http://136.145.231.32:8080/${artName}`) .then(response => { let homeArticleParent = document.querySelector("#home-article") let articleButton = document.createElement("button"); articleButton.textContent = response.data; articleButton.classList.add("m-5", "article-content"); articleButton.setAttribute("data-toggle", "modal"); articleButton.setAttribute("data-target", "#homeArticleModal"); let modal = document.createElement("div"); modal.classList.add("modal", "fade"); modal.setAttribute("id", "homeArticleModal"); modal.setAttribute("tabindex", "-1"); modal.setAttribute("aria-labelledby", "homeArticleModalLabel"); modal.setAttribute("aria-hidden", "true"); modal.innerHTML = ` `; document.body.appendChild(modal); homeArticleParent.appendChild(articleButton); }) .catch(error => console.log(error)); } else { for (let i = 0; i < articles.length; i++) { let element = articles[i]; let elementNoExt = element.substr(0, element.lastIndexOf('.')) || element; axios.get(`http://136.145.231.32:8080/${element}`) .then(response => { let articlesHeading = document.querySelector("#articles-heading").parentElement; let articleButton = document.createElement("button"); articleButton.textContent = response.data; articleButton.classList.add("m-5", "article-content"); articleButton.setAttribute("data-toggle", "modal"); articleButton.setAttribute("data-target", `#articleModal${i}`); let modal = document.createElement("div"); modal.classList.add("modal", "fade"); modal.setAttribute("id", `articleModal${i}`); modal.setAttribute("tabindex", "-1"); modal.setAttribute("aria-labelledby", `articleModalLabel${i}`); modal.setAttribute("aria-hidden", "true"); modal.innerHTML = ` `; document.body.appendChild(modal); articlesHeading.appendChild(articleButton); }) .catch(error => console.error(error)); } } }) .catch(error => console.error(error)); }