How do I include a .js script across a website without format-resources? #10654
-
DescriptionHello! I've been experimenting with the best way to deploy a .js script that modifies the sidebar across part of a website that uses hybrid navigation. After trying (and failing) to pass it via contributes:
formats:
html:
include-in-header:
- text: |
<script src="mysidebar.js"></script>
format-resources:
- "mysidebar.js" This works, but the downside is that I believe I could do this with a filter that uses |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Did you try using |
Beta Was this translation helpful? Give feedback.
-
Haha, thank you for the validation! Everything you said make sense. The path resolution does seem tricky. I'm not sure about the tradeoffs here, but admitting .js files under In the meantime, though, I'm happy for any excuse to write a filter 😎 . That works perfectly. It also provides an open door for other functionality that I'd like to add to this format in the future. Thanks @cderv ! |
Beta Was this translation helpful? Give feedback.
Oh I know ! 🤦
include-in-header
hastext
andfile
option. Thefile
option is just a convenient way to dotext
by letting Quarto read from a file.This means the content is expected to be HTML. Here you are passing directly the
.js
so it will read your JS file and put the content inside the HTML header, and somehow this gets inserted afterbody
. Probably because the content is not valid HTML anyway.Dealing with path resolution for extension is not simple. Quarto does the right thing when file are passed in extension. But it does not catch and modify a path in text like
<script src="mysidebar.js"></script>
.So it would do the right thing for something like this
include-in-header: …