From 945d28952f12c0b64587b2413dd67863a1be45b3 Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <the@jeffreyfreeman.me>
Date: Fri, 13 Oct 2023 14:52:54 -0400
Subject: [PATCH] Fixed the hack, I hope

---
 README.md       |  5 +++--
 clean-build.cjs | 37 +++++++++++++++++++++++++++++++++++++
 clean-build.sh  |  4 ----
 3 files changed, 40 insertions(+), 6 deletions(-)
 create mode 100644 clean-build.cjs
 delete mode 100755 clean-build.sh

diff --git a/README.md b/README.md
index ccbed51e5..5bbdc06b5 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,7 @@ change now. Finally go to the settings for the newly created project and in the
 general section add the following as an "overide" to the build command:
 
 ```bash
-hugo --gc && sh clean-build.sh
+hugo --gc && node clean-build.cjs
 ```
 
 This is a huge hack but the only solution I could find, if someone has a better
@@ -78,7 +78,8 @@ Next go to your Vercel dashboard then navigate to to your new project. In the
 settings tab there should be an `Environment Variables` section. Here is where
 we will populate those.
 
-First generate your public and private keys used for ActivityPub. It is important you dont loose these as they identify your site. So save them.
+First generate your public and private keys used for ActivityPub. It is
+important you dont loose these as they identify your site. So save them.
 
 ```bash
 npm install ts-node typescript '@types/node'
diff --git a/clean-build.cjs b/clean-build.cjs
new file mode 100644
index 000000000..e5e039433
--- /dev/null
+++ b/clean-build.cjs
@@ -0,0 +1,37 @@
+'use strict';
+
+const path = require('path');
+const fs = require('fs');
+
+const listDir = (dir, fileList = [], active = false ) => {
+
+    let files = fs.readdirSync(dir);
+
+    files.forEach(file => {
+        if (fs.statSync(path.join(dir, file)).isDirectory()) {
+            if(! ("page" === file) ) {
+              fileList = listDir(path.join(dir, file), fileList, true);
+            }
+        } else {
+            if( (/^index\.html$/.test(file)) && (active) ) {
+                const name = 'status.html';
+                let src = path.join(dir, file);
+                let newSrc = path.join(dir, name);
+                fileList.push({
+                    oldSrc: src,
+                    newSrc: newSrc
+                });
+            }
+        }
+    });
+
+    return fileList;
+};
+
+let foundFiles = listDir( './public/news');
+listDir('./public/resource', foundFiles);
+listDir('./public/projects', foundFiles);
+
+foundFiles.forEach(f => {
+   fs.renameSync(f.oldSrc, f.newSrc);
+});
diff --git a/clean-build.sh b/clean-build.sh
deleted file mode 100755
index 43733492e..000000000
--- a/clean-build.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-find public/news -name "index.html" -exec rename --all "index.html" "status.html" {} \;
-find public/projects -name "index.html" -exec rename --all "index.html" "status.html" {} \;
-find public/resource -name "index.html" -exec rename --all "index.html" "status.html" {} \;
-- 
GitLab