Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom javascript files are not copied to the output folder #2091

Closed
1 task done
kungfux opened this issue Dec 5, 2024 · 7 comments · Fixed by #2101
Closed
1 task done

Custom javascript files are not copied to the output folder #2091

kungfux opened this issue Dec 5, 2024 · 7 comments · Fixed by #2101
Labels
bug Something isn't working released Included or resolved in the release

Comments

@kungfux
Copy link
Collaborator

kungfux commented Dec 5, 2024

Checklist

How did you create the site?

Generated from chirpy-starter

Describe the bug

Custom javascript files are not copied to the output folder after upgrading to 7.2.1, because changes made in #2090 are promoted to the Chirpy starter template.

Steps To Reproduce

  1. Have custom scripts in assets folder
  2. Build website

Expected Behavior

Custom scripts are copied to the output folder.

Environment

  • Ruby: ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
  • Jekyll: jekyll 4.3.3
  • Chirpy: 7.2.1

Anything else?

Workaround: edit _config.yml as follows

exclude:
- - "*.js"
+ - purgecss.js
@cotes2020
Copy link
Owner

Steps To Reproduce

Have custom scripts in assets folder

Can you be more specific?

@kungfux
Copy link
Collaborator Author

kungfux commented Dec 6, 2024

Can you be more specific?

I have custom javascript files in assets/js folder that are being included from markdown or metadata-hook.html files.

root/
├── _includes/
│   └── metadata-hook.html
└── assets/
    └── js/
        └── my-script.js
<script src="/assets/js/my-script.js" defer></script>

This worked as javascript files are copied to _site/assets/js folder on build. Since javascript files are excluded in the config now, they are no being copied.

If I remove the following parameter in _config.yml, then my javascript files will be copied.

exclude:
  - "*.js"

Is this something we would like to avoid by default?

@cotes2020
Copy link
Owner

cotes2020 commented Dec 6, 2024

The pattern *.js will only exclude js files in the root directory and does not apply to js files in the assets folder. So I'm curious how you came to this conclusion? Did it exclude the js files in the assets/ folder after running it?

BTW, I tested this pattern locally before commit #2090, and it will copy the JS files in the subdirectories to the output directory.

@kungfux
Copy link
Collaborator Author

kungfux commented Dec 6, 2024

I see what you're saying.

  • Matches any file. Can be restricted by other values in the glob. Equivalent to /.*/x in regexp.

Here's what I'm observing though. When I add *.js to the exclude section, there are no js files in the _site/assets/js folder after the build. When I remove it, the js files are there.

OK, I will try to find the cause on my end. At the moment I have no idea why it works differently for you.

@cotes2020
Copy link
Owner

Sorry, I made a mistake. When checking the output with ls command, the path I entered was missing the _site/ prefix.

Using ruby to check, it's confirmed that *.js can match files in subdirectories.

# test.rb
puts File.fnmatch('*.js', 'sub/script.js')        # output: true
puts File.fnmatch('*.js', 'assets/js/script.js')  # output: true

It seems that ruby has a different pattern than the shell and needs to be used more carefully.

@cotes2020 cotes2020 added the bug Something isn't working label Dec 6, 2024
@kungfux
Copy link
Collaborator Author

kungfux commented Dec 6, 2024

Thanks for checking @cotes2020

Copy link

github-actions bot commented Dec 6, 2024

🎉 This issue has been resolved in version 7.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Included or resolved in the release label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Included or resolved in the release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants