最近创建的 GitHub 文件的名称
Name of latest created GitHub file
首先,很抱歉,我是网页设计的新手,javascript,我希望能详细说明答案,但如果有任何帮助,我将不胜感激.
我尝试在我自己的(小)网站中(通过 GitHub)显示 PDF 文件,这很容易。但是当我试图获取最新的文件来显示它时,我失败了。网上查不到代码样例,转过来问一下。
如何在 GitHub 存储库中搜索以显示 最新 创建的文件?
我一直在尝试阅读和理解类似 this documentation 的内容,但我不明白 如何在 [=] 中应用 61=]。我应该把功能放在哪里?以及如何将目录内容(包括创建日期和时间)输入到javascript[的一些数组中=43=]?很抱歉提出这些(可能)愚蠢的问题,但我没有在 Internet 上找到相关的代码示例。 谁能帮我解决这个问题?如果可能的话,我想看看一些代码示例。
我想用Javascript(当然还有HTML)来实现这个,但我真的很陌生,请原谅我(我知道 basics 在 Python 3 和 C++ 中编程。
如有任何帮助,我们将不胜感激。
用代码编辑
<!DOCTYPE html>
<html>
<body>
<script text="type/javascript">
var response =
await octokit.request('GET /repos/tonymayixuan/Introducing_Rigorous_Mathematics/contents/PDF/', {
owner: 'tonymayixuan',
repo: 'Introducing_Rigorous_Mathematics',
path: 'PDF'
})
document.open();
document.write(response);
document.close();
</script>
</body>
</html>
我尝试 运行 以上内容,但没有显示任何内容。请问如何记录“回复”并使用?
您的代码有几个问题。
await
不能在 async
函数之外使用。 (参见 MDN。)全局作用域不是异步函数。
您似乎没有在任何地方导入 octokit 库。
如果您按照 octokit/rest.js 中的示例进行操作,您将能够按照自己的意愿进行操作:
<script type="module">
import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
const octokit = new Octokit();
async function showFile()
{
const response = await octokit.request('GET /repos/tonymayixuan/Introducing_Rigorous_Mathematics/contents/PDF/',
{
owner: 'tonymayixuan',
repo: 'Introducing_Rigorous_Mathematics',
path: 'PDF'
});
response.data.forEach(datum => document.write(datum.name+'<br>'));
}
showFile().then(_ => console.log('done'));
</script>
首先,很抱歉,我是网页设计的新手,javascript,我希望能详细说明答案,但如果有任何帮助,我将不胜感激.
我尝试在我自己的(小)网站中(通过 GitHub)显示 PDF 文件,这很容易。但是当我试图获取最新的文件来显示它时,我失败了。网上查不到代码样例,转过来问一下。
如何在 GitHub 存储库中搜索以显示 最新 创建的文件?
我一直在尝试阅读和理解类似 this documentation 的内容,但我不明白 如何在 [=] 中应用 61=]。我应该把功能放在哪里?以及如何将目录内容(包括创建日期和时间)输入到javascript[的一些数组中=43=]?很抱歉提出这些(可能)愚蠢的问题,但我没有在 Internet 上找到相关的代码示例。 谁能帮我解决这个问题?如果可能的话,我想看看一些代码示例。
我想用Javascript(当然还有HTML)来实现这个,但我真的很陌生,请原谅我(我知道 basics 在 Python 3 和 C++ 中编程。
如有任何帮助,我们将不胜感激。
用代码编辑
<!DOCTYPE html>
<html>
<body>
<script text="type/javascript">
var response =
await octokit.request('GET /repos/tonymayixuan/Introducing_Rigorous_Mathematics/contents/PDF/', {
owner: 'tonymayixuan',
repo: 'Introducing_Rigorous_Mathematics',
path: 'PDF'
})
document.open();
document.write(response);
document.close();
</script>
</body>
</html>
我尝试 运行 以上内容,但没有显示任何内容。请问如何记录“回复”并使用?
您的代码有几个问题。
await
不能在async
函数之外使用。 (参见 MDN。)全局作用域不是异步函数。您似乎没有在任何地方导入 octokit 库。
如果您按照 octokit/rest.js 中的示例进行操作,您将能够按照自己的意愿进行操作:
<script type="module">
import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
const octokit = new Octokit();
async function showFile()
{
const response = await octokit.request('GET /repos/tonymayixuan/Introducing_Rigorous_Mathematics/contents/PDF/',
{
owner: 'tonymayixuan',
repo: 'Introducing_Rigorous_Mathematics',
path: 'PDF'
});
response.data.forEach(datum => document.write(datum.name+'<br>'));
}
showFile().then(_ => console.log('done'));
</script>