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

Issue with swup and javascript #2081

Closed
garazdawi opened this issue Jan 28, 2025 · 7 comments
Closed

Issue with swup and javascript #2081

garazdawi opened this issue Jan 28, 2025 · 7 comments

Comments

@garazdawi
Copy link
Contributor

garazdawi commented Jan 28, 2025

In order to create links from the sidebar to other application I generate markdown files that look like this:

# compiler

<script>window.location.replace("../lib/compiler/doc/html/index.html");</script>

This no longer works as swup does not execute the javascript. I tried using the new exdoc:loaded:

# compiler

<script>window.addEventListener("exdoc:loaded", () => { window.location.replace("../lib/compiler/doc/html/index.html"); });</script>

and while that works, the event is triggered rather late so that you can see the rendered page flicker by before the redirect happens.

Any suggestions on what I should do?

@josevalim
Copy link
Member

@garazdawi we do support a new redirects option, would that work well:

* `:redirects` - A map or list of tuples, where the key is the path to redirect from and the
?

@garazdawi
Copy link
Contributor Author

I had forgotten about those. I will try it.

@garazdawi
Copy link
Contributor Author

Yes, that works! Great!

It seems a bit fragile though as essentially what happens is that original the .html files for the markdown is generated and those are then overwritten by the redirect files.

@josevalim
Copy link
Member

@garazdawi alternatively we could support this:

extras: [
  "foo": [redirect: "bar"]
]

Basically, if we have a redirect key, then we also generate the redirect page but keeping the sidebar link. Would that help?

@garazdawi
Copy link
Contributor Author

Would it not then just be better to have:

extras: [
  "foo": [url: "bar"]
]

and have the link directly on the sidebar? Which is what I'm trying to achieve anyway.

@josevalim
Copy link
Member

Yes, agreed. If you want to submit a PR, feel free, otherwise open up an issue and it will eventually be tackled. :) Just need to remember we should probably discard those for epub. :)

@garazdawi
Copy link
Contributor Author

Opened an issue. I will use my workaround for now, I'll try to get some time to work on a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants