简体   繁体   English

如何在网站上嵌入github git README文件

[英]how to embed a github git README file on a website

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. 我正在为某人建立一个网站,他们希望能够让该网站在某个URL上获取github readme markdown文件并将其显示在网站上,这样就不必在两个地方写自述文件了来自github。 Is that possible? 那可能吗? How do I do it? 我该怎么做? I saw this: 我看到了这个:

https://github.com/coreyti/showdown 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. 这将markdown转换为html,但我仍然不知道如何获取自述文件URL并将其转换为showdown可以解析的对象。

Any ideas would be greatly appreciated. 任何想法将不胜感激。

GitHub has an option to show file source, Raw button in top right corner. GitHub有一个显示文件源的选项,右上角是Raw按钮。 Raw link for your example is: https://raw.github.com/coreyti/showdown/master/README.md 您的示例的原始链接是: 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. 假设README文件已经在Markdown格式化,您可以只获取源并将其格式化,您的语言很可能已经存在库。

UPDATE UPDATE

I wouldn't actually download file from GitHub every time the page on your site is requested. 每次请求您网站上的页面时,我都不会从GitHub下载文件。 GitHub may be down, connection may be slow -- and this will affect visitors of your site. GitHub可能已关闭,连接速度可能会很慢 - 这会影响网站的访问者。 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. 相反,您可能希望在服务器上运行一个cron作业,该程序将从GitHub下载文件,例如每五分钟一次,并在本地缓存它。 Then, every time you need to display the file, you'll read a local copy and don't depend on GitHub server being accessible. 然后,每次需要显示文件时,您将读取本地副本,而不依赖于可访问的GitHub服务器。 As a drawback, you will have a certain synchronization delay (5 minutes in my example). 作为一个缺点,您将有一定的同步延迟(在我的示例中为5分钟)。

You can use StackEdit . 您可以使用StackEdit It allows you to publish your markdown document on Github and on others locations at the same time in Markdown or HTML format. 它允许您以Markdown或HTML格式同时在Github和其他位置发布降价文档。 For instance, you could publish the HTML on a public Google Drive or Dropbox location. 例如,您可以在公共Google云端硬盘或Dropbox位置发布HTML。

NOTE: I'm the developer of StackEdit 注意:我是StackEdit的开发人员

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM