feat: clean up filters
Some sorely needed reorganization and pruning
This commit is contained in:
parent
e6cfa88f61
commit
ea6280226a
11 changed files with 159 additions and 176 deletions
28
config/filters/collection.js
Normal file
28
config/filters/collection.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import date from "./date.js";
|
||||
|
||||
const filterFavourites = (collection) => {
|
||||
return collection.filter(
|
||||
(item) => item.data.favourite || item.data.isFavourite,
|
||||
);
|
||||
};
|
||||
|
||||
const organizeByYear = (collection) => {
|
||||
const collectionByYear = {};
|
||||
|
||||
collection.forEach((item) => {
|
||||
const year = date.formatDate(item.date, "YYYY");
|
||||
|
||||
if (!collectionByYear[year]) {
|
||||
return (collectionByYear[year] = [item]);
|
||||
}
|
||||
|
||||
collectionByYear[year].push(item);
|
||||
});
|
||||
|
||||
return collectionByYear;
|
||||
};
|
||||
|
||||
export default {
|
||||
filterFavourites,
|
||||
organizeByYear,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue