util: pull pair function into util file

This commit is contained in:
Matilde Park 2022-11-07 16:24:25 -08:00
parent 798d4f16fa
commit a3c79ec95d
2 changed files with 11 additions and 8 deletions

9
lib/util.js Normal file
View File

@ -0,0 +1,9 @@
// Organises arrays into arrays of pairs
// Used mostly for TwoUps + content
export const pair = (arr) =>
arr.reduce(function (rows, key, index) {
return (
(index % 2 == 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) &&
rows
);
}, []);

View File

@ -13,6 +13,8 @@ import Card from "../../components/Card";
import Meta from "../../components/Meta";
import Header from "../../components/Header";
import Footer from "../../components/Footer";
import { pair } from '../../lib/util';
export default function Directory({ search, directory }) {
const post = {
title: "Directory",
@ -156,14 +158,6 @@ export default function Directory({ search, directory }) {
);
}
const pair = (arr) =>
arr.reduce(function (rows, key, index) {
return (
(index % 2 == 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) &&
rows
);
}, []);
export async function getStaticProps() {
const directory = getAllPosts(
["name", "title", "patp", "org", "content"],