diff --git a/src/ts/app.ts b/src/ts/app.ts index 4d3cee9..bcbbf71 100644 --- a/src/ts/app.ts +++ b/src/ts/app.ts @@ -1,6 +1,7 @@ import API from "./API"; import UI from "./UI"; import Input from "./Input"; +import Author from "./Author"; const pkg = require("../../package.json"); @@ -35,12 +36,20 @@ declare const Prism: any; const blogPostContainer = UI.blogPostContainer; if (blogPostContainer) { + const authors = []; const template = Handlebars.compile(UI.blogPostTemplate.innerHTML); API.getBlogPostCount().then(async (count) => { for (let i = 0; i < count; i++) { const posts = await API.getBlogPosts(i, 5); for (const post of posts) { - const author = await API.getAuthor(post.authorId); + let author: Author; + if (authors[post.authorId]) { + author = authors[post.authorId]; + } else { + author = await API.getAuthor(post.authorId); + authors[post.authorId] = author; + } + const card = UI.createBlogPostCard(template, post, author); blogPostContainer.appendChild(card); UI.updateUI(card);