简体   繁体   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

I'm trying to create an easy-access document to all the files of my repository (they are all written in Markdown).我正在尝试为我存储库的所有文件创建一个易于访问的文档(它们都是用 Markdown 编写的)。

The idea is to make an script in.js that analyzes the repository and lists all the files like links to access to them.这个想法是制作一个 in.js 脚本来分析存储库并列出所有文件,如访问它们的链接。 (An easy way to see the files from mobile for example) (例如,一种从手机查看文件的简单方法)

I've tried to use this code, but it doesn't work to me:/:我试过使用这段代码,但它对我不起作用:/:

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();

You are not passing in the url parameter.您没有传入 url 参数。

The request hast to look like this:该请求必须如下所示:

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

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

You had a typo (all caps) with the url variable.您的 url 变量有错字(全部大写)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular-合并index.html中所有JS文件的最佳实践 - Angular - Best practice for merging all JS files in index.html 自动将所有JS文件添加到index.html - Automatically add all JS files to the index.html 如何使用grunt usemin从index.html创建多个js文件 - how to create multiple js files from index.html using grunt usemin 如何使用gulp重命名index.html中脚本的原始文件? - How to rename the original files of scripts in index.html using gulp? 对于Angular2项目,我如何连接从typescript生成的所有JavaScript文件并将它们添加到我的index.html文件中 - For Angular2 project, In gulp how do I concat all my JavaScript files that were generated from typescript and add them to my index.html file 在index.php / index.html文件中隐藏JavaScript代码 - Obscure JavaScript code in index.php/index.html files 使用JavaScript访问文件夹中所有文件的名称 - Access the Name of all files in folder using JavaScript Angular - 我在index.html中引用了所有JS文件 - 这样可以吗? - Angular - I'm referencing all JS files in index.html - is this ok? 为什么我的 Express 服务器对除 index.html 之外的所有文件都响应 404? - Why is my Express server responding with 404 for all files except index.html? 如何在目录中查找所有文件? (HTML JavaScript) - How to find all files in directory? (HTML JavaScript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM