[英]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.