From 5fa7909eb12ead33b154251f6aa990a64686433e Mon Sep 17 00:00:00 2001 From: Kirill Danshin Date: Tue, 11 Oct 2016 04:30:20 +0300 Subject: [PATCH] fix links --- repo.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/repo.go b/repo.go index 194d4022..9c53515c 100644 --- a/repo.go +++ b/repo.go @@ -11,27 +11,74 @@ import ( "github.com/russross/blackfriday" ) +// memory usage optimizations +const ( + emtyStr = "" + git = "git" + checkout = "checkout" + force = "-f" + pull = "pull" + + // options + readmePath = "./README.md" + tplPath = "tmpl/tmpl.html" + idxPath = "tmpl/index.html" + + bfHTMLRendererOpts = 0 | + blackfriday.HTML_USE_XHTML | + blackfriday.HTML_USE_SMARTYPANTS | + blackfriday.HTML_SMARTYPANTS_FRACTIONS | + blackfriday.HTML_SMARTYPANTS_DASHES | + blackfriday.HTML_SMARTYPANTS_LATEX_DASHES + + bfMDOpts = 0 | + blackfriday.EXTENSION_NO_INTRA_EMPHASIS | + blackfriday.EXTENSION_TABLES | + blackfriday.EXTENSION_FENCED_CODE | + blackfriday.EXTENSION_AUTOLINK | + blackfriday.EXTENSION_STRIKETHROUGH | + blackfriday.EXTENSION_SPACE_HEADERS | + blackfriday.EXTENSION_HEADER_IDS | + blackfriday.EXTENSION_BACKSLASH_LINE_BREAK | + blackfriday.EXTENSION_DEFINITION_LISTS | + blackfriday.EXTENSION_AUTO_HEADER_IDS +) + +var ( + doneResp = []byte("Done!\n") +) + type content struct { Body string } func generateHTML() { // Update repo - exec.Command("git", "checkout", "-f").Output() - exec.Command("git", "pull").Output() + exec.Command(git, checkout, force).Output() + exec.Command(git, pull).Output() - input, _ := ioutil.ReadFile("./README.md") - body := string(blackfriday.MarkdownCommon(input)) + input, _ := ioutil.ReadFile(readmePath) + body := string( + blackfriday.Markdown( + input, + blackfriday.HtmlRenderer( + bfHTMLRendererOpts, + emtyStr, + emtyStr, + ), + bfMDOpts, + ), + ) c := &content{Body: body} - t := template.Must(template.ParseFiles("tmpl/tmpl.html")) - f, _ := os.Create("tmpl/index.html") + t := template.Must(template.ParseFiles(tplPath)) + f, _ := os.Create(idxPath) t.Execute(f, c) } func hookHandler(w http.ResponseWriter, r *http.Request) { go generateHTML() - w.Write([]byte("Done!\n")) + w.Write(doneResp) } func main() {