Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github - How to get file list under directory on github pages?

Suppose a repo myname/myrepo with github pages enabled, then myname.github.io/myrepo will be available, hosting same content as original repo without any dedicated deployment.

repo
  |-- folder
        |-- file1
        |-- file2

I expect to send http request like myname.github.io/myrepo/folder to get something like ['file1', 'file2'] dynamically (even just a string I can parse through javascript), like nginx autoindex.

How can I achieve this?

Note: I know I can write a script, possibly in any language like bash, python, ruby, perl, to name endlessly, to generate the index file. I do not want any additional deployment, even with CI.

like image 662
Mike Avatar asked May 30 '18 09:05

Mike


2 Answers

Inspired by octotree (a chrome plugin for github), send API GET https://api.github.com/repos/{owner}/{repo}/git/trees/master to get root folder structure and recursively visit children of "type": "tree".

As github API has rate limit of 5000 requests / hour, this might not be good for deep and wide tree.

like image 74
Mike Avatar answered Sep 30 '22 07:09

Mike


Directory Listing - GitHub Pages

If using the script for generating an index file is not what you wanted, there's no other way to get that.

GitHub Pages used to allow .PHP files where you could do something similar in an easier way (see here), but this feature is not available, so the script mentioned above generates static files for it.

There's no other way i know to achieve this. Why don't you want to use the script? (special reasons?) Please give more information of what you could use so we can find other ways.

UPDATE 1:

I found something that could make it work, but needs to be installed, so you might not like it (see "*note" below). This is a bit outdated (last commit on Feb).

*Note: most people would agree that to achieve what you want, you'll need a server-side language, but php is not supported on GHP as explained before. See more here.

like image 33
luismiguelss Avatar answered Sep 30 '22 06:09

luismiguelss