<%
    let posts = site.posts,
        current = (page.current - 1) * config.index_generator.per_page;
    posts.data.sort((a, b) => {
        let x = a.pinned ?? 0,
            y = b.pinned ?? 0;
        return x === y ? b.date - a.date : y - x;
    });
    posts = posts.slice(current, config.index_generator.per_page + current);
%>
<% posts.forEach(post => { %>
<div class="post">
    <a href="<%- url_for(post.path) %>">
        <h2 class="post-title"><%= post.title %></h2>
    </a>
    <div class="category-and-date">
        <% if (post.categories.data.length !== 0) { %>
        <span class="category">
            <a href="<%- url_for(post.categories.data[0].path) %>">
                <span class="icon">
                    <i class="fa-solid fa-bookmark fa-fw"></i>
                </span>
                <%= post.categories.data[0].name %>
            </a>
        </span>
        <% } %>
        <span class="date">
            <span class="icon">
                <i class="fa-solid fa-calendar fa-fw"></i>
            </span>
            <%- date(post.date, "YYYY/M/D") %>
        </span>
        <% if (theme.crypto.enable && typeof post.secret !== "undefined") { %>
        <span class="special">
            <i class="fa-solid fa-lock fa-fw"></i>
        </span>
        <% } %>
        <% if (typeof post.pinned !== "undefined") { %>
        <span class="special">
            <i class="fa-solid fa-grip-vertical fa-fw"></i>
        </span>
        <% } %>
    </div>
    <div class="description">
        <div class="content" v-pre>
            <% if (typeof post.description !== "undefined") { %>
            <%- markdown(post.description) %>
            <% } else if (post.excerpt) { %>
            <%- post.excerpt %>
            <% } else { %>
            <%- post.content %>
            <% } %>
        </div>
    </div>
    <div class="post-tags">
        <% if (post.tags.data.length !== 0) { %>
        <span class="icon">
            <i class="fa-solid fa-tags fa-fw"></i>
        </span>
        <% } %>
        <% post.tags.data.forEach(data => { %>
        <span class="tag">
            <%
                const color = [
                    "color: #ffa2c4",
                    "color: #00bcd4",
                    "color: #03a9f4",
                    "color: #00a596",
                    "color: #ff7d73",
                ];
                let id = Math.floor(Math.random() * color.length);
            %>
            <a href="<%- url_for(data.path) %>" style="<%- color[id] %>"><%= data.name %></a>
        </span>
        <% }); %>
    </div>
    <a href="<%- url_for(post.path) %>" class="go-post">阅读全文</a>
</div>
<% }); %>
