Last active
February 19, 2019 10:08
-
-
Save williamlsh/ac038420821b3c849ed22b60b517d006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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