curiousdannii / parchment

The Interactive Fiction web app
https://iplayif.com
MIT License
421 stars 60 forks source link

Generate single-file HTML for a single story file #139

Closed dfabulich closed 9 months ago

dfabulich commented 9 months ago

Now you can run node tools/make-single-file.js --story_file ~/intfiction/LostPig.z8.

It will compute the format for the file based on file extension, then generate a parchment.html file with only the required terp and with the storyfile embedded in the HTML as a data: URI.

There is some funny business here around the format detection. In my initial implementation, I tried importing formats.js directly, but that includes import Glk from '../upstream/glkote/glkapi.js' which fails in Node because glkapi.js is ESM, but its package.json doesn't declare ESM. I've filed a separate PR https://github.com/curiousdannii/glkote/pull/11 against this.

dfabulich commented 9 months ago

It would be nice if the generated HTML had the correct <title>, and perhaps include <meta property="ifiction:ifid"> so the HTML file could be automatically associated as the "same game" as the embedded file.

But I think doing any of that would require us to pull in Babel… And, uh, I guess we'd have to make Babel somehow runnable from JS? Which I most definitely don't know how to do…

dfabulich commented 9 months ago

I'm making good progress on the iplayif.com version of this, but I need this PR to be merged in order to support data: URIs.

curiousdannii commented 9 months ago

And, uh, I guess we'd have to make Babel somehow runnable from JS? Which I most definitely don't know how to do…

I have been thinking of adding it to Emglken, but it won't be necessary if we do it server side on iplayif.com

dfabulich commented 9 months ago

Incorporated feedback. Should be ready to merge and publish to iplayif.com.

dfabulich commented 9 months ago

I don't think that test failure could be my fault. (How would I repro it?)

dfabulich commented 9 months ago

I ran ./tests/runtests.sh and it did fail:

* save/restore
* menu

Testing an Inform playable website
File not recognized: src/upstream/emglken/tests/advent.z5

  Puppeteer old Headless deprecation warning:
    In the near feature `headless: true` will default to the new Headless mode
    for Chrome instead of the old Headless implementation. For more
    information, please see https://developer.chrome.com/articles/new-headless/.
    Consider opting in early by passing `headless: "new"` to `puppeteer.launch()`
    If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.

* prologue
file:///Users/dfabulich/git/parchment/node_modules/puppeteer-core/lib/esm/puppeteer/common/Frame.js:215
                    ? new Error(`${response.errorText} at ${url}`)
                      ^

Error: net::ERR_FILE_NOT_FOUND at file:///Users/dfabulich/git/parchment/tests/Release/index.html?story=http://localhost:8080/src/upstream/emglken/tests/advent.z5&do_vm_autosave
    at navigate (file:///Users/dfabulich/git/parchment/node_modules/puppeteer-core/lib/esm/puppeteer/common/Frame.js:215:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Frame.goto (file:///Users/dfabulich/git/parchment/node_modules/puppeteer-core/lib/esm/puppeteer/common/Frame.js:181:21)
    at async CDPPage.goto (file:///Users/dfabulich/git/parchment/node_modules/puppeteer-core/lib/esm/puppeteer/common/Page.js:435:16)
    at async Runner.run_one_test (file:///Users/dfabulich/git/parchment/node_modules/regtest-html/src/runner.js:107:9)
    at async Runner.run (file:///Users/dfabulich/git/parchment/node_modules/regtest-html/src/runner.js:74:13)

… but I'm sure this couldn't have been my fault!

curiousdannii commented 9 months ago

I re-ran the tests, and they worked. Not sure what happened before, but I'll keep a watch out if it happens again.