<?php
/**
 * 文章归档
 * @package custom
 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
?>

<?php $this->need('header.php'); ?>

<div class="col-mb-12 col-8" id="main" role="main">
    <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
        <h1 class="post-title" itemprop="name headline">
            <a itemprop="url" href="<?php echo Helper::options()->siteUrl('archives.html'); ?>"><?php $this->title() ?></a>
        </h1>
        <div class="post-content" itemprop="articleBody">
            <?php
            $archives = [];
            $this->widget('Widget_Contents_Post_Recent', 'pageSize=1000')->to($posts);
            while ($posts->next()) {
                $year = date('Y', $posts->created);
                $month = date('m', $posts->created);
                $archives[$year][$month][] = [
                    'title' => $posts->title,
                    'permalink' => $posts->permalink,
                    'date' => date('m-d', $posts->created)
                ];
            }
            ?>

            <?php if (!empty($archives)): ?>
                <?php foreach ($archives as $year => $months): ?>
                    <h2><?php echo $year; ?></h2>
                    <?php foreach ($months as $month => $posts): ?>
                        <h3><?php echo $year . ' 年 ' . $month . ' 月'; ?></h3>
                        <ul>
                            <?php foreach ($posts as $post): ?>
                                <li>
                                    <a href="<?php echo $post['permalink']; ?>">
                                        <?php echo $post['title']; ?>
                                    </a>
                                    <span class="date">(<?php echo $post['date']; ?>)</span>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    <?php endforeach; ?>
                <?php endforeach; ?>
            <?php else: ?>
                <p class="text-muted"><?php _e('没有文章'); ?></p>
            <?php endif; ?>
        </div>
    </article>
</div>

<?php $this->need('footer.php'); ?>

<!-- CSS 样式 -->
<style>
    .post-content h2 {
        margin-top: 20px;
        font-size: 22px;
        border-bottom: 2px solid #ddd;
        padding-bottom: 5px;
    }

    .post-content h3 {
        margin-top: 15px;
        font-size: 18px;
        color: #666;
    }

    .post-content ul {
        list-style: none;
        padding: 0;
    }

    .post-content li {
        margin: 5px 0;
    }

    .post-content a {
        text-decoration: none;
        color: #333;
        font-size: 16px;
    }

    .post-content .date {
        font-size: 14px;
        color: #999;
        margin-left: 8px;
    }

    .post-content a:hover {
        text-decoration: underline;
    }
</style>




