flobrosch / valadoc-org

32 stars 5 forks source link

Serverside #65

Open btkostner opened 8 years ago

btkostner commented 8 years ago

Stop this madness!

This makes the index.php page render any template file. Basically making valadoc work without the need for javascript (yay?). The added benifit being that we can link files with nice, normal urls like such: http://localhost:7777/glib-2.0/GLib.FileUtils.html. I kept the old hash logic for anyone who still uses those. I also kept the client side page loading, but that could be removed without complication if we choose to.

This changes the way deployment is! You will need your nginx (or whatever your pick is) to try to return a file if it already exists, and fallback to the index.php script if no file is found.

Random other fixes:

Testing welcome ;)

ZanderBrown commented 8 years ago

the PHP part of me says do it, the JavaScript part says 'Noooo'.

The rest of me wishes we could use Vala instead of PHP :smile: .

While the current system is not ideal, not a fan of hashbang URLs either, putting it all server side isn't necessarily the best fix. All we achieve there is extra work for the server.

btkostner commented 8 years ago

It's not really doing extra work though. It's just interpreting real paths instead of hashes. Javascript is still doing the page loading after it's initial load as well, so there is that small speed boost.

As far as the back end, It just needs to stop being a jumble of different tech. I'm not a fan of the build system creating markup templates. Sadly that seems to be the biggest hurdle in redoing the site.

lewisgoddard commented 8 years ago

I agree, this doesn't technically generate any new server workload, just different work.

roojs commented 8 years ago

From the other ticket #56

I'd agree on the comments about doing everything in two or more places, it's a more than a bit confusing.

having to get .htaccess+nginx config correct plus php redirecting etc... - the bulk looks like it's already done in Javascript, so it looks better to keep the rest as simple as possible..

Something like at the top of the PHP code - and remove all the readfile() - would improve the security and simplicity no-end.

if(!empty($_SERVER['PATH_INFO'])) {
        header('Location: /index.php#!api='.preg_replace('/\.html$/','', $_SERVER['PATH_INFO']));
        exit;
}
if(!empty($_GET['page'])) {
        header('Location: /index.php#!api='.preg_replace('/\.html$/','', $_GET['page']));
        exit;
}
``
btkostner commented 8 years ago

Sorry for the late reply. I agree with the header redirect for api pages. This should reduce the complexity of the PHP side quite a bit. I'll fix it soon.

Although, I would REALLY recommend removing this javascript rendering logic, and doing strictly PHP with clean URLs.

benwaffle commented 8 years ago

Would it be better if the urls were http://localhost:7777/glib-2.0/GLib.FileUtils, i.e. /{pkg}/{class}

lewisgoddard commented 8 years ago

That would require additional server-side logic, I think. It would certainly be possible though.

btkostner commented 8 years ago

Alright. As a community we need to decide on this. Ignoring the implementation question, please answer how you want URLs. Voting closes on September 25th (little over a week).

:laughing: for urls like /{pkg}/{class} :heart: for urls as they currently are like #!wiki=cairo/index

ZanderBrown commented 8 years ago

I'm in the 😄 group but we would have to be careful of the various site that use ❤️ links

lewisgoddard commented 8 years ago

We should still be able to redirect from the hashed links to the correct page, no?

btkostner commented 8 years ago

Yes, but it will need to be client side, as hashes are not sent to the server

lewisgoddard commented 8 years ago

I understand that, but a javascript snippet to redirect shouldn't be difficult. It only needs to be on the homepage.

ZanderBrown commented 8 years ago

assuming

http://www.valadate.org:8000/#!api=gtk+-3.0/Gtk.AboutDialog

becomes

http://www.valadate.org:8000/gtk+-3.0/Gtk.AboutDialog

then

window.addEventListener('load', function() {
    location = location.hash.substr(6);
});

should work fine.

although URLs like

http://www.valadate.org:8000/#!wiki=gtk+-3.0/index

require further thought as my suggestion would redirect to

http://www.valadate.org:8000/=gtk+-3.0/index

EDIT

window.addEventListener('load', function() {
    if (location.hash.substr(2, 3) == 'api') {
        location = location.hash.substr(6);
    } else {
        location = location.hash.substr(7);
    }
});

that should do it

lewisgoddard commented 8 years ago

To redirect: /#!api=gtk+-3.0/index to /gtk+-3.0/index and /#!wiki=gtk+-3.0/index to /gtk+-3.0/index

window.addEventListener('load', function() {
  if (
    location.hash.substr(2, 3) == 'api' ||
    location.hash.substr(2, 4) == 'wiki'
  ) {
    redirect_to = location.hash.split('=')
    location = '/' + redirect_to[1]
  }
});
ZanderBrown commented 8 years ago

@lewisgoddard or that could work.... 😄

lewisgoddard commented 8 years ago

@ZanderBrown My thought was that way whatever that first string is you just have to check for it, makes it easier to add new possibilities in case we missed any.