最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to embed a github git README file on a website - Stack Overflow

programmeradmin4浏览0评论

I am making a website for someone and they want to be able to have that site fetch the github readme markdown file at a certain URL and display it on the website, so that instead of having to write the readme in two places, it just pulls from github. Is that possible? How do I do it? I saw this:

which turns markdown into html, but I'm still not how I would fetch the readme URL and convert it into an object that showdown could parse.

Any ideas would be greatly appreciated.

I am making a website for someone and they want to be able to have that site fetch the github readme markdown file at a certain URL and display it on the website, so that instead of having to write the readme in two places, it just pulls from github. Is that possible? How do I do it? I saw this:

https://github.com/coreyti/showdown

which turns markdown into html, but I'm still not how I would fetch the readme URL and convert it into an object that showdown could parse.

Any ideas would be greatly appreciated.

Share Improve this question asked Apr 25, 2013 at 23:08 mheaversmheavers 30.2k62 gold badges198 silver badges326 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 5

You can use StackEdit. It allows you to publish your markdown document on Github and on others locations at the same time in Markdown or HTML format. For instance, you could publish the HTML on a public Google Drive or Dropbox location.

NOTE: I'm the developer of StackEdit

GitHub has an option to show file source, Raw button in top right corner. Raw link for your example is: https://raw.github.com/coreyti/showdown/master/README.md

Assuming that README file is formatted in Markdown already, you could just fetch source and format it on your side, libraries most probably already exist for your language.

UPDATE

I wouldn't actually download file from GitHub every time the page on your site is requested. GitHub may be down, connection may be slow -- and this will affect visitors of your site. Instead, you may want to have a cron job running on the server that would download a file from GitHub, say, every five minutes, and cache it locally. Then, every time you need to display the file, you'll read a local copy and don't depend on GitHub server being accessible. As a drawback, you will have a certain synchronization delay (5 minutes in my example).

I’ve written riss.awk to insert a README.md on your website, optionally performing some transformations in the process.

be able to have that site fetch the github readme

You can automatically fetch the original README.md file like this:

curl https://raw.githubusercontent.com/cljoly/readme-in-static-site/main/README.md | awk -f riss.awk >readme-in-static-site.md

convert it into an object that showdown could parse

I couldn’t find showdown’s documentation, but there might be some kind of API you could use to upload the file generated above (readme-in-static-site.md)? A cronjob-like task could then run this process every few hours to keep things up to date.

Heroku seems to be doing it by copying the rendered html https://elements.heroku.com/buildpacks/stouffi/heroku-i18n-js-buildpack-ruby#buildpack-instructions

发布评论

评论列表(0)

  1. 暂无评论