JSFiddle - React, Tailwind, and code Playground
JavaScript
var posts = $(".posts .post");
var postsInfo = [];
posts.each(function () {
var info = {};
var header = $("h1.title a", this);
info.title = header.text();
info.link = header.attr("href");
info.views = $("div.views-count_post", this).text();
var commentsLink = $(".post-comments__link", this);
if (commentsLink.find(".post-comments_all").length != 0) {
info.comments = "0"; // к числу привести, или к строке?
} else {
info.comments = commentsLink.text();
}
postsInfo.push(info);
});
// > допиши к заголовкам постов в скобках число просмотров
var posts = $(".posts .post");
posts.each(function () {
var header = $("h1.title a", this);
var views = $("div.views-count_post", this).text();
header.append(" (" + views + ") ");
});