Skip to content

feat: add shareable snippet links using base64-encoded raw URLs (Issue #23)#132

Open
amritamishra01 wants to merge 1 commit intolfortran:mainfrom
amritamishra01:feat/share-snippet-links
Open

feat: add shareable snippet links using base64-encoded raw URLs (Issue #23)#132
amritamishra01 wants to merge 1 commit intolfortran:mainfrom
amritamishra01:feat/share-snippet-links

Conversation

@amritamishra01
Copy link
Contributor

@amritamishra01 amritamishra01 commented Feb 27, 2026

Summary

This PR implements shareable snippet links for dev.lfortran.org as described in Issue #23.

Users can now:

  1. Load code from any direct raw download URL (e.g. GitHub Gist raw link).
  2. Click the "Share" button.
  3. Generate a short link of the form:
    ?snippet=<base64_encoded_raw_url>
  4. Open that link and automatically load + run the same code locally in the browser.

This follows the maintainer's vision:

Encode the download link itself using base64 — no server required.


Implementation Details

1. Direct URL Fetching

  • Supports ?url=<raw_download_link>
  • Fetches the provided link directly (no URL reconstruction)
  • Stores the exact download URL in sourceUrl state

2. Shareable Snippet Links

  • Adds encodeSnippet and decodeSnippet utilities
  • Uses URL-safe Base64 encoding
  • Generates links like:
    ?snippet=<base64_encoded_raw_url>

3. Snippet Loading

  • On page load, checks for ?snippet=
  • Decodes the base64 string
  • Fetches the decoded raw URL directly
  • Loads and runs the code locally

4. UI Changes

  • Added a "Share" button in TextBox
  • Button is enabled only when code is loaded from an external source
  • Uses Ant Design Tooltip + message for user feedback

Architecture Notes

  • Removed reliance on gist ID reconstruction.
  • No GitHub-specific logic.
  • No backend/server required.
  • Works with any publicly accessible raw download link (e.g., GitHub Gist, repository raw file).

Manual Testing

Tested the following:

  • Load via ?url=<raw_link> → works
  • Click Share → snippet link generated
  • Open ?snippet=<encoded> → auto-load works
  • Hard refresh → still works
  • Invalid snippet → safe fallback to default example
  • No 400 errors or raw URL reconstruction issues

vid1.mp4

Closes #23

…Issue lfortran#23)

- Add encodeSnippet and decodeSnippet utilities
- Support ?snippet= and ?url= parameters
- Implement Share button in TextBox
- Remove dependency on gist ID reconstruction
- Align with maintainer's no-server architecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the ability to easily share links to code snippets

1 participant