Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions layouts/partials/meta-links.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
{{ $editURL := printf "%s/edit/%s/content/%s%s" $gh_repo $gh_branch $gh_path $gh_file }}
{{ $issuesURL := printf "%s/issues/new?title=Feedback: %s&body=Page https://redis.io/docs/latest/%s%s" $gh_repo (safeURL $.Title ) $gh_path $stripped_filename }}

{{/* Get the markdown output format URL and generate a proper filename */}}
{{ $markdownURL := "" }}
{{ range .AlternativeOutputFormats }}
{{ if eq .Name "markdown" }}
{{ $markdownURL = .Permalink }}
{{ end }}
{{ end }}

{{/* Generate a filename based on the page path */}}
{{ $filename := "" }}
{{ if $stripped_filename }}
{{ $filename = printf "%s.md" $stripped_filename }}
{{ else }}
{{ $filename = printf "%s.md" (replaceRE "[^a-zA-Z0-9-]+" "-" .Title | lower) }}
{{ end }}

<nav class="flex flex-col gap-3 pb-3 w-52 text-redis-pencil-600 border-b border-b-redis-pen-700 border-opacity-50">
<a {{ printf "href=%q" $editURL | safeHTMLAttr }} target="_blank" class="group inline-flex items-center gap-1 hover:text-redis-pen-400 mt-auto self-start">
<svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
Expand All @@ -28,5 +44,31 @@
</svg>
Create an issue
</a>
{{ if $markdownURL }}
<a href="#" onclick="downloadMarkdown('{{ $markdownURL }}', '{{ $filename }}'); return false;" class="group inline-flex items-center gap-1 hover:text-redis-pen-400 mt-auto self-start">
<svg class="w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6zm6-10v5l-2-2-1.5 1.5L12 18l3.5-3.5L14 13l-2 2V10h-2z"/>
</svg>
Download Markdown
</a>

<script>
function downloadMarkdown(url, filename) {
fetch(url)
.then(response => response.blob())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetch doesn't check response status before downloading

Medium Severity

The fetch call pipes response.blob() without checking response.ok first. If the server returns a non-2xx status (e.g., 404 or 500), the error page HTML body is silently converted to a blob and downloaded as a .md file. The user receives a file that appears valid but contains HTML error content instead of the expected markdown.

Fix in Cursor Fix in Web

.then(blob => {
const a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = filename;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(a.href);
})
.catch(error => console.error('Download failed:', error));
}
</script>
{{ end }}
</nav>

Loading