feat: add archive view of posts
This commit is contained in:
parent
5e72b839fe
commit
6265474981
8 changed files with 78 additions and 10 deletions
|
@ -32,9 +32,9 @@ const getPostsByCategory = (collection) => {
|
|||
|
||||
const postsByCategory = {};
|
||||
categories.forEach((category) => {
|
||||
const categoryPosts = posts.filter((post) =>
|
||||
post.data.categories.includes(category),
|
||||
);
|
||||
const categoryPosts = posts.filter((post) => {
|
||||
return post.data.categories.includes(category);
|
||||
});
|
||||
|
||||
postsByCategory[category] = categoryPosts;
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const dayjs = require("dayjs");
|
||||
const utc = require("dayjs/plugin/utc");
|
||||
const advancedFormat = require("dayjs/plugin/advancedFormat");
|
||||
|
||||
const postcss = require("postcss");
|
||||
const cssnano = require("cssnano");
|
||||
|
@ -8,6 +9,7 @@ const values = Object.values;
|
|||
const entries = Object.entries;
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(advancedFormat);
|
||||
|
||||
const minifyCss = async (css) => {
|
||||
const output = await postcss([cssnano]).process(css, { from: undefined });
|
||||
|
@ -17,9 +19,35 @@ const minifyCss = async (css) => {
|
|||
|
||||
const formatDate = (date, format) => dayjs.utc(date).format(format);
|
||||
|
||||
const organizeByDate = (collection) => {
|
||||
const collectionByDate = {};
|
||||
|
||||
collection.forEach((item) => {
|
||||
const year = formatDate(item.date, "YYYY");
|
||||
const month = formatDate(item.date, "MMMM");
|
||||
|
||||
if (!collectionByDate[year]) {
|
||||
return (collectionByDate[year] = {
|
||||
[month]: [item],
|
||||
});
|
||||
}
|
||||
|
||||
if (!collectionByDate[year][month]) {
|
||||
return (collectionByDate[year][month] = [item]);
|
||||
}
|
||||
|
||||
collectionByDate[year][month].push(item);
|
||||
});
|
||||
|
||||
console.log(collectionByDate);
|
||||
|
||||
return collectionByDate;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
entries,
|
||||
formatDate,
|
||||
minifyCss,
|
||||
organizeByDate,
|
||||
values,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue