Skip to content

Commit 74a4ee5

Browse files
committed
add a pinned post feature
1 parent 6aa4dcb commit 74a4ee5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

.eleventy.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ module.exports = function (eleventyConfig) {
152152
});
153153
});
154154

155+
// Pin article option (add 'pinned' tag in the article)
156+
eleventyConfig.addCollection('blog', (collection) => {
157+
return collection.getFilteredByGlob('src/posts/**/*.md')
158+
.sort((a, b) => {
159+
160+
// Sort pinned posts first, then by date
161+
if (a.data.pinned && !b.data.pinned) {
162+
return -1; // a before b
163+
}
164+
else if (!a.data.pinned && b.data.pinned) {
165+
return 1; // b before a
166+
}
167+
else {
168+
// If both are pinned or neither, sort by date
169+
return (b.data.date - a.data.date); // Latest first
170+
}
171+
});
172+
});
173+
155174
// Add talks.json
156175
eleventyConfig.addPassthroughCopy({ 'src/data/talks.json': 'assets/talks.json' });
157176

0 commit comments

Comments
 (0)