运行 git 从托管在静态站点中的 javascript 推送
Run git push from javascript hosted in static site
想象一个用 jekyll 编译并托管在 github 页面上的静态网站。是否可以在这个页面上有一些 javascript 询问用户一些输入,然后 "git push" 这个输入到一些 github 存储库?
也就是说,如何在javascript中编写如下程序:
- 向用户询问他的姓名,将姓名放入变量s
- 从给定的 github 存储库下载(或提取)文本文件 "allnames.txt"
- 在allnames.txt
末尾加s
- 提交文件 "allnames.txt" 并将其推送回 github
当然,我理解潜在的安全风险,因为 javascript 代码需要嵌入私人 ssh 密钥。但这将是一种向静态网站添加动态性的有趣方式,并且可能有人知道一些解决方案来确保此安全?
谢谢!
如果您了解 git 的内部结构(blob、树、提交),那么您应该能够使用 GitHub REST API 实施解决方案。这不会在 5 分钟内完成。至于安全,你应该可以使用OAuth,所以不需要私钥。
除了使用 GitHub API,您还可以使用 JavaScript 中编写的 git 客户端之一在浏览器中执行上述操作。
这里有几个例子:
来自 Ivan Zuzak 的老 post 描述了他如何使用 Github 评论来构建动态评论系统(source). I recently recreated the system he described (using Github issues for comments) using some extra services: Zapier, the Zapier Github integration and the free version of Zoho forms。这使我能够让自定义网络表单将数据提交到 Github 问题,通过 Zapier(因此无需要求用户创建 Github 帐户)。
我在我的博客上使用 Github 问题作为评论,但您也许可以对其他内容(例如您的姓名列表)使用相同的解决方案。
来自 Staticman 网站:
Staticman handles user-generated content for you and transforms it into data files that sit in your GitHub repository, along with the rest of your content.
Staticman works perfectly with Jekyll sites hosted on GitHub Pages, as a push to your main branch will regenerate the site automatically. If you want to moderate entries before they are published, a pull request will be created for your approval; otherwise, files will be pushed to your main branch straight away.
想象一个用 jekyll 编译并托管在 github 页面上的静态网站。是否可以在这个页面上有一些 javascript 询问用户一些输入,然后 "git push" 这个输入到一些 github 存储库?
也就是说,如何在javascript中编写如下程序:
- 向用户询问他的姓名,将姓名放入变量s
- 从给定的 github 存储库下载(或提取)文本文件 "allnames.txt"
- 在allnames.txt 末尾加s
- 提交文件 "allnames.txt" 并将其推送回 github
当然,我理解潜在的安全风险,因为 javascript 代码需要嵌入私人 ssh 密钥。但这将是一种向静态网站添加动态性的有趣方式,并且可能有人知道一些解决方案来确保此安全?
谢谢!
如果您了解 git 的内部结构(blob、树、提交),那么您应该能够使用 GitHub REST API 实施解决方案。这不会在 5 分钟内完成。至于安全,你应该可以使用OAuth,所以不需要私钥。
除了使用 GitHub API,您还可以使用 JavaScript 中编写的 git 客户端之一在浏览器中执行上述操作。
这里有几个例子:
来自 Ivan Zuzak 的老 post 描述了他如何使用 Github 评论来构建动态评论系统(source). I recently recreated the system he described (using Github issues for comments) using some extra services: Zapier, the Zapier Github integration and the free version of Zoho forms。这使我能够让自定义网络表单将数据提交到 Github 问题,通过 Zapier(因此无需要求用户创建 Github 帐户)。
我在我的博客上使用 Github 问题作为评论,但您也许可以对其他内容(例如您的姓名列表)使用相同的解决方案。
来自 Staticman 网站:
Staticman handles user-generated content for you and transforms it into data files that sit in your GitHub repository, along with the rest of your content.
Staticman works perfectly with Jekyll sites hosted on GitHub Pages, as a push to your main branch will regenerate the site automatically. If you want to moderate entries before they are published, a pull request will be created for your approval; otherwise, files will be pushed to your main branch straight away.