11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.18k stars 494 forks source link

Output files are all in directories #584

Closed jonahsnider closed 5 years ago

jonahsnider commented 5 years ago

Eleventy is putting file.md into _site/file/index.html rather than _site/file.html. It's putting files in their own folders by default, which I want to disable. I can't find an option in the config to disable this.

psalaets commented 5 years ago

This might not be the best way, but you can set the permalink to a value that ends with .html.

permalink: /file.html generates _site/file.html

You don't need to duplicate that in every page's frontmatter because a layout's frontmatter is inherited by pages that use the layout and permalinks can be templated.

So assuming your pages all use a common layout, set the permalink template once in the layout's frontmatter, maybe using the fileSlug variable.

Your page layout (i.e. _includes/layouts/page.njk):

---
permalink: "/{{ page.fileSlug }}.html"
---
{{ content | safe }}

file.md:

---
layout: layouts/page
---
words here

If fileSlug doesn't quite work for you, you could use some of the other page data properties and a custom filter in the permalink template.

YMMV

Links to relevant docs

zachleat commented 5 years ago

A new 0.9.0 feature will assist you with defining these permalinks. See https://www.11ty.io/docs/data/#filepathstem

zachleat commented 5 years ago

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and I will reopen the issue. Thanks!

shama230 commented 4 years ago

Hi Everyone,

I am quite new to 11ty.. I wanted to check if each directory in 11ty should have new folder and inside that folder should be index.html? Cant we have one common directory e.g. (Public) and have separate file name as that of folder name ?

Thanks

omartan commented 3 years ago

@psalaets I tried the permalink route, doesn't seem to work as all the links in the page is still something like /products/ instead of /products.html so I ended up with broken links and broken images

Ryuno-Ki commented 3 years ago

@omartan Can you share exactly what you used? In which file?

boehs commented 2 years ago

A new 0.9.0 feature will assist you with defining these permalinks. See https://www.11ty.io/docs/data/#filepathstem

https://www.11ty.dev/docs/data-eleventy-supplied/#filepathstem

....

Cool URIS don't change 😉

flameddd commented 1 year ago

Add following code in .eleventy.js file work for me

module.exports = function(eleventyConfig) {
  //...
  //...

  eleventyConfig.addGlobalData("permalink", () => {
    return (data) => `${data.page.filePathStem}.${data.page.outputFileExtension}`;
  });

  //...
  //...
};

Ref: https://www.11ty.dev/docs/data-eleventy-supplied/#changing-your-project-default-permalinks

cc @omartan , @Ryuno-Ki

Thanks for all