<#assign attribute=category.attribute/>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>${(attribute.title)?has_content?then(attribute.title,category.name)!}</title>
    <meta name="keywords" content="${(attribute.keywords)!}"/>
    <meta name="description" content="${(attribute.description)!}"/>
    <style>
        nav a.selected{border-bottom:1px solid #f099f0;}
        .bread{border-bottom:1px solid #eee;}
        .pagination{list-style:none;}
        .pagination:after{content:"";display:block;clear:both;}
        .pagination .page-item{padding:0 0.3rem;float:left;}
        .pagination .page-item .page-link{margin-left:0;border-radius:0.2rem;padding:0.375rem 0.875rem;color:#999;border-color:#eee;}
        .page-item.active .page-link{background-color:#4C81E7;border-color:#eee;color:#FFF;}
    </style>
</head>
<body>
    <header data-diy="page">
        <h1>${(site.name)!}</h1>
    </header>
    <nav data-diy="category">
        <a href="${site.dynamicPath}" data-id="home">Home</a>
<@cms.categoryList>
    <#list page.list as category>
        <a href="${category.url!}" target="_blank" data-id="${category.id}" data-diy-item="${category.id}">${category.name}</a>
    </#list>
</@cms.categoryList>
    </nav>
    <main>
<#macro bread category>
    <#if category.parentIds?has_content>
        <@cms.category ids=category.parentIds>
            <#list map as k,category>
            <a href="${category.url}" data-id="${category.id}" data-diy-item="${category.id}">${category.name}</a> &gt;
            </#list>
        </@cms.category>
    </#if>
    <a href="${category.url}" data-id="${category.id}" data-diy-item="${category.id}">${category.name}</a> &gt;
</#macro>
        <p class="bread" data-diy="category"><@bread category/></p>
        <h1 data-diy="category" data-diy-id="${(category.id)!}">${(category.name)!}</h1>
    <@cms.contentList categoryId=category.id containChild=category.containChild pageIndex=pageIndex pageSize=category.pageSize>
        <ul data-diy="content">
        <#list page.list as content>
            <li data-diy-item="${content.id}">
                <h3><a href="<#if content.onlyUrl>${site.dynamicPath}content/redirect?id=${content.id}<#else>${content.url!}</#if>" target="_blank">${content.title}</a></h3>
                <p>
                    <#if content.cover?has_content><img src="${content.cover}" alt="${content.title}"/></#if>
                    ${content.description!}
                </p>
            </li>
        </#list>
        </ul>
        <ul class="pagination">
            <#if category.url?contains('?')><#assign pageParameter="pageIndex"/></#if>
            <#assign
                start=1
                end=page.totalPage
            />
            <#if (page.pageIndex-5) gt start>
                <#assign start=page.pageIndex-4/>
            </#if>
            <#if (page.pageIndex+5) lt end>
                <#assign end=page.pageIndex+4/>
            </#if>
            <li class="page-item"><a class="page-link" href="${getPage(category.url,page.prePage,pageParameter)}">Previous page</a></li>
            <#if start gt 1>
                <li class="page-item"><a class="page-link" href="${category.url}">1</a></li>
                <li class="page-item"><span class="page-link">...</span></li>
            </#if>
            <#list start..end as n>
                <li class="page-item<#if n=page.pageIndex> active</#if>"><a class="page-link" href="${getPage(category.url,n,pageParameter)}">${n}</a></li>
            </#list>
            <#if end lt page.totalPage>
                <li class="page-item"><span class="page-link">...</span></li>
                <li class="page-item"><a class="page-link" href="${getPage(category.url,page.totalPage,pageParameter)}">${page.totalPage}</a></li>
            </#if>
            <li class="page-item"><a class="page-link" href="${getPage(category.url,page.nextPage,pageParameter)}">Next page</a></li>
        </ul>
    </@cms.contentList>
        <aside>
            <h3>Popular content</h3>
            <ul data-diy="content">
        <@cms.contentList categoryId=category.id containChild=true orderField='clicks' pageSize=10>
            <#list page.list as content>
                <li data-diy-item="${content.id}"><a href="<#if content.onlyUrl>${site.dynamicPath}content/redirect?id=${content.id}<#else>${content.url!}</#if>" target="_blank">${content.title}</a><span>${content.clicks}</span></li>
            </#list>
        </@cms.contentList>
            </ul>
        </aside>
    </main>
    <script>
    var itemString="itemType=category&itemId=${category.id}";
    var templatePath='${.current_template_name?keep_after('/')}';
    </script>
<#-- footer -->
    <footer>
        Copyright &copy; ${.now?string('yyyy')}
    </footer>
    <script src="${site.dynamicPath}resource/js/cms.support.js"></script>
    <script>
    var ca = cmsAnalytics();
    var url="${site.dynamicPath}api/visit/record";
    if("string" ==typeof itemString){
        url=url+"?"+itemString;
    }
    ca.setDomain("${site.sitePath?keep_after('//')?keep_before('/')?keep_before(':')}");
    ca.setPath("/");
    ca.report(url);
    </script>
<#-- end footer -->
    <script>
    var bread = document.querySelector('.bread a:first-child');
    if(bread)
        var nav = document.querySelector('nav a[data-id="'+bread.getAttribute("data-id")+'"]');
        if(nav){
            nav.className="selected";
        }
    }
    </script>
</body>
</html>