-
Notifications
You must be signed in to change notification settings - Fork 48
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
External scripts don't work #306
Comments
I'm not sure if Astro supports this out-of-the-box (cc. @Nemikolh, ???). But one thing you could do is convert the ---
type: lesson
title: Example
---
import landing from "./_files/landing.js?raw"
# Test
<script>
{landing}
</script> But if you just want to add some interactivity to lesson markdown, I would recommend to check Astro docs: https://docs.astro.build/en/basics/astro-components/ and https://docs.astro.build/en/guides/client-side-scripts/ |
With Astro's content collection, I would advise against having code that is part of your app inside your I find that it's usually nicer to have the following structure:
Which then let you import your script like this in any ---
type: lesson
title: Example
---
import "@utils/script";
# My lesson The nice thing is that you can import your script using the same import in any lesson. If you want to add a ui element, you might find it useful to have a component instead which let's you access and modify the state of the tutorial: With a import tutorialStore from 'tutorialkit:store';
interface Props {
path: string;
content: string;
}
export function UpdateFileButton({ path, content }: Props) {
function writeFile() {
tutorialStore.updateFile(path, content);
}
return (
<button onClick={writeFile}>
Update file
</button>
);
} You can then use it like this in your lessons: ---
type: lesson
title: Example
---
import { UpdateFileButton } from "@components/UpdateFileButton";
# My lesson
<UpdateFileButton client:load path="/index.js" content="console.log('Hello world!')" /> |
So it's ok to put images in content, but not scripts? Even if the script is for a particular lesson only? |
@iliakan could you describe your use case a bit more? What does the |
@AriPerkkio for this particular case I was going to create a landing script to nicely show callouts above the webcontainer and the editor, to introduce the environment in a clear visual style. |
I mean you can also have them there but it won't be as nice as having them outside in terms of DX with tutorialkit/packages/astro/src/index.ts Lines 87 to 89 in 1eb41fd
So IIRC, it means that Note that they are excluded for a reason: we do not want vite to try to resolve imports for file that ends in WebContainer as it leads to confusing errors |
Describe the bug
Adding an external script to a lesson doesn't work.
Steps to reproduce
<script src="landing.js"></script>
tocontent.md
of a lesson.landing.js
file withconsole.log(1)
in the lesson folder.npm run dev
and open the lesson in the browser.Expected behavior
Astro supports scripts. I'd expect the script to work.
Platform
P.S.
Adding
image.png
to the lesson and including it as![](ball.png)
works.Perhaps, there's an alternative "proper" way to add an external script?
The text was updated successfully, but these errors were encountered: