├── .gitignore ├── site └── blog │ ├── blog.json │ ├── post1 │ └── index.md │ ├── post2 │ └── index.md │ └── post3 │ └── index.md ├── .eleventy.js ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | dist 4 | -------------------------------------------------------------------------------- /site/blog/blog.json: -------------------------------------------------------------------------------- 1 | { 2 | "permalink": "/{{ page.fileSlug }}.html" 3 | } 4 | -------------------------------------------------------------------------------- /site/blog/post1/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BLOG POST 1 3 | --- 4 | 5 |
6 |

{{ title }}

7 |
8 | -------------------------------------------------------------------------------- /site/blog/post2/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BLOG POST 2 3 | --- 4 | 5 |
6 |

{{ title }}

7 |
8 | -------------------------------------------------------------------------------- /site/blog/post3/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: BLOG POST 3 3 | --- 4 | 5 |
6 |

{{ title }}

7 |
8 | 9 |
10 | {{ page | toJson | safe }}
11 | 
12 | -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | module.exports = function (eleventyConfig) { 2 | 3 | eleventyConfig.addFilter("toJson", (value) => JSON.stringify(value, null, 2)); 4 | 5 | return { 6 | dir: { 7 | input: "site", 8 | output: "dist" 9 | } 10 | }; 11 | }; 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 11ty-1444 2 | 3 | > ## Q: How can I serve collection from root? (blog) 4 | > I'm moving my WP blog over to eleventy. 5 | > I have a posts collection in /site/blog/post1/index.md and this is rendered as /dist/blog/post1/index.html. 6 | > I would like yo serve it from the root of my site so it should become /dist/post1/index.htm. 7 | > So like http://example.com/blog/post1.html should be http://example.com/post1.html actually. 8 | > How can I do that? 9 | 10 | ## A: Create a [Data Directory File](https://www.11ty.dev/docs/data-template-dir/) 11 | In this case, we can create a [site/blog/blog.json](site/blog/blog.json) config file and set a custom `permalink` property which will cascade to all the files in the site/blog/** directory. 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11ty-1444", 3 | "description": "How can I serve collection from root? (blog)", 4 | "version": "1.0.0", 5 | "author": "Peter deHaan (https://about.me/peterdehaan)", 6 | "bugs": { 7 | "url": "https://github.com/pdehaan/11ty-1444/issues" 8 | }, 9 | "dependencies": {}, 10 | "devDependencies": { 11 | "@11ty/eleventy": "^0.11.0" 12 | }, 13 | "homepage": "https://github.com/pdehaan/11ty-1444#readme", 14 | "keywords": [], 15 | "license": "MPL-2.0", 16 | "main": "index.js", 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/pdehaan/11ty-1444.git" 20 | }, 21 | "scripts": { 22 | "build": "eleventy", 23 | "test": "echo \"Error: no test specified\" && exit 1" 24 | } 25 | } 26 | --------------------------------------------------------------------------------