Add custom 404 copy step to deploy workflow - #344
Conversation
|
The video seems to be switching from |
Actually, when I am trying to deploy this, an error is showing regarding some permission, so its not getting deployed. Screen.Recording.2025-07-03.003828.mp4 |
|
The part I don't understand is the 404 and es/404 pages. We have the 404.html page in the DISCOVER folder. Then we have the same page also as html in |
I've implemented a multilingual 404 page using a single custom-designed Although we could create separate static 404 pages for each language, I chose to use JavaScript to dynamically detect the language (based on the URL or referrer) and update the text accordingly. This allows us to maintain just one file instead of duplicating content for each language. The language switcher dropdown also uses JS to redirect users to the appropriate version ( If you prefer static, language-specific 404s, we can skip JS — but we’ll need to maintain multiple files. Each file would be hardcoded in its own language. |
|
|
||
| const pathLang = location.pathname.split("/")[1]; | ||
| const refLang = new URL(document.referrer || "", location.origin).pathname.split("/")[1]; | ||
| const lang = translations[pathLang] ? pathLang : (translations[refLang] ? refLang : "en"); |
There was a problem hiding this comment.
Could this be the reason it doesn't work on the root 404 page? We set the language through the switcher but the language defined from the path takes priority?
| document.getElementById("language-switcher").addEventListener("change", function () { | ||
| const selectedLang = this.value; | ||
| if (selectedLang === "en") { | ||
| window.location.href = `/404.html`; | ||
| } else { | ||
| window.location.href = `/${selectedLang}/404.html`; | ||
| } | ||
| }); |
There was a problem hiding this comment.
or maybe this isn't updating the language related constants? not even sure it is possible though (0 javascript knowledge on my end)
|
@OriolAbril I have published the website on my fork, here's the link: https://speco29.github.io/DISCOVER-Cookbook/in.html |
|
The switching language while maintaining the broken url is working which is great. Given there is a switcher, it is not strictly necessary (and might even be a good idea if it allows to simplify the code significantly). The part that is not working now is the default language as taken from the URL: https://speco29.github.io/DISCOVER-Cookbook/es/bad.html shows in English. From the little I understand of the code, I think it has to do with what is expected of the URLs when splitting it through |
But it shows in spanish in my laptop, when I clicked on that link, by default it showed spanish: Screen.Recording.2025-07-14.223841.mp4Altthough when I changed it into english, the folder still remains the same /es/bad.html. |
It also works on my phone, but still getting English on my laptop. I guess it is an issue with the browser on my laptop. As I said, I can change manually so not a problem.
That is what we want to happen in the 404 page. |
@OriolAbril Is there something that I should change/add in this page? |
✅ Deploy Preview for stupendous-kringle-a86e81 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
|
||
| - name: Copy global 404.html | ||
| run: | | ||
| cp DISCOVER/404.html DISCOVER/_build/html/404.html | ||
|
|
||
|
|
There was a problem hiding this comment.
the build website script already does this
There was a problem hiding this comment.
I'll remove it then
There was a problem hiding this comment.
This should not be part of this PR but a different one. Not sure why this file was missing form the toc but it should definitely be added, just in a different PR
|
This PR we can keep with |
|
@OriolAbril I have made few changes, please you review it as per your convenience and let me know about it;) |
There was a problem hiding this comment.
also undo the rename of the file as it is done in #365
Screen.Recording.2025-06-30.135547.mp4
@OriolAbril I will be keeping this as final 404 page, let me know if there is anything to change. This 404 page required to create an
/esfolder insideDISCOVER/build/htmlcontaining every html page.