Beispiel #1
0
func (m *Markdown) Serve(talk core.Talk) {
	data, err := ioutil.ReadAll(talk.Request())
	if err != nil {
		//TODO Do error handling?
	}
	out := mark.Render(string(data))
	talk.Respond() <- strings.NewReader(out)
}
Beispiel #2
0
func (s *Site) CreatePage(name string, wg *sync.WaitGroup) {
	defer wg.Done()
	remote := strings.TrimSuffix(globalFlags.remoteDrive, "/") +
		"/read/blau.io/content/" + name
	req, err := http.NewRequest("GET", remote, nil)
	if err != nil {
		log.Printf("Error while creating request: %v", err)
		return
	}

	req.AddCookie(&http.Cookie{
		Name:  "token",
		Value: s.Token,
	})

	resp, err := client.Do(req)
	if err != nil {
		log.Printf("Error while making request: %v", err)
		return
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Printf("Error while reading response: %v", err)
		return
	}

	header, err := ioutil.ReadFile("html/header.html")
	if err != nil {
		log.Printf("Error loading header.html: %v", err)
		return
	}

	footer, err := ioutil.ReadFile("html/footer.html")
	if err != nil {
		log.Printf("Error loading footer.html: %v", err)
		return
	}

	name = strings.Replace(name, ".md", ".html", -1)

	remote = strings.TrimSuffix(globalFlags.remoteDrive, "/") +
		"/delete/blau.io/PUBLIC/" + name
	req, err = http.NewRequest("DELETE", remote, nil)
	if err != nil {
		log.Printf("Couldn't create new request: %v", err)
		return
	}

	req.AddCookie(&http.Cookie{
		Name:  "token",
		Value: s.Token,
	})

	_, _ = client.Do(req) // Fail gracefully

	reqBody := string(header) + mark.Render(string(body)) + string(footer)

	remote = strings.TrimSuffix(globalFlags.remoteDrive, "/") +
		"/add/blau.io/PUBLIC/" + name
	req, err = http.NewRequest("POST", remote, strings.NewReader(reqBody))
	if err != nil {
		log.Printf("Error while creating request: %v", err)
		return
	}

	req.AddCookie(&http.Cookie{
		Name:  "token",
		Value: s.Token,
	})

	_, err = client.Do(req)
	if err != nil {
		log.Printf("Error while making request: %v", err)
		return
	}
}
Beispiel #3
0
// Helper for rendering markdown.
func toMarkdown(src string) template.HTML {
	return template.HTML(mark.Render(src))
}