peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
964 stars 65 forks source link

Don't trigger download of `examples.peggy` in docs #546

Open spenserblack opened 3 months ago

spenserblack commented 3 months ago

When I click on the link that points to js/examples.peggy, my browser triggers a download. Personally, I'd rather read the plain text in my browser, and then I'm free to download it if I want to. Perhaps there's a configuration option to allow this behavior, by recognizing .peggy as plain text?

hildjj commented 3 months ago

I'll take a PR on this. It's most likely just figuring out the correct URL.

spenserblack commented 3 months ago

Unfortunately I can't seem to reproduce this locally. Both by running the dev server or by building and serving the production build. This could be caused by the deployment server's config.

Edit: nor could I reproduce by accessing a deployment on a Codespace. So it seems to only happen at https://peggyjs.org/, not on any other deployment I've been able to make.

j4k0xb commented 2 months ago

it's a server issue, should respond with Content-Type: text/plain instead of application/octet-stream for peggy files

https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#mime-types-on-github-pages

While you can't specify custom MIME types on a per-file or per-repository basis, you can add or modify MIME types for use on GitHub Pages. For more information, see the mime-db contributing guidelines.

hildjj commented 2 months ago

Yuck. I wish they could get the MIME type from a .gitattributes entry. I guess we could ask them to add .peggy and .pegjs to their mime-db project as text/plain, but they don't have very many things in text/plain at the moment, so I bet they're going to be cautious about adding more.

I wonder if there are any other creative approaches?

j4k0xb commented 2 months ago

nvm some type starting with application/ would be more appropriate

some workarounds: code block with copy button, change the extension to .txt, serve a html file

hildjj commented 2 months ago

I could theoretically just assert that an application/x-peggy media type exists, in the docs, then ask them to add it.