rustdoc icon indicating copy to clipboard operation
rustdoc copied to clipboard

Investigate the best way to load data.json

Open steveklabnik opened this issue 7 years ago • 11 comments

So, in order to preserve the ability to load off of the file system, we currently make a relative call to load data.json https://github.com/steveklabnik/rustdoc/blob/master/frontend/app/routes/application.js#L6

But, this means that if yo uhit any URL other than the root, it mis-loads it.

We should find some way to fix this. Loading with / works in every case except when you're browsing as file://. ☹️

steveklabnik avatar Jul 27 '17 16:07 steveklabnik

Hey @steveklabnik, so I'm coming into this completely out of the blue and looking for frontend-tagged issues and don't really have any Ember experience 😛 , but if the only issue is literally file:// itself and we're always in a browser, would it be sufficient to do something like fetch((document.location.protocol === 'file:' ? '/' : '') + 'data.json') (possibly exploded into multiple lines for readability)?

revin avatar Jul 28 '17 20:07 revin

that's an interesting idea! Quite possibly!

steveklabnik avatar Jul 28 '17 21:07 steveklabnik

Disclaimer: New to ember.

I'm trying to fix this, but I'm finding a bunch of questions on StackOverflow that say that you just can't run ember without a server, because the relative paths won't resolve correctly. In addition, even if you fix them, the router will break. There is an ember plugin that lets you render everything statically, but that would require us knowing all the visitable routes upfront.

Not sure if there's a solution here other than running the ember server, or booting out ember and keeping everything static.

euclio avatar Aug 01 '17 20:08 euclio

that you just can't run ember without a server, because the relative paths won't resolve correctly.

Yeah so I've seen some buggy behavior when not loading up the root, even though by loading up the root it does work.

steveklabnik avatar Aug 02 '17 14:08 steveklabnik

I think this stackoverflow post gives some insight as to why and this one. Looks like ember-cli without a server is a no go.

mgattozzi avatar Aug 02 '17 14:08 mgattozzi

Soooo I've been thinking about this, and I'm not even sure we need to load it as ajax. Consider current rustdoc, for example: the search index is a js file that defines an object, like this: https://doc.rust-lang.org/stable/search-index.js

we could do the same, and then not even make the ajax call at all, and this would remove this path issue.

steveklabnik avatar Aug 09 '17 21:08 steveklabnik

That seems reasonable. If we don't need to make any Ajax calls at all that would be great. The docs are best treated as a static site for the most part.

mgattozzi avatar Aug 09 '17 21:08 mgattozzi

Won't we still run into the same issues with ember? It would still be looking for the file at /.

On Wed, Aug 9, 2017, 5:48 PM Michael Gattozzi [email protected] wrote:

That seems reasonable. If we don't need to make any Ajax calls at all that would be great. The docs are best treated as a static site for the most part.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/steveklabnik/rustdoc/issues/76#issuecomment-321391021, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTxFmusl5ASGMyW7ml7Y6YJYhumEuu5ks5sWikpgaJpZM4OlgbW .

euclio avatar Aug 09 '17 21:08 euclio

@euclio no, because the js gets concatenated, there's only one file.

steveklabnik avatar Aug 09 '17 23:08 steveklabnik

Oh well, that'd be at build time, it'd end up being two files. Hm.

It still should work it's just figuring out how to work it into the tooling.

steveklabnik avatar Aug 11 '17 01:08 steveklabnik

Is this all going to live in the same route? If not, we would still need ember to use the server to resolve the paths correctly. If so, why not just generate static HTML from data.json?

euclio avatar Aug 28 '17 22:08 euclio