├── .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 | {{ title }}
7 | {{ title }}
7 | {{ title }}
7 |
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