From ff3f53817112ec142c3ec9d6124424a05454dc7c Mon Sep 17 00:00:00 2001
From: Cory Dransfeldt <hi@coryd.dev>
Date: Sat, 12 Oct 2024 16:39:49 -0700
Subject: [PATCH] fix: don't mutate shuffled arrays

---
 config/utilities/index.js             | 11 ++++++-----
 package-lock.json                     |  4 ++--
 package.json                          |  2 +-
 src/pages/dynamic/watching/index.html |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/config/utilities/index.js b/config/utilities/index.js
index 8dbc3b10..34d8eeb0 100644
--- a/config/utilities/index.js
+++ b/config/utilities/index.js
@@ -1,11 +1,12 @@
 export const shuffleArray = array => {
-  for (let i = array.length - 1; i > 0; i--) {
+  const shuffled = [...array]
+  for (let i = shuffled.length - 1; i > 0; i--) {
     let j = Math.floor(Math.random() * (i + 1))
-    let temp = array[i]
-    array[i] = array[j]
-    array[j] = temp
+    let temp = shuffled[i]
+    shuffled[i] = shuffled[j]
+    shuffled[j] = temp
   }
-  return array
+  return shuffled
 }
 
 export const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })
diff --git a/package-lock.json b/package-lock.json
index 3a55d2d3..8103e19b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "coryd.dev",
-  "version": "1.0.5",
+  "version": "1.0.6",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "coryd.dev",
-      "version": "1.0.5",
+      "version": "1.0.6",
       "license": "MIT",
       "dependencies": {
         "@cdransf/api-text": "^1.5.0",
diff --git a/package.json b/package.json
index e3099be6..991a8ca7 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "coryd.dev",
-  "version": "1.0.5",
+  "version": "1.0.6",
   "description": "The source for my personal site. Built using 11ty (and other tools).",
   "type": "module",
   "scripts": {
diff --git a/src/pages/dynamic/watching/index.html b/src/pages/dynamic/watching/index.html
index c5209a8a..be9ee38b 100644
--- a/src/pages/dynamic/watching/index.html
+++ b/src/pages/dynamic/watching/index.html
@@ -6,7 +6,7 @@ permalink: "/watching/index.html"
 updated: "now"
 schema: watching
 ---
-{% assign featuredMovie = movies.recentlyWatched | shuffleArray | first %}
+{%- assign featuredMovie = movies.recentlyWatched | shuffleArray | first -%}
 <h2 class="watching">{{ title }}</h2>
 {% render "partials/media/watching/hero.liquid" movie:featuredMovie %}
 <p>Here's all of the TV and movies I've been watching presented in what is (hopefully) an organized fashion.</p>