<%- partial('include/header') %>

<%- partial('include/sidebar') %>

<div id="main">
    <%- partial('include/head') %>
    <div class="wrap">
        <section id="page-index">
            <% if( page.tag && page.path.indexOf('tags/') > -1 ){ %>
                <h1 class="search">标签<b><%=page.tag %></b>的搜索结果</h1>
            <% } %>
            <% page.posts.each(function(post) { %>
                <%  
                    var url;
                    if( post.link ){
                        url = url_for(post.link)
                    }else{
                        url = url_for(post.path);
                    }
                %>
                <article data-url='<%-url%>'>
                    <div class="meta">
                        <div class="date">
                            <% if (post.lang) { %>
                                <%= post.date.locale(post.lang).format(__('date_format')) %>
                            <% } else { %>
                                <%= post.date.locale(page.lang).format(__('date_format')) %>
                            <% } %>
                        </div>
                        <div class="tags">
                            <%  post.tags.each(function( tag , index ){ %>
                                <% if(index !== 0){%>
                                     , 
                                <%}%>
                                <a  href="<%= '/tags/' + tag.name  %>" data-tag="<%= tag.name.toLowerCase() %>">
                                    <%= tag.name %>
                                </a>
                            <% }) %>
                        </div>
                    </div>
                    <h1>
                        <% if (post.link) { %>
                            <a href="<%- url_for(post.link) %>">
                                <%= post.title || '(' + __('post.no_title') + ')' %>
                            </a>
                        <% } else { %>
                            <a href="<%- url_for(post.path) %>">
                                <%= post.title || '(' + __('post.no_title') + ')' %>
                            </a>
                        <% } %>
                    </h1>
                    <%
                        function delHtmlTag( str ){
                            return str.replace(/<[^>]+>/g,"");
                        }
                    %>
                    <div class="desc">
                        <% if( post.excerpt ){%>
                            <%- delHtmlTag(post.excerpt) %>
                        <%} else{ %>
                            <%- delHtmlTag(post.content) %>
                        <%} %>
                     </div>
                    <p class="more">
                        <% if (post.link && _('post.go_to_website')) { %>
                            <a href="<%- url_for(post.link) %>" target="new">
                                <%= __('post.go_to_website') %>
                            </a>
                        <% } else if (__('post.read_more')) { %>
                            <a href="<%- url_for(post.path) %>" >
                                <%- __('post.read_more') %>
                            </a>
                        <% } %>
                    </p>
                </article>
            <% }) %>
        </section>
        <%- partial('include/pagination', {type: 'page'}) %>
    </div>
</div>

<%- partial('include/footer') %>