{"id":303133,"date":"2020-02-04T09:10:25","date_gmt":"2020-02-04T16:10:25","guid":{"rendered":"https:\/\/css-tricks.com\/?p=303133"},"modified":"2020-02-06T06:08:36","modified_gmt":"2020-02-06T13:08:36","slug":"possibly-the-easiest-way-to-run-an-ssg","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/possibly-the-easiest-way-to-run-an-ssg\/","title":{"rendered":"Possibly The Easiest Way to Run an SSG"},"content":{"rendered":"\n

“Static Site Generator,” that is. We’ll get to that in a second. <\/p>\n\n\n\n

Netlify<\/a> is a sponsor of this site (thank you very much), and I see Zach Leatherman has gone to work<\/a> over there now. Very cool. Zach is the creator of Eleventy<\/a>, an SSG for Node. One thing of the many notable things about Eleventy is that you don’t even have to install it<\/em> if you don’t want to. Lemme set the stage.<\/p>\n\n\n\n\n\n\n\n

Say you have a three-page website, and one of the reasons you want to reach for an SSG is because you want to repeat the navigation on all three pages. An “HTML include,” one of the oldest needs in web development, is in there! We’ve covered many ways to do it<\/a> in the past. So we have…<\/p>\n\n\n\n

\/my_project\n- index.html\n- about.html\n- contact.html<\/code><\/pre>\n\n\n\n

And each of those HTML files needs this repeated chunk of navigation.<\/p>\n\n\n\n

<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <title>Southside Laundromat<\/title>\n  <\/head>\n  <body>\n    {{ INCLUDE NAVIGATION HERE }}\n\n    Unique content to this page.\n\n  <\/body>\n<\/html><\/code><\/pre>\n\n\n\n

Well why don’t we chuck that block of navigation into a file, so…<\/p>\n\n\n\n

\/my_project\n- \/_includes\n  - nav.html\n- index.html\n- about.html\n- contact.html<\/code><\/pre>\n\n\n\n

Which is something like…<\/p>\n\n\n\n

<nav>\n  <a href=\"\/\">Home<\/a>\n  <a href=\"\/about\/\">About<\/a>\n  <a href=\"\/contact\/\">Contact<\/a>\n<\/nav><\/code><\/pre>\n\n\n\n

So how do we actually do the include? This is where Eleventy comes in. Eleventy supports a bunch of templating languages, but the default one is Liquid<\/a>. Liquid supports file includes! Like this…<\/p>\n\n\n\n

{% include .\/nav.html %}<\/code><\/pre>\n\n\n\n

So that’s the line I put in each of the three HTML files. How do I process it then? Isn’t this the moment where I have to install<\/em> Eleventy to get that all going? Nope, I can run a single command on the command line to make this happen (assuming I have npm installed):<\/p>\n\n\n\n

npx @11ty\/eleventy<\/code><\/pre>\n\n\n\n

Here’s a 30-second video showing it work:<\/p>\n\n\n\n