簡體   English   中英

如何獲取 Github 存儲庫的所有文件,使用 Javascript 創建索引。html 以訪問所有文件

[英]How to get all the files of a Github repository using Javascript to create an index.html to access all the files

我正在嘗試為我存儲庫的所有文件創建一個易於訪問的文檔(它們都是用 Markdown 編寫的)。

這個想法是制作一個 in.js 腳本來分析存儲庫並列出所有文件,如訪問它們的鏈接。 (例如,一種從手機查看文件的簡單方法)

我試過使用這段代碼,但它對我不起作用:/:

const xhr = new XMLHttpRequest();
    const url = "https://api.github.com/repos/gitblanc/Obsidian-Notes/contents/"
    // Replace -username- with your GitHub username, -repo- with the repository name, and then :path with a path to the file or folder you want to get the content of (leave blank to ge all files of the repository)

    xhr.open('GET', URL, true);

    xhr.onload = function() {
        const data = JSON.parse(this.response);

        console.log(data);
    };
    
    xhr.send();

您沒有傳入 url 參數。

該請求必須如下所示:

const url = "https://api.github.com/repos/gitblanc/Obsidian-Notes/contents/"

xhr.open('GET', url, true);

您的 url 變量有錯字(全部大寫)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM