From 7ec429ac6e4a4c572a5918b2ca578b1bbe948843 Mon Sep 17 00:00:00 2001 From: paoloredis Date: Thu, 28 May 2026 13:12:34 +0200 Subject: [PATCH 1/6] feat: add Try It button to CLI code examples Adds a 'Try it' button to code examples that opens redis.io/cli with pre-populated commands and autorun enabled. - Extracts CLI commands from shortcode inner content (lines with '> ' or 'redis> ' prefix) - Renders a red 'Try it' button in the codetabs header - Button only visible when the Redis CLI tab is selected - Clicking opens https://redis.io/cli?commands=[...]&autorun=true in a new tab --- layouts/partials/tabbed-clients-example.html | 17 ++++++ layouts/partials/tabs/wrapper.html | 56 +++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/layouts/partials/tabbed-clients-example.html b/layouts/partials/tabbed-clients-example.html index 1c7a00d8b2..a49bccac80 100644 --- a/layouts/partials/tabbed-clients-example.html +++ b/layouts/partials/tabbed-clients-example.html @@ -39,6 +39,20 @@ {{ warnf "[tabbed-clients-example] Example not found %q for %q" $id $.Page }} {{ end }} +{{/* Extract executable CLI commands (lines starting with "> " or "redis> ") for Try It button */}} +{{ $tryItCommands := slice }} +{{ if (ne (trim $redisCommands "\n") "") }} + {{ range $line := split (trim $redisCommands "\n") "\n" }} + {{ $trimmedLine := trim $line " " }} + {{ if hasPrefix $trimmedLine "redis> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "redis> " $trimmedLine) }} + {{ else if hasPrefix $trimmedLine "> " }} + {{ $tryItCommands = $tryItCommands | append (strings.TrimPrefix "> " $trimmedLine) }} + {{ end }} + {{ end }} +{{ end }} + + {{ $tabs := slice }} {{/* Render redis-cli example from inner content if any */}} {{ if (ne (trim $redisCommands "\n") "") }} @@ -131,4 +145,7 @@ {{ if gt (len $buildsUpon) 0 }} {{ $params = merge $params (dict "buildsUpon" $buildsUpon) }} {{ end }} +{{ if gt (len $tryItCommands) 0 }} + {{ $params = merge $params (dict "tryItCommands" $tryItCommands) }} +{{ end }} {{ partial "tabs/wrapper.html" $params }} diff --git a/layouts/partials/tabs/wrapper.html b/layouts/partials/tabs/wrapper.html index fd9553d09d..0cb7ff5d52 100644 --- a/layouts/partials/tabs/wrapper.html +++ b/layouts/partials/tabs/wrapper.html @@ -9,6 +9,7 @@ {{ $description := .description }} {{ $difficulty := .difficulty }} {{ $buildsUpon := .buildsUpon }} +{{ $tryItCommands := .tryItCommands }} {{- /* Build metadata map for each language/client combination */ -}} {{- $codetabsMeta := dict -}} @@ -73,7 +74,7 @@ {{- if $exampleId -}} {{- end -}} -
+
@@ -101,6 +102,21 @@
+ {{/* "Try it" button - opens redis.io/cli with pre-populated commands */}} + {{ if $tryItCommands }} + + {{ end }} {{/* BinderHub "Run in browser" link - shown conditionally based on current tab's binderId */}}