From 8755771942051d2978c4cc771e7a4ddfb56cb862 Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Thu, 5 Jun 2025 10:42:00 -0400 Subject: [PATCH 1/3] feat: add button to show full code example --- .../layouts/shortcodes/gh-codeblock.html | 155 ++++++++++++++---- 1 file changed, 126 insertions(+), 29 deletions(-) diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index ca3073301620..84fd7b70f7ae 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -6,21 +6,22 @@ {{ $defaultBranchFromEnv := (getenv "SELENIUM_EXAMPLES_BRANCH") }} {{ if $defaultBranchFromEnv }} - {{ $branch = $defaultBranchFromEnv }} +{{ $branch = $defaultBranchFromEnv }} {{ end }} {{ $defaultOrgFromEnv := (getenv "SELENIUM_EXAMPLES_ORG") }} {{ if $defaultOrgFromEnv }} - {{ $org = $defaultOrgFromEnv }} +{{ $org = $defaultOrgFromEnv }} {{ end }} {{ $defaultRepoFromEnv := (getenv "SELENIUM_EXAMPLES_REPO") }} {{ if $defaultRepoFromEnv }} - {{ $repo = $defaultRepoFromEnv }} +{{ $repo = $defaultRepoFromEnv }} {{ end }} {{ $fullPath := .Get "path" }} {{ $path := index (split $fullPath "#") 0 }} +{{ $hasFragment := in $fullPath "#" }} {{ $apiUrl := printf "%s/%s/%s/contents%s?ref=%s" $apiBaseUrl $org $repo $path $branch }} {{ $webUrl := printf "%s/%s/%s/blob/%s/%s" $webBaseUrl $org $repo $branch $fullPath }} @@ -30,34 +31,130 @@ {{ $githubToken := (getenv "SELENIUM_CI_TOKEN") }} {{ if $githubToken }} - {{ $toReplace := printf "://%s@" $githubToken }} - {{ $tokenInUrl := cond (eq $githubToken "") "://" $toReplace }} - {{ $apiUrlWithToken := replace $apiUrl "://" $tokenInUrl }} - - {{ $apiResults := getJSON $apiUrlWithToken }} - {{ $content := base64Decode $apiResults.content }} - {{ $codeSnippet := $content }} - - {{ $parsedApiUrl := urls.Parse $webUrl }} - {{ with $parsedApiUrl.Fragment }} - {{ $codeLines := split $parsedApiUrl.Fragment "-" }} - {{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }} - {{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }} - {{ $numOfLines := cond (eq (sub $toLine $fromLine) 0) 1 (sub $toLine $fromLine) }} - {{ $splitContent := split $content "\n" }} - {{ $codeSnippet = delimit (first $numOfLines (after $fromLine $splitContent)) "\n" }} - {{ end }} - - {{ highlight $codeSnippet $language }} - -
+{{ $toReplace := printf "://%s@" $githubToken }} +{{ $tokenInUrl := cond (eq $githubToken "") "://" $toReplace }} +{{ $apiUrlWithToken := replace $apiUrl "://" $tokenInUrl }} + +{{ $apiResults := getJSON $apiUrlWithToken }} +{{ $content := base64Decode $apiResults.content }} +{{ $codeSnippet := $content }} + +{{ $parsedApiUrl := urls.Parse $webUrl }} +{{ with $parsedApiUrl.Fragment }} +{{ $codeLines := split $parsedApiUrl.Fragment "-" }} +{{ $fromLine := sub (int (replace (index $codeLines 0) "L" "")) 1 }} +{{ $toLine := int (cond (eq (len $codeLines) 1) (replace (index $codeLines 0) "L" "") (replace (index $codeLines 1) "L" "")) }} +{{ $numOfLines := cond (eq (sub $toLine $fromLine) 0) 1 (sub $toLine $fromLine) }} +{{ $splitContent := split $content "\n" }} +{{ $codeSnippet = delimit (first $numOfLines (after $fromLine $splitContent)) "\n" }} +{{ end }} + +{{ highlight $codeSnippet $language }} + +{{ if $hasFragment }} +{{ $uniqueId := md5 $path }} +
+ +
+ + + + +{{ end }} + + +
+ {{ else }} - {{ partial "github-content.html" }} +{{ partial "github-content.html" }} {{ end }} - - From fad32045108eba512c1ce4478ce7cc6a7a75dd6b Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Thu, 5 Jun 2025 10:53:28 -0400 Subject: [PATCH 2/3] fix: apply bot code suggestions --- website_and_docs/layouts/shortcodes/gh-codeblock.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index 84fd7b70f7ae..d31e7047c5c9 100644 --- a/website_and_docs/layouts/shortcodes/gh-codeblock.html +++ b/website_and_docs/layouts/shortcodes/gh-codeblock.html @@ -64,7 +64,7 @@
{{ $path }}
- +