Coding is done

main
Mike Lynch 2024-12-01 12:01:03 +11:00
parent 4961a3c030
commit e76286ab9d
5 changed files with 129 additions and 14 deletions

View File

@ -4,13 +4,19 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>Damned Fort | NaNoGenMo 2024</title>
</head>
<body>
<div id="frame"></div>
<div id="header">
</div>
<div id="controls">
<input id="nextPage" type="button" value="Next" />
</div>
<div id="page"></div>
<div id="colophon">
</div>
<script type="module" src="/src/main.js"></script>
<script>
do_stuff();
</script>
</body>
</html>

55
package-lock.json generated
View File

@ -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=="
}
}
}

View File

@ -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"
}
}

View File

@ -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 = `<p>${fragments.join('<br />')}</p>`;
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();
main();

View File

@ -13,6 +13,11 @@
-moz-osx-font-smoothing: grayscale;
}
#frame {
padding: 2em;
}
a {
font-weight: 500;
color: #646cff;