Skip to content

Instantly share code, notes, and snippets.

@williamlsh
Last active February 19, 2019 10:08
Show Gist options
  • Save williamlsh/ac038420821b3c849ed22b60b517d006 to your computer and use it in GitHub Desktop.
Save williamlsh/ac038420821b3c849ed22b60b517d006 to your computer and use it in GitHub Desktop.
var (
postContentType = "text/plain"
articlesDir = "articles"
htmlExt = ".html"
)
// renderMarkdown posts raw markdown texts to Github REST api service to render.
// It then writes a rendered HTML file with the same name as its coresponding article tile under articles directory.
func renderMarkdown(articlesDir, title string, body io.Reader) (err error) {
resp, err := http.Post(url, postContentType, body)
if err != nil {
fmt.Printf("post markdown raw text to github: %v", err)
return
}
file, err := os.Create(fmt.Sprintf("%s/%s%s", articlesDir, title, htmlExt))
if err != nil {
return
}
_, err = io.Copy(file, resp.Body)
resp.Body.Close()
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment