├── .eslintignore ├── .gitignore ├── src ├── pages │ ├── pages.11tydata.js │ ├── about.njk │ └── index.njk ├── posts │ ├── posts.11tydata.js │ └── 2020-01-17-hello-world.njk ├── _layouts │ ├── page.html │ ├── post.html │ └── default.html ├── _data │ ├── metadata.js │ └── nav.js ├── _includes │ ├── nav.njk │ └── metatags.njk └── _11ty │ ├── layoutaliases.js │ ├── _lib.js │ ├── collections.js │ ├── shortcodes.js │ ├── filters.js │ └── .eleventy.js ├── .eslintrc.js └── package.json /.eslintignore: -------------------------------------------------------------------------------- 1 | www 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node 2 | node_modules 3 | 4 | # Eleventy 5 | www 6 | -------------------------------------------------------------------------------- /src/pages/pages.11tydata.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | layout: "page" 3 | }; 4 | -------------------------------------------------------------------------------- /src/posts/posts.11tydata.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | layout: "post" 3 | }; 4 | -------------------------------------------------------------------------------- /src/_layouts/page.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 |

PAGE

6 | {{ content | safe }} 7 |

ENDPAGE

8 | -------------------------------------------------------------------------------- /src/_layouts/post.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | --- 4 | 5 |

POST

6 | {{ content | safe }} 7 |

ENDPOST

8 | -------------------------------------------------------------------------------- /src/_data/metadata.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | title: "SITE NAME", 3 | description: "SOME KIND OF DESCRIPTION", 4 | robots: "index,follow" 5 | }; 6 | -------------------------------------------------------------------------------- /src/_includes/nav.njk: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/_data/nav.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { href: "/", label: "Home" }, 3 | { href: "/about/", label: "About" }, 4 | { href: "https://github.com/pdehaan/", label: "GitHub" } 5 | ]; 6 | -------------------------------------------------------------------------------- /src/_11ty/layoutaliases.js: -------------------------------------------------------------------------------- 1 | module.exports = config => { 2 | const aliases = ["default", "page", "post"]; 3 | for (const alias of aliases) { 4 | config.addLayoutAlias(alias, `${alias}.html`); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /src/_11ty/_lib.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | isoString(date) { 3 | return new Date(date).toISOString(); 4 | }, 5 | localeDateString(date, dateStyle = "long") { 6 | return new Date(date).toLocaleDateString([], { dateStyle }); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /src/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {%- include "metatags.njk" -%} 5 | 6 | 7 | {%- include "nav.njk" -%} 8 |
9 | {{ content | safe }} 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /src/pages/about.njk: -------------------------------------------------------------------------------- 1 | --- 2 | title: ABOUT ME 3 | permalink: about/ 4 | draft: true 5 | --- 6 | 7 |
8 |

{{ title }}

9 |
10 | 11 |

I AM AN ABOUT PAGE.

12 | 13 |

Pre excerpt

14 | 15 | 16 | 17 |

This is post excerpt.

18 | -------------------------------------------------------------------------------- /src/_11ty/collections.js: -------------------------------------------------------------------------------- 1 | module.exports = config => { 2 | config.addCollection("pages", collection => 3 | collection.getFilteredByGlob("src/pages/*.njk") 4 | ); 5 | config.addCollection("posts", collection => 6 | collection.getFilteredByGlob("src/posts/*.njk") 7 | ); 8 | }; 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true, 4 | es6: true 5 | }, 6 | extends: ["eslint:recommended"], 7 | root: true, 8 | rules: { 9 | "eqeqeq": "error", 10 | "quotes": ["error", "double"], 11 | "prefer-const": "error", 12 | "no-var": "error" 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /src/_11ty/shortcodes.js: -------------------------------------------------------------------------------- 1 | const lib = require("./_lib"); 2 | 3 | module.exports = config => { 4 | config.addShortcode("time", (date, dateStyle) => { 5 | const isoDate = lib.isoString(date); 6 | const localeDate = lib.localeDateString(date, dateStyle); 7 | return ``; 8 | }); 9 | }; 10 | -------------------------------------------------------------------------------- /src/posts/2020-01-17-hello-world.njk: -------------------------------------------------------------------------------- 1 | --- 2 | title: Hello World 3 | draft: true 4 | --- 5 | 6 | The following example shows how you can do a thing with Eleventy. 7 | 8 | 9 | 10 | First, we need to create a new package.json file using npm init -y. 11 | Next, we'll install the @11ty/eleventy dependency using npm i @11ty/eleventy -D 12 | -------------------------------------------------------------------------------- /src/_11ty/filters.js: -------------------------------------------------------------------------------- 1 | const util = require("util"); 2 | const lib = require("./_lib"); 3 | const pkg = require("../../package.json"); 4 | 5 | module.exports = config => { 6 | config.addFilter("absurl", url => new URL(url, pkg.homepage).href); 7 | config.addFilter("isoString", lib.isoString); 8 | config.addFilter("localeDateString", lib.localeDateString); 9 | 10 | config.addFilter("inspect", obj => util.inspect(obj)); 11 | }; 12 | -------------------------------------------------------------------------------- /src/pages/index.njk: -------------------------------------------------------------------------------- 1 | --- 2 | title: HOME 3 | permalink: / 4 | --- 5 | 6 |
7 |

{{ title }}

8 |
9 | 10 | This should be excerpted 11 | 12 | 13 | 14 | This is the main body of the page, the previous bit twas but an excerpt. 15 | 16 |
17 | 18 | 23 | -------------------------------------------------------------------------------- /src/_11ty/.eleventy.js: -------------------------------------------------------------------------------- 1 | const collections = require("./collections"); 2 | const filters = require("./filters"); 3 | const layoutAliases = require("./layoutaliases"); 4 | const shortcodes = require("./shortcodes"); 5 | 6 | module.exports = eleventyConfig => { 7 | collections(eleventyConfig); 8 | filters(eleventyConfig); 9 | layoutAliases(eleventyConfig); 10 | shortcodes(eleventyConfig); 11 | 12 | eleventyConfig.setDataDeepMerge(true); 13 | eleventyConfig.setQuietMode(true); 14 | eleventyConfig.setFrontMatterParsingOptions({ 15 | excerpt: true, 16 | excerpt_separator: "" 17 | }); 18 | 19 | return { 20 | dir: { 21 | input: "src", 22 | output: "www", 23 | includes: "_includes", 24 | layouts: "_layouts" 25 | }, 26 | dataTemplateEngine: "njk", 27 | htmlTemplateEngine: "njk", 28 | markdownTemplateEngine: "njk", 29 | templateFormats: ["html", "md", "njk"] 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11ty-config-dir-test", 3 | "description": "Playing around with .eleventy.js config dirs.", 4 | "version": "1.0.0", 5 | "author": "Peter deHaan (https://about.me/peterdehaan)", 6 | "devDependencies": { 7 | "@11ty/eleventy": "^1.0.2", 8 | "eslint": "^6.8.0", 9 | "npm-run-all": "^4.1.5", 10 | "prettier": "^1.19.1", 11 | "rimraf": "^3.0.1" 12 | }, 13 | "homepage": "https://examples.com", 14 | "keywords": [], 15 | "license": "MPL-2.0", 16 | "private": true, 17 | "scripts": { 18 | "11ty:build": "eleventy build --config=src/_11ty/.eleventy.js --quiet", 19 | "11ty:serve": "npm run 11ty:build -- --serve", 20 | "build": "run-s clean lint:js format:src 11ty:build format:dist", 21 | "clean": "rimraf www", 22 | "format:dist": "prettier www/*.html www/**/*.html --write --loglevel=silent", 23 | "format:src": "prettier src/**/*.{js,json,html} --write", 24 | "lint:js": "eslint .", 25 | "test": "echo \"Error: no test specified\" && exit 1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/_includes/metatags.njk: -------------------------------------------------------------------------------- 1 | {%- set $metaTitle = (renderData.title or title or metadata.title) | striptags -%} 2 | {%- set $metaDescription = (renderData.description or description or metadata.description) | striptags -%} 3 | {%- set $metaKeywords = (renderData.keywords or keywords or metadata.keywords or "") -%} 4 | {%- set $metaRobots = (renderData.robots or robots or metadata.robots) -%} 5 | {%- set $metaCanonical = (page.url) | absurl | url -%} 6 | 7 | {%- if draft -%} 8 | {%- set $metaRobots = "noindex,nofollow" -%} 9 | {%- endif -%} 10 | 11 | 12 | {{ $metaTitle }} 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | --------------------------------------------------------------------------------