adhocteam / nytimes-library

A collaborative documentation site, powered by Google Docs.
https://nyt-library-demo.herokuapp.com/
Apache License 2.0
1 stars 1 forks source link

Custom EJS files require parent EJS files to be included #70

Open zenkimoto opened 2 years ago

zenkimoto commented 2 years ago

Context (Environment)

When creating a custom EJS file, you'd copy the EJS file from the layouts folder into custom/layouts. However, if the EJS file is a child EJS file (another EJS file includes it), the file doesn't get included unless the parent EJS file (the one including the child EJS) is also part of the custom/layouts folder.

Recently, there were changes to partial/search.ejs. However, the changes didn't appear in the search results screen. I had to include in the custom folder: partial/nav.ejs in order for the search changes to appear.

Expected Behavior

Use custom EJS only if the EJS file is there regardless of parent.

Actual Behavior

Includes custom EJS files only if the parent is a custom EJS file.

To Reproduce

  1. Copy an existing child EJS file and place it in the custom/layouts folder.
  2. Make some modifications to it.
  3. Launch Content Library in local development and see the code changes from step 2 do not appear.

Additional Information

This may be a problem with how the Content Library is set up or maybe it's just how EJS operates. This ticket is meant for an investigation into the issue and present a possible solution.

zenkimoto commented 2 years ago

I looked into this a little bit. The EJS set up code in question is here:

https://github.com/adhocteam/nytimes-library/blob/main/server/index.js#L34-L35

This sets the EJS templates to resolve in the ./custom/layouts folder first, then resolves to ./layouts.

However, if that is the case, then I don't know why this function is needed:

https://github.com/adhocteam/nytimes-library/blob/main/server/utils.js#L12-L31

Which is what is used to fetch the top-level templates.

What I don't understand is when it goes through and resolves partials. I assume it should be using the above where the ./custom/layouts folder is resolved first. I guess if it's a partial and it's already in the ./layouts folder, it doesn't go back to the ./custom/layouts folder to resolve partials? 🤷‍♂️