From e76286ab9d11e6dd5f0688c9686ab4170e1be886 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sun, 1 Dec 2024 12:01:03 +1100 Subject: [PATCH] Coding is done --- index.html | 16 ++++++++---- package-lock.json | 55 ++++++++++++++++++++++++++++++++++++++++- package.json | 5 +++- src/main.js | 62 +++++++++++++++++++++++++++++++++++++++++------ src/style.css | 5 ++++ 5 files changed, 129 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index ef163c6..8482838 100644 --- a/index.html +++ b/index.html @@ -4,13 +4,19 @@ - Vite App + Damned Fort | NaNoGenMo 2024 -
+ +
+ +
+
+ +
+
- + diff --git a/package-lock.json b/package-lock.json index 93a047a..f377550 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,10 @@ "name": "damned-fort", "version": "0.0.0", "dependencies": { - "compromise": "^14.14.2" + "compromise": "^14.14.2", + "compromise-speech": "^0.1.1", + "fs-extra": "^11.2.0", + "wink-helpers": "^2.0.0" }, "devDependencies": { "vite": "^6.0.1" @@ -651,6 +654,14 @@ "node": ">=12.0.0" } }, + "node_modules/compromise-speech": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/compromise-speech/-/compromise-speech-0.1.1.tgz", + "integrity": "sha512-nTT/zi0cNQXoiwnvJVl6Sm9TLE+esHmjRHISmyPw3DtiLPagpaONFKa/rY/gCgvOGemOkr3i4jOj+gG5YtdsOw==", + "peerDependencies": { + "compromise": ">=14.0.0" + } + }, "node_modules/efrt": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/efrt/-/efrt-2.7.0.tgz", @@ -698,6 +709,19 @@ "@esbuild/win32-x64": "0.24.0" } }, + "node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -712,6 +736,11 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, "node_modules/grad-school": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/grad-school/-/grad-school-0.0.5.tgz", @@ -720,6 +749,17 @@ "node": ">=8.0.0" } }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/nanoid": { "version": "3.3.8", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", @@ -823,6 +863,14 @@ "resolved": "https://registry.npmjs.org/suffix-thumb/-/suffix-thumb-5.0.2.tgz", "integrity": "sha512-I5PWXAFKx3FYnI9a+dQMWNqTxoRt6vdBdb0O+BJ1sxXCWtSoQCusc13E58f+9p4MYx/qCnEMkD5jac6K2j3dgA==" }, + "node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/vite": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vite/-/vite-6.0.1.tgz", @@ -893,6 +941,11 @@ "optional": true } } + }, + "node_modules/wink-helpers": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/wink-helpers/-/wink-helpers-2.0.0.tgz", + "integrity": "sha512-I/ZzXrHcNRXuoeFJmp2vMVqDI6UCK02Tds1WP4kSGAmx520gjL1BObVzF7d2ps24tyHIly9ngdB2jwhlFUjPvg==" } } } diff --git a/package.json b/package.json index d584770..993d185 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "vite": "^6.0.1" }, "dependencies": { - "compromise": "^14.14.2" + "compromise": "^14.14.2", + "compromise-speech": "^0.1.1", + "fs-extra": "^11.2.0", + "wink-helpers": "^2.0.0" } } diff --git a/src/main.js b/src/main.js index 1c8ee3f..429eac8 100644 --- a/src/main.js +++ b/src/main.js @@ -1,15 +1,63 @@ -import './style.css' +import nlp from 'compromise'; +import helpers from 'wink-helpers'; -async function do_stuff() { - const r = await fetch("./moby_dick.txt"); - if( !r.ok ) { +import './style.css'; + +const CHUNK_SIZE = 1024; + +function scramble(words) { + const w = words.map(o => o.text()); + return helpers.array.shuffle(w); +} + +function make_fragments(verbs, nouns) { + const fragments = []; + while( verbs.length > 0 && nouns.length > 0 ) { + const v = verbs.pop(); + const n = nouns.pop(); + if( nouns.length > 0 && Math.random() > 0.5 ) { + const n2 = nouns.pop(); + fragments.push(`${n} ${v} ${n2}`); + } else{ + fragments.push(`${n} ${v}`); + } + } + return fragments; +} + +async function damned_fort() { + const response = await fetch("./damned.txt"); + if( !response.ok ) { throw new Error(`Response failed: ${response.status}`) } + const text = await response.text(); + + let i = 0; + return () => { + const chunk = text.substring(i, i + CHUNK_SIZE); + if( chunk ) { + const div = document.getElementById("page"); + const doc = nlp(chunk); + const v = scramble(doc.verbs()); + const n = scramble(doc.nouns()); + const fragments = make_fragments(n, v); + div.innerHTML = `

${fragments.join('
')}

`; + i +=CHUNK_SIZE; + } else { + i = 0; + } + } +} + +async function main() { + + const next_ctrl = await damned_fort(); + const next = document.getElementById("nextPage"); + + next.addEventListener("click", (e) => { next_ctrl(); }); - const text = await r.text(); - document.getElementById("frame").innerHTML = text; } -do_stuff(); \ No newline at end of file +main(); \ No newline at end of file diff --git a/src/style.css b/src/style.css index 30aa814..9d84d3e 100644 --- a/src/style.css +++ b/src/style.css @@ -13,6 +13,11 @@ -moz-osx-font-smoothing: grayscale; } +#frame { + padding: 2em; +} + + a { font-weight: 500; color: #646cff;