How to make viewer like raw github

Viewed 50

I need create a file viewer in html, because html can open only txt. Thing like I need - raw githubusercontent. How it works?

1 Answers

If your file viewer can use curl, you can use gh api to get the content URL of a file, and download it, as seen here:

API_URL=https://api.github.com/repos/owner/repo/contents/path/file.ext
curl $(gh api $API_URL --jq .download_url) -o file.ext

That would simulate what raw.githubusercontent.com does.
And not just for .txt files.

Related