11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://eleventy-base-blog.netlify.app/
MIT License
1.19k stars 609 forks source link

Changing output directory in .eleventy.js appears to only add a new subdirectory to _site rather than renaming _site #131

Closed jglovier-okta closed 2 years ago

jglovier-okta commented 2 years ago

Hi there! First just want to say thank you for making this project. It was exactly what I needed when I discovered that Jekyll and Middleman were unavailable to me on a machine for which Ruby was not available and only Node. 😄

So I don't know if this is expected behavior and the docs are just confusing me, or if the behavior is buggy so I decided to just report it and find out!

Basically I'd like to rename my output directory from _site to something like compiled_templates to make using the repo easy for my engineering cross functional partners who will just jump in and reference it from time to time for grabbing some rendered HTML from that directory.

I learned via the docs that I can added a .eleventy.js config file and specify my alternative output location with the output directory config option, so I renamed my output directory as shown. However, instead of renaming _site to compiled_templates it turns out that I'm getting _site/compiled_templates.

Is this expected behavior? If so, might I suggest updating the docs to make that a little more clear? And also, what method could I use to rename the actual top level output directory?

Thanks again! :bow:

pdehaan commented 2 years ago

@jglovier-okta I'm unable to reproduce that _site/compiled_templates/* behavior (on macOS 12.4).

I cloned this repo, ran npm install, then npm run build, and it wrote all the files to _site/* as expected. Then I changed the output path in .eleventy.js to "compiled_templates", and re-ran npm build, and it wrote all the files to compiled_templates/*:

diff --git a/.eleventy.js b/.eleventy.js
index 16a5614..6f3aa2f 100644
--- a/.eleventy.js
+++ b/.eleventy.js
@@ -128,7 +128,7 @@ module.exports = function(eleventyConfig) {
       input: ".",
       includes: "_includes",
       data: "_data",
-      output: "_site"
+      output: "compiled_templates"
     }
   };
 };
npm run build

> eleventy-base-blog@7.0.0 build
> npx @11ty/eleventy

[11ty] Writing compiled_templates/sitemap.xml from ./sitemap.xml.njk
[11ty] Writing compiled_templates/feed/feed.xml from ./feed/feed.njk
[11ty] Writing compiled_templates/feed/.htaccess from ./feed/htaccess.njk
[11ty] Writing compiled_templates/feed/feed.json from ./feed/json.njk
[11ty] Writing compiled_templates/posts/fourthpost/index.html from ./posts/fourthpost.md (njk)
[11ty] Writing compiled_templates/404.html from ./404.md (njk)
[11ty] Writing compiled_templates/posts/firstpost/index.html from ./posts/firstpost.md (njk)
[11ty] Writing compiled_templates/posts/secondpost/index.html from ./posts/secondpost.md (njk)
[11ty] Writing compiled_templates/posts/thirdpost/index.html from ./posts/thirdpost.md (njk)
[11ty] Writing compiled_templates/about/index.html from ./about/index.md (njk)
[11ty] Writing compiled_templates/posts/index.html from ./archive.njk
[11ty] Writing compiled_templates/index.html from ./index.njk
[11ty] Writing compiled_templates/page-list/index.html from ./page-list.njk
[11ty] Writing compiled_templates/tags/second-tag/index.html from ./tags.njk
[11ty] Writing compiled_templates/tags/another-tag/index.html from ./tags.njk
[11ty] Writing compiled_templates/tags/number-2/index.html from ./tags.njk
[11ty] Writing compiled_templates/tags/posts-with-two-tags/index.html from ./tags.njk
[11ty] Writing compiled_templates/tags/index.html from ./tags-list.njk
[11ty] Copied 4 files / Wrote 18 files in 0.11 seconds (6.1ms each, v1.0.1)
tree compiled_templates

compiled_templates/
├── 404.html
├── about/index.html
├── css/
│   ├── index.css
│   ├── prism-base16-monokai.dark.css
│   └── prism-diff.css
├── feed/
│   ├── feed.json
│   └── feed.xml
├── img/
├── index.html
├── page-list/index.html
├── posts/
│   ├── firstpost/index.html
│   ├── fourthpost/index.html
│   ├── index.html
│   ├── secondpost/index.html
│   └── thirdpost/index.html
├── sitemap.xml
└── tags/
    ├── another-tag/index.html
    ├── index.html
    ├── number-2/index.html
    ├── posts-with-two-tags/index.html
    └── second-tag/index.html

15 directories, 20 files
jglovier-okta commented 2 years ago

@pdehaan thanks for taking time to attempt to reproduce and showing your work. That's really helpful for comparison. :bow:

I'm not sure why my repo isn't respecting the changes to the defaults that I've made in .eleventy.js. 🤔 This is what it contains:

module.exports = function(eleventyConfig) {
  // Return your Object options:
  return {
    dir: {
      input: "./templates",
      output: "templates_compiled_mjml"
    }
  }
};

I noticed you said you are running npm run build, but I'm running npx @11ty/eleventy to build it...maybe that is affecting my outcome?

pdehaan commented 2 years ago

@jglovier-okta

I noticed you said you are running npm run build, but I'm running npx @11ty/eleventy to build it...maybe that is affecting my outcome?

It shouldn't affect the outcome.

But the first few things that come to mind are:

  1. Your .eleventy.js file isn't in the correct spot.
  2. Does your .eleventy.js file have multiple module.exports = ... statements?
  3. Did you clone this repo, or are you using a different setup?

If you have a public repo, I can try cloning and taking a look and see if I can reproduce the error.

jglovier-okta commented 2 years ago

Your .eleventy.js file isn't in the correct spot.

Wow. I thought it was in the root, but I had it in a directory that was just toggled open so it looked like it was in the root (apparently I wasn't looking carefully enough). Thank youuuu!!!! :bow: