Static Website "compiler"?

Status
Not open for further replies.

Jeff S

Ars Legatus Legionis
11,961
Subscriptor++
Hello,

Over the past 10 years or so, I've dabbled in web development, off and on, mostly doing a combination of hand-written html, and php. One of the things I liked to do with php is to create common blocks of code (like a menu bar at the top or side of the pages, or a copyright notice at the bottom of pages), save those code blocks to files, then use php's include() function to include them in my web pages. This allowed me to maintain a single copy of those 'widgets', change them, and have the results reflected on all the pages from the website.

Recently, I've been thinking that running php at runtime for such use seems like it has a number of possible downsides:

* As a site scales in page requests, it adds a lot of extra burden for content which isn't truly dynamic - invoking the php script interpreter/compiler to parse the php source page and re-generate what amounts to the same page every time.

* Any potential security vulnerabilities in php become a potential threat to my site, which if I'm not doing something truly dynamic, seems to be an unnecessary increase in my 'vulnerability footprint'.

So, I wonder, are there any technologies which allow you to generate static pages from templates, doing replacement? Are there any features of php, perl, python, etc which would make it easy to do such a thing without a 'special purpose' tool to 'compile' the static pages for the website? I'm thinking about this, and I suspect I could use PHP, but instead of setting up my website (and links) to access/link files like page_xyz.php, I just tell them to access page_xyz.htm, then from the command line (possibly via a shell script or Makefile), invoke php, passing it page_xyz.php and then saving the output to page_xyz.htm?
 

Jonathon

Ars Legatus Legionis
17,646
Subscriptor
gaijin":cbcyw8c8 said:
Sounds like this could be useful:
http://www.mickgardner.com/2011/04/27/A ... ators.html
As that article recommends, I use Jekyll for my personal site/blog... it can be a bit blog-centric, but its templating engine works well for the sort of stuff you want to do (lots of static content with a common header, footer, or menu area). Actual content (both blog posts and actual pages) can be HTML, or Textile or Markdown if you want to write in something a bit more human readable.

Hosted on Github's infrastructure (Github Pages), it's pretty fast and very easy to use (you push your Jekyll templates and content to a repo on Github, and it invokes Jekyll automatically to build the static site that they serve). No idea how easy it would be to automate for your own infrastructure, but it should be just about as fast everywhere (limited by your available bandwidth, of course).

If you want an example of what a Jekyll site looks like (since the linked article doesn't give one), the source of my site is available here... static pages are in the root directory, page templates are in _layouts/, and blog posts are in _posts/.
 

chaboud

Ars Centurion
313
Subscriptor
Static saving of pages isn't unheard of. Movable Type did this, and it's not at all uncommon to do this with php. Just take the php output and save it to a .htm file. You could have regeneration of the static pages be a periodic action or a manual one.

You could also start getting html5-y and have static sections of pages fetched by thin frame requests.

I'm not a webby person, so you're probably best off waiting for someone who knows what they're really doing. Still, I suspect that you have a *broad selection* of possible answers.
 

HitScan

Ars Tribunus Militum
2,523
Subscriptor++
It's very low-level and not the most flexible thing, but if you have several parts each in their own file (such as a nav bar, side menu, social plugin stuff, etc.) you could build the site around your content by using C pre-processor style defines and includes (putting #include "file" at the far left margin where another file should be included) then you can build pages by running a compiler with a pre-processor only flag. You could also put all of the included files in an out-of-the-way location, and specify it on the command line with an -I flag to separate your content and layout if you're so inclined. Finally, if you're dealing with a site where new pages aren't added very often, you could even set up a makefile to rebuild all of the content pages at once when you change an included file or do more involved processing.

There may be better solutions depending on your skill level, but if you know anything about basic development don't overlook the tools you may already have.
 

Jeff S

Ars Legatus Legionis
11,961
Subscriptor++
Tornadus":2kxsygwg said:
I don't mean to offend anyone, but from the description of Jeff's problem he may not know enough about setting up a caching proxy.

Since you already know some PHP, Jeff, would you mind using a PHP library that offers the same modular functionality of your setup, plus caching?

If you don't, you can use something like Twig.

As far as setting up a caching proxy, I'm using a shared web host, so I don't believe I can actually setup a separate service on the web server. However, something like a php library might be something I can setup, as I can probably 'install' the library files into my own home directory somewhere, and have PHP open/invoke the files. I'll check out Twig. Other people also suggested some other ideas, so I'll look into those too.

Thanks everyone.
 
I suspect you'll still want some CMSy features (categories, sort posts by date, etc) even if you're serving static files, and simply doing server side includes or the like is not going to get those features for you. So I'd suggest looking for a static site generator app. Someone already mentioned Jekyll. I use that and like it alright. It's written in Ruby, although you shouldn't need to know much Ruby syntax to get going (I didn't know any Ruby when I started with it). That said, if you don't already know Liquid/Markdown syntax and don't want to learn, you might not like Jekyll. There is a Python translation called "Hyde" too.

As previously mentioned, Movable Type and other PHP CMS's can generate static pages for you. I'm guessing there is probably some PHP equivalent of Jekyll by now.
 

Jonathon

Ars Legatus Legionis
17,646
Subscriptor
npHardProblem":3k8yhciq said:
I suspect you'll still want some CMSy features (categories, sort posts by date, etc) even if you're serving static files, and simply doing server side includes or the like is not going to get those features for you. So I'd suggest looking for a static site generator app. Someone already mentioned Jekyll. I use that and like it alright. It's written in Ruby, although you shouldn't need to know much Ruby syntax to get going (I didn't know any Ruby when I started with it). That said, if you don't already know Liquid/Markdown syntax and don't want to learn, you might not like Jekyll. There is a Python translation called "Hyde" too.
I don't know Ruby, and I use Jekyll just fine... you'll need Ruby (and RubyGems) installed to get Jekyll running, but you should never have to write Ruby code to use Jekyll.

Likewise, Markdown isn't necessary (although you don't get the most out of Jekyll if you're not using Markdown or Textile, because they make writing and adding content really easy). Liquid (the templating engine Jekyll uses) is the only likely sticking point for a new user since its syntax is different than PHP... otherwise, you're really just writing HTML.
 
Status
Not open for further replies.