Splitting Jekyll files into partials
In this recipe, we will look at observing the don't repeat yourself principle. By separating our code into partials, and using Jekyll's front matter, we will achieve just that.
Getting ready
To start off, navigate to chapter10/complete/recipe2 and run the console from this folder. Start the Jekyll server by running the jekyll serve --watch console command. Open your browser, point it to localhost:4000 and preview the result. Click on some of the links on the navbar to see how it behaves.
How to do it...
- Open the folder titled
chapter10/start/recipe2in Bash. - Create a new file inside the
_layoutsfolder by typing the following command:
touch _layouts/default-layout.html
- Cut the first 11 lines from
index.htmland paste them inside_layouts/default-layout.html. Your_layouts/default-layout.htmlfile should now look like this:
<!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name...