Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebuild GDC site as a vibe.d server, converting all pages to markdown. #6

Merged
merged 3 commits into from
Jul 28, 2014

Conversation

ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Jun 22, 2014

Rather than using diet templates, it functions in the following way:

  • Receives a request object for GET /foobar
  • Translates /foobar into a path of where the markdown file is expected to be.
'/'         => /views/index.md
'/foo'      => /views/foo.md
'/foo/bar/' => /views/foo/bar.md
  • Checks if the translated path exists as a file and proceeds to render the page in the topdown order of:
  • Template header (templates/header.inc)
  • Markdown script (views/foobar.md)
  • Template footer (templates/footer.inc)
  • Sends the built page back to the response object.

The benefit of this being that templates can be loaded onto the server dynamically and without requiring a restart of the entire service to make a change.
As of writing, the memory consumption and build time was > 50% reduction in comparison to using Diet templates to compile only four pages in CTFE.

The only time when a site rebuild would be required is for fixing any of the todo listed items in src/app.d.

Before:
gdc-before

After:
gdc-after

@ibuclaw
Copy link
Member Author

ibuclaw commented Jun 22, 2014

@jpf91 - also, lets talk implementing /downloads into this server.


// Catch all GET requests and push them through our main handler.
auto router = new URLRouter;
router.get("*", toDelegate(&handleRequest));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only a single request handler, router is not necessary, you can do straight listenHTTP(settings, &handleRequest); (in fact router is implemented as multiplexing handler)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if I do it that way, wouldn't the handler need to check the type of request? (As in, discards anything that isn't a GET request)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Though I don't see why you would want to reject any other HTTP requests other than trying to go for RESTful style semantic purity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I tested various commands, all came back as bad requests, so I guess your suggestion is fine.

Yes, RESTful style semantic purity. eg: GET and POST should not perform the same action. ;-)

@jpf91
Copy link
Contributor

jpf91 commented Jun 23, 2014

@ibuclaw I think the simplest approach for downloads/index.html is using a downloads/index.json file containing the data and downloads/index.mustache containing the template. As mustache has got a D implementation, we can use it instead of compile time diet templates. Header/footer can be handled like all other pages. I guess the mustache template can generate markdown+html and we can then pass it through filterMarkdown. If you agree with this concept I can provide the code later today.

Also moving part of our email discussion here:
I actually only wanted to keep two or three releases on the download page. This way users can immediately access the previous release in case there are regressions in GDC or the frontend or if they haven't updated their code yet. All older releases can then be browsed on the FTP server.
So do you think we should provide more history and split up the page?

OT caching is probably important for the download page. @Dicebot does vibe-d have some nice caching helpers? I guess the simplest approach is to stat the template files and only re-render if the timestamp changed. However, this still produces some disk-accesses for every request. I guess for huge sites a 'fast path' which uses a time check could be useful.

string cachedSite()
{
    static string cachedString;
    static SysTime lastCheck;
    //Hopefully compiles down to a simple integer add / comparison
    if(Clock.currTime() < lastCheck + dur!msecs(100))
        return cachedString;
    else
    {
        if(sourceFileChanged())
        {
            cachedString = renderPage();
        }
        lastCheck = Clock.currTime();
        return cachedString;
    }
}

@mihails-strasuns
Copy link

@jpf91 not something I am aware of. But it can be implemented by built-in tools of reverse proxy in front of vibe.d, for example proxy_cache in case of nginx.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jun 23, 2014

@jpf91 I was thinking some sort of output range / custom AA to store cached pages.

Notable fields:

struct CacheStore
{
   immutable hash_t key;  // requestURL path
   hash_t checksum;       // mod-time & size of path
   string content;        // GC alloc'd data
}

As for downloads, I think things should be split up/separated in a nicer way. That goes perhaps for the ftp view too. If it's going to be used as an archive of releases, then the toplevel should be a directory named after the version number.

downloads/
. gdc-4.6/
. gdc-4.8/
.. 2.064.2/
.... arm-linux-eabi/
.... i686-linux-gnu/
.... x86_64-linux-gnu/
.. 2.065.0/
.... arm-linux-eabi/
.... i686-linux-gnu/
.... x86_64-linux-gnu/
. gdc-4.9/
. gdc-latest/     <-- gdc-4.9
. gdc-oldstable/  <-- gdc-4.8

But then again, maybe the downloads page can be cleaned up using only CSS changes.

@jpf91
Copy link
Contributor

jpf91 commented Jun 23, 2014

Do you think we need an archive html page for 'old releases'? Otherwise we could simply keep the most recent release on downloads.html and restructure the ftp view as you proposed.

@jpf91
Copy link
Contributor

jpf91 commented Jun 23, 2014

ibuclaw#1

@ibuclaw
Copy link
Member Author

ibuclaw commented Jun 23, 2014

I don't see a need for old releases/archives. For the D front-end, it should always be the latest (2.065). For GCC, it should be OK to keep 2 versions (4.9.x, 4.8.x) as there are those who are still on older systems. :)

@ibuclaw
Copy link
Member Author

ibuclaw commented Jun 28, 2014

And (more as a joke) with the GNU head.
g9470

@ibuclaw ibuclaw mentioned this pull request Jun 28, 2014
@AlixPexton
Copy link
Contributor

I detect clip-art in those wilder designs! The whole wolf thing was a joke anyway, one I'm starting to regret ><

I don't know if you noticed, but one of the doodle sheets I shared had a C that looked like a Gnu on its side, kinda/sorta/ifyasquintabit. I was thinking of putting it on bottom face of an inside-out cube, but it looked awful.

I also doodled a G that is made out of an n and a u stacked on top of each other, but I didn't think anyone would be interested in that.

@AlixPexton
Copy link
Contributor

I just took a look at a few reference images for inspiration, and it turns out that wolves have a dark area around their eyes that is gibbous moon shaped. Turns out I already drew some wolves without noticing ^^

@ibuclaw
Copy link
Member Author

ibuclaw commented Jun 29, 2014

I detect clip-art in those wilder designs! The whole wolf thing was a joke anyway, one I'm starting to regret ><

It's all drawn by my own hand-ish in inkscape. I say hand-ish because I'm limited to a trackpad on my laptop. I'm also not much of an artist behold simple stuff. So clip-art would be a nice way of describing my work. :)

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 28, 2014

I've actually been working on a visual overhaul since this pull: http://staging.dgnu.org

So I will go ahead and merge this (just need to do a cursory rebase to make sure everything is in order) and raise a new pull for the new-new site.

@jpf91 - Any thoughts on what I've changed on the downloads page?

ibuclaw added a commit that referenced this pull request Jul 28, 2014
Rebuild GDC site as a vibe.d server, converting all pages to markdown.
@ibuclaw ibuclaw merged commit 3b699a9 into D-Programming-GDC:master Jul 28, 2014
@jpf91
Copy link
Contributor

jpf91 commented Jul 28, 2014

The new design looks great!
But on the download page I'd either reduce the spacing between the 'host' headers and the download boxes or increase the spacing between the release archive and the 'host' header.

BTW: The download tables don't scale to well for very small windows (same problem with the old design) but I couldn't figure out how to make that work.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 30, 2014

Done! I've also right aligned the link too (as per the old design).

Yeah, I need to work out how to best layout the tables.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 31, 2014

OK, I've tweaked the downloads page, it's not as fancy as before, but it is more consistent now on smaller screens vs larger.

@jpf91
Copy link
Contributor

jpf91 commented Jul 31, 2014

That's much better :-) One last nitpick: can we keep alternating colors for the table rows?

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 31, 2014

They are alternated. Albeit there is not much difference between the two shades of grey. :)

@jpf91
Copy link
Contributor

jpf91 commented Jul 31, 2014

Weird, I could swear I used ctrl-f5 to reload the page... Anyway with caches cleared I now get these alternating colors, so I think this is good to go.

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 31, 2014

Anyway with caches cleared I now get these alternating colors, so I think this is good to go.

Files are checked for changes every 5 seconds. So time for cache to refresh is....

@ibuclaw ibuclaw deleted the markdown branch July 31, 2014 14:48
@jpf91
Copy link
Contributor

jpf91 commented Jul 31, 2014

@ibuclaw looks like the download links don't work for some reason?

@ibuclaw
Copy link
Member Author

ibuclaw commented Jul 31, 2014

I noticed. Somehow it tries to retrieve (on the server)
downloads/downloads/binaries/i686-w64-mingw32/dgreen/gcc-4.6.1-tdm64-1-gdc-6a4bafe80b-20120708-D2.058.7z

@MartinNowak
Copy link

What was the reason you decided against diet?
While diet is compiled it'd still be possible that updating the downloads.json generates a new page at runtime.

@ibuclaw
Copy link
Member Author

ibuclaw commented Nov 8, 2014

From what I recall of testing, when you make a change to a diet template, you must recompile (taking down the server with it) in order to load in the new changes.

However, I can't test now as it seems that vibe.d no longer builds with D2.065

@MartinNowak
Copy link

From what I recall of testing, when you make a change to a diet template, you must recompile (taking down the server with it) in order to load in the new changes.

Correct and interesting to hear that this was the deal breaker. I usually compile my sites on my development machine, upload the binaries and restart the systemd service. So there is no real downtime.

@ibuclaw
Copy link
Member Author

ibuclaw commented Nov 9, 2014

Correct and interesting to hear that this was the deal breaker. I usually compile my sites on my development machine, upload the binaries and restart the systemd service. So there is no real downtime.

Except for the small blip when you restart the service. ;-)

One of the nice things about this was that I can add an unlimited number of pages without the need for recompiling. I just push the changes in and they are there on the server.

@ibuclaw
Copy link
Member Author

ibuclaw commented Nov 9, 2014

However, I can't test now as it seems that vibe.d no longer builds with D2.065

Actually, I was attempting to build with my experimental copy of 2.066, hmm...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants