From a3c79ec95db61eb0670d4f0ee22e9610b85cbe85 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Mon, 7 Nov 2022 16:24:25 -0800 Subject: [PATCH] util: pull pair function into util file --- lib/util.js | 9 +++++++++ pages/community/directory.js | 10 ++-------- 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 lib/util.js diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..a9e285c --- /dev/null +++ b/lib/util.js @@ -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 + ); + }, []); \ No newline at end of file diff --git a/pages/community/directory.js b/pages/community/directory.js index e9815e2..07b8d40 100644 --- a/pages/community/directory.js +++ b/pages/community/directory.js @@ -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"],