diff --git a/website_and_docs/layouts/shortcodes/gh-codeblock.html b/website_and_docs/layouts/shortcodes/gh-codeblock.html index ca3073301620..6bde93c39539 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,136 @@ {{ $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 }} - -