From 9276e234ef2683a0cbfe37ce6c0b56d5fe8e19ed Mon Sep 17 00:00:00 2001 From: Nick Lamicela Date: Fri, 27 Dec 2024 22:46:03 -0800 Subject: [PATCH] neocities test --- package-lock.json | 10 ++++++++++ package.json | 1 + tools/neocities/test.html | 1 + tools/publish-neocities.js | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 tools/neocities/test.html create mode 100644 tools/publish-neocities.js diff --git a/package-lock.json b/package-lock.json index 6be1d36..d3a6ad8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "jsdom": "^25.0.1", "luxon": "^3.3.0", "markdown-it-anchor": "^8.6.7", + "neocities": "^0.0.3", "sharp": "^0.33.5" }, "engines": { @@ -2333,6 +2334,15 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/neocities": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/neocities/-/neocities-0.0.3.tgz", + "integrity": "sha512-veH8WhrNz7l3YhSA2y6EHokCy45F19hUs14N3e1oVk5MWwg39bG7AeC9xp7WpdLqRkHQjy86J3aOy5Xvf3vslQ==", + "license": "BSD-2-Clause", + "dependencies": { + "form-data": "*" + } + }, "node_modules/node-retrieve-globals": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/node-retrieve-globals/-/node-retrieve-globals-6.0.0.tgz", diff --git a/package.json b/package.json index b2c1a94..d545710 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "jsdom": "^25.0.1", "luxon": "^3.3.0", "markdown-it-anchor": "^8.6.7", + "neocities": "^0.0.3", "sharp": "^0.33.5" } } diff --git a/tools/neocities/test.html b/tools/neocities/test.html new file mode 100644 index 0000000..90d3d88 --- /dev/null +++ b/tools/neocities/test.html @@ -0,0 +1 @@ +hello from node.js! diff --git a/tools/publish-neocities.js b/tools/publish-neocities.js new file mode 100644 index 0000000..a807afa --- /dev/null +++ b/tools/publish-neocities.js @@ -0,0 +1,27 @@ +import fs from 'node:fs/promises'; +import path from 'node:path'; +import dotenv from 'dotenv'; +import Neocities from 'neocities' + +const uploadDir = 'tools/neocities'; + +async function listFiles() { + const files = []; + for (let name of await fs.readdir(uploadDir, { recursive: true })) { + const file = path.join(uploadDir, name); + const stat = await fs.stat(file); + if (stat.isDirectory()) continue; + files.push({ name: name, path: file }); + } + return files; +} + +async function main() { + dotenv.config(); + const api = new Neocities(process.env.NEOCITIES_USERNAME, process.env.NEOCITIES_PASSWORD); + const files = await listFiles(); + const response = await new Promise(cb => api.upload(files, cb)); + console.log(response); +} + +main();