Skip to content

Instantly share code, notes, and snippets.

@pftnhr
Last active October 26, 2023 07:05
Show Gist options
  • Save pftnhr/61fcd1a7881bb29d2a6f2272b0b4027d to your computer and use it in GitHub Desktop.
Save pftnhr/61fcd1a7881bb29d2a6f2272b0b4027d to your computer and use it in GitHub Desktop.
[datenstrom-yellow] PaperMod like archive page

yellow-archive

... creates an archive that groups blog posts by year and month using the group() function of yellow. The inspiration for this comes from the archive of the PaperMod theme for Hugo.

How it works

Save the archive.html in your system/layout folder and create a content/4-archive/page.md with the following page settings:

---
Title: Archive
Layout: archive
---
<!---------------------------
archive.html
Description: This code creates an archive in the style of Hugo's PaperMod theme. The design is your responsibility.
Created by Robert Pfotenhauer on 26.10.23.
---------------------------->
<?php $this->yellow->layout("header") ?>
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContentHtml() ?>
<?php $pages = $this->yellow->content->index()->filter("layout", "blog")->sort("published", false) ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<?php foreach ($pages->group("published", false, "Y") as $year=>$collectionYear): ?>
<div class="archive-year">
<h2><?php echo htmlspecialchars($year) ?> <sup class="archive-count">(<?php echo count($collectionYear) ?>)</sup></h2>
<?php foreach ($collectionYear->group("published", false, "F") as $month=>$collectionMonth): ?>
<div class="archive-month">
<div class="archive-month__header">
<strong><?php echo htmlspecialchars($this->yellow->lookup->normaliseDate($month)) ?> <sup class="archive-count">(<?php echo count($collectionMonth) ?>)</sup></strong>
</div>
<div class="archive-posts">
<?php foreach ($collectionMonth as $page): ?>
<div class="archive-entry">
<?php echo $page->getHtml("title") ?>
<div class="archive-meta">
<?php echo $page->getDateHtml("published") ?>
<?php echo " &middot; " . $page->parseContentShortcut("readingtime", "", "inline") . " min"; ?>
</div>
<a class="entry-link" aria-label="<?php echo $page->getHtml("title") ?>" title="<?php echo $page->getHtml("title") ?>" href="<?php echo $page->getLocation(true) ?>">&nbsp;</a>
</div>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>
</div>
<?php endforeach ?>
<?php $this->yellow->layout("footer") ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment