Skip to content

Commit

Permalink
download url now actually download the file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Nov 22, 2023
1 parent 69bfcc3 commit e06b460
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% endif %}
</td>
<td scope="row">
<a href="{{ext.download_url}}" role="button" class="outline">Download</a>
<a href="#" onclick="download_file('{{ext.download_url}}')" role="button">Download</a>
</td>
</tr>
{% endfor %}
Expand All @@ -37,4 +37,5 @@
<th scope="col">Download</th>
</tr>
</tfoot>
</table>
</table>

20 changes: 19 additions & 1 deletion templates/coltrane/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,25 @@ <h2>A registry of htmx extensions, both official and third-party.</h2>
<footer>
&copy; 2023 Tobi DEGNON| <a href="https://oluwatobi.dev">oluwatobi.dev</a>
</footer>


<script>
const download_file = (url) => {
let extensionName = url.split('/').pop();
fetch(url)
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = extensionName
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(() => alert('oh no!'));
}
</script>
</body>

</html>

0 comments on commit e06b460

Please sign in to comment.