Add cgit pdf download post
This commit is contained in:
parent
fed2333433
commit
904f21f1e9
1 changed files with 26 additions and 0 deletions
26
content/blog/make-cgit-serve-pdfs-directly/index.rst
Normal file
26
content/blog/make-cgit-serve-pdfs-directly/index.rst
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: "How to make cgit serve PDF files as direct downloads"
|
||||
date: 2025-11-17T23:42:00+01:00
|
||||
summary: >
|
||||
cgit is great, but by default when you click on a PDF file in a repository content listing it will show you a
|
||||
hexdump of the file. You can access the actual file by clicking the "plain" link on top of the listing, but that's
|
||||
not only annoying, for large PDF files rendering the hexdump can also hang browser tabs.
|
||||
---
|
||||
|
||||
cgit is great, but by default when you click on a PDF file in a repository content listing it will show you a
|
||||
hexdump of the file. You can access the actual file by clicking the "plain" link on top of the listing, but that's
|
||||
not only annoying, for large PDF files rendering the hexdump can also hang browser tabs.
|
||||
|
||||
I found a quick and easy solution to this problem, which I'm documenting here because it seems nobody on the
|
||||
internet has really done this before, and the usual AI assistants (ChatGPT and Claude) are both deeply confused.
|
||||
|
||||
You just add a simple rewrite rule to your nginx config that 302-redirects requests to ``/tree/.../foobar.pdf`` to
|
||||
``/plain/.../foobar.pdf``. Here's the rule, make sure you put them in your nginx config *before* the location directive
|
||||
proxying requests to cgit.
|
||||
|
||||
.. code:: nginx
|
||||
|
||||
location ~ ^/([^/]+)/tree/(.*\.pdf)$ {
|
||||
return 302 /$1/plain/$2;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue