Skip to content

Commit

Permalink
feat: componentize article lists
Browse files Browse the repository at this point in the history
  • Loading branch information
limulus authored Sep 28, 2024
1 parent 81a23ee commit 10f6337
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
19 changes: 19 additions & 0 deletions www/_includes/components/article-card.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<article>
<time @text="article.date.toDateString()"></time>
<h1><a :href="article.url" @text="article.data.title"></a><br /></h1>
<p class="teaser" @html="article.data.teaser"></p>
</article>

<style webc:scoped>
:host h1 {
margin: 0;
font-size: inherit;
}

:host time {
display: block;
font-size: 0.8em;
--var-font-slnt: -10;
color: #666;
}
</style>
25 changes: 25 additions & 0 deletions www/_includes/components/article-list.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script webc:setup>
const sorts = {
chron: (a, b) => a.date - b.date,
'reverse-chron': (a, b) => b.date - a.date,
}

const collate = ({ articles, order = 'reverse-chron', limit = Infinity }) => {
limit = typeof limit === 'number' ? limit : parseInt(limit, 10)
return articles.slice().sort(sorts[order]).slice(0, limit)
}
</script>

<ol>
<li webc:for="article of collate({ articles, order, limit })">
<article-card :@article="article"></article-card>
</li>
</ol>

<style webc:scoped>
:host ol {
list-style: none;
margin: 0;
padding: 0;
}
</style>
30 changes: 1 addition & 29 deletions www/penumbra/index.webc
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,4 @@ Add these links somewhere:
<li><a href="/feed.xml">RSS</a></li>
-->

<ol class="journal">
<li webc:for="entry of collections.journal.reverse()">
<article>
<time @text="entry.date.toDateString()"></time>
<h1><a :href="entry.url" @text="entry.data.title"></a><br /></h1>
<p class="teaser" @html="entry.data.teaser"></p>
</article>
</li>
</ol>

<style>
ol.journal {
list-style: none;
margin: 0;
padding: 0;
}

ol.journal h1 {
margin: 0;
font-size: inherit;
}

ol.journal time {
display: block;
font-size: 0.8em;
--var-font-slnt: -10;
color: #666;
}
</style>
<article-list :@articles="collections.journal"></article-list>
10 changes: 10 additions & 0 deletions www/penumbra/journal/index.webc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Penumbra Development Journal
layout: page
---

<header>
<h1>Penumbra Development Journal</h1>
</header>

<article-list :@articles="collections.journal"></article-list>

0 comments on commit 10f6337

Please sign in to comment.