Run git push from javascript hosted in static site - Stack Overflow

Imagine a static web site piled with jekyll and hosted on github pages. Is it possible to have some jav

Imagine a static web site piled with jekyll and hosted on github pages. Is it possible to have some javascript on this page that asks the user some input, and then "git push" this input into some github repository ?

In other words, how to write in javascript the following program:

  • Ask the user for his name, put the name in variable s
  • Download (or pull) from a given github repo a text file "allnames.txt"
  • Add s at the end of allnames.txt
  • Commit and push the file "allnames.txt" back into github

Of course, I understand the potential security risks, because the javascript code would need to embed private ssh keys. But this would be a fun way to add dynamicity to a static web site, and may be someone knows of some solution to make this secure ?

Thank you !

Imagine a static web site piled with jekyll and hosted on github pages. Is it possible to have some javascript on this page that asks the user some input, and then "git push" this input into some github repository ?

In other words, how to write in javascript the following program:

  • Ask the user for his name, put the name in variable s
  • Download (or pull) from a given github repo a text file "allnames.txt"
  • Add s at the end of allnames.txt
  • Commit and push the file "allnames.txt" back into github

Of course, I understand the potential security risks, because the javascript code would need to embed private ssh keys. But this would be a fun way to add dynamicity to a static web site, and may be someone knows of some solution to make this secure ?

Thank you !

Share Improve this question edited Oct 1, 2017 at 13:00 xtof54 asked Oct 1, 2017 at 10:07 xtof54xtof54 1,38311 silver badges17 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Check out Staticman

From the Staticman site:

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.

If you know the internals of git (blobs, trees, mits), then you should be able to implement a solution with the GitHub REST API. This is not going to be done in 5 minutes. As for security, you should be able to use OAuth, so no need for private ssh key.

Have a look at: https://developer.github./v3/git/

Alternative to using GitHub APIs, you can use one of the git clients written in JavaScript to do the actions you described above within the browser.

Here are a few examples:

https://github./creationix/js-git

https://github./danlucraft/git.js

An old post from Ivan Zuzak describes how he uses Github ment to build a dynamic menting system (source). I recently recreated the system he described (using Github issues for ments) using some extra services: Zapier, the Zapier Github integration and the free version of Zoho forms. This enabled me let a custom webform submit data to Github issues, through Zapier (so without asking users to create a Github account).

I used the Github issues as ments on my blog, but you might be able to use the same solution for something else (like your list of names).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743746714a4500138.html

相关推荐

  • Run git push from javascript hosted in static site - Stack Overflow

    Imagine a static web site piled with jekyll and hosted on github pages. Is it possible to have some jav

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信