-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
docs: fix js and ts extension when TSToggle is active #9486
docs: fix js and ts extension when TSToggle is active #9486
Conversation
|
@geoffrich accessibility-wise, is there anything speaking against this? For example screen readers who list both extension names. |
It shouldn't be an issue -- the non-active extension will be Though I did notice this issue in the load docs. We should spot-check where we already mention something like "+page.js or +page.ts" and update it since the file extension will automatically change. |
@geoffrich Are you refering to update the markdown files where .js or .ts are mentioned simultaneously as example? For example: the one you mentioned in the load docs. Solution: i can check all the .md files that contains a .js extension and check the context if they mention .ts or .js at the same time. If true, then i would delete the 2nd example. Like the example you gave. If you agree i can do this. @dummdidumm |
Mhhhhm tough call. As a reader, if you didn't notice the toggle already, you might think "oh so SvelteKit only works with JavaScript?" - on the other hand, there are many places where only once is used. I'm inclined to say we should remove the double mentions. @Rich-Harris what's your stance on this? |
@@ -371,7 +388,13 @@ function parse({ file, body, code, codespan }) { | |||
throw new Error(`Unexpected <h${level}> in ${file}`); | |||
} | |||
|
|||
return `<h${level} id="${slug}">${html}<a href="#${slug}" class="permalink"><span class="visually-hidden">permalink</span></a></h${level}>`; | |||
return `<h${level} id="${slug}" style="display: inline-flex">${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing the double mentions makes sense, but the toggle probably needs to be more discoverable somehow, whether that's by mentioning it in the docs where it makes sense to, or moving it somewhere else on the page, or something else. I don't have a great suggestion right now though. Other than that, I love this change! |
Great. So i will remove the double mentions on all the corresponding markdown files, where the string contains any .js and .ts mention at the same time.
I was watching how the Vue docs do it: And how Deno Docs does it but for different versions. It's a good idea to put in on the top-left side. In that way people before reading any section, they will always notice the Typescript or Javascript. Plus we follow the same pattern. This is a fast sketch of how it woud look: What do you think? @Rich-Harris @dummdidumm 👀 |
Let's worry about where to place the toggle later and just replace the double occurences with either/or for now 👍 |
thank you! |
❤️ |
The Problem
Solves #9431. When switching to the TypeScript mode in the docs, the .js and .ts references didnt change to their specific language.
The only change happened on the file name of the code blocks (because its already implemented specifically for it).
Describe the solution
The way of dealing with typescript toggle is the following:
kit/sites/kit.svelte.dev/src/lib/docs/TSToggle.svelte
Lines 7 to 22 in c0612a8
Which adds the following CSS classes to the DOM:
kit/sites/kit.svelte.dev/src/app.html
Lines 20 to 31 in f1beb92
To avoid duplicate files for every markdown documentation, is to modify the output of
<code>
and<heading>
element whenever they have a.js
or a.ts
extension using a conditionalregex
.If they contain that conditional regex, we delete the
extension
from the string and then render the code element with both available extensions as follows:We modify the return statement to check if the conditional regex (.js or .ts extension) is true, then return the span element with both available extensions.
I added style
inline-flex
to the<heading>
element, because the css properties for.prefers-ts
and.prefers-js
are for block elements. In that way we can avoid overflow.Improvements
Maybe there's better ways to handle the conditional statement and return the span element.
2023-03-22.16-53-01.mp4
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.