-
Notifications
You must be signed in to change notification settings - Fork 651
Inline code examples at build time instead of fetching via JavaScript #3717
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
Open
JuanitoFatas
wants to merge
2
commits into
master
Choose a base branch
from
3715/sometimes-syntax-not-loaded
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: Code examples were loaded via fetch() requests at runtime, which could fail due to: - Browser extensions (1Password, ad blockers) interfering with JavaScript - Network issues or timing problems - JavaScript execution failures Solution: Inline the syntax-highlighted code directly in the HTML during Jekyll build, eliminating the need for runtime fetch requests. Changes: - Created _includes/home/code_examples/*.html with the three Ruby examples - Modified _includes/home/try_ruby.html to use Jekyll includes instead of empty placeholders - Simplified javascripts/try-ruby-examples.js - removed fetch logic, now only generates TryRuby button URLs from existing DOM content - Simplified javascripts/hero-animation.js - removed async loading dependency - Added <noscript> fallback in _layouts/homepage.html for graceful degradation Result: - No more fetch requests to /examples/ endpoints - Syntax highlighting displays immediately (no JS dependency for content) - Works even with JavaScript disabled - Faster page load (3 fewer HTTP requests)
Deploying www-ruby-lang-org with
|
| Latest commit: |
4843bb7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://123c9c32.www-ruby-lang-org.pages.dev |
| Branch Preview URL: | https://3715-sometimes-syntax-not-lo.www-ruby-lang-org.pages.dev |
Member
|
Should we also remove |
Member
Author
How about we ship this CSS fix PR first, verified we dont need these examples, then another PR to remove all examples? What do you think? :) |
Member
|
Ah, make sensed. We may use that examples from other place. |
Add explicit color rules for .highlight pre/code elements in @layer base to ensure Rouge syntax highlighting colors take precedence over Tailwind's body text color inheritance.
add422d to
4843bb7
Compare
Member
Author
|
cc @taea would love your review on this 🙇🏻♂️ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves loading examples to not depend on needing JavaScript. Mostly done by Claude. Fixes #3715.
Problem
Code examples were loaded via
fetch()requests at runtime, which could fail due to:Fix
Inline the syntax-highlighted code directly in the HTML during Jekyll build, eliminating the need for runtime fetch requests.
Changes
_includes/home/code_examples/*.htmlwith the three Ruby examples_includes/home/try_ruby.htmlto use Jekyll includes instead of empty placeholdersjavascripts/try-ruby-examples.js- removed fetch logic, now only generates TryRuby button URLs from existing DOM contentjavascripts/hero-animation.js- removed async loading dependency<noscript>fallback in_layouts/homepage.htmlfor graceful degradation when JavaScript is disabled/unavailableResult
/examples/endpointsVerifications
No need to
fetchWhen JavaScript is disabled