Esempio n. 1
0
func makeMainPage(indexFile string, pkg string) (err error) {

	log.Info("makeMainPage", indexFile, "of", pkg)

	b, err := ioutil.ReadFile(indexFile)
	if err != nil {
		return
	}

	readmeFile := "https://" + pkg + "/blob/master/README.md"
	div, err := renderGithubMarkdown(readmeFile)
	if err != nil {
		return
	}

	var mainPageDocStart bytes.Buffer
	fmt.Fprintf(&mainPageDocStart, srcMainPageDocStartTempl, projectNameOf(pkg))
	pos := bytes.Index(b, mainPageDocStart.Bytes())
	if pos >= 0 {
		destMainPage := make([]byte, 0, len(div)+len(destMainPageDocStart)+len(destMainPageDocEnd))
		destMainPage = append(destMainPage, destMainPageDocStart...)
		destMainPage = append(destMainPage, div...)
		destMainPage = append(destMainPage, destMainPageDocEnd...)
		b = xbytes.ReplaceAt(b, pos, mainPageDocStart.Len(), destMainPage)
		b = xbytes.Replace(b, srcStyleSheet, destStyleSheet, 1)
		err = ioutil.WriteFile(indexFile, b, 0666)
	}
	return
}
Esempio n. 2
0
func serveContent(
	w http.ResponseWriter, req *http.Request,
	pkg, name string, modtime time.Time, content io.ReadSeeker) {

	if !strings.HasSuffix(name, ".html") {
		http.ServeContent(w, req, name, modtime, content)
		return
	}

	b, err := ioutil.ReadAll(content)
	if err != nil {
		httputil.Error(w, err)
		return
	}

	var destFooter bytes.Buffer
	fmt.Fprintf(&destFooter, destFooterTempl, pkg)

	b = xbytes.Replace(b, srcFooter, destFooter.Bytes(), 1)
	b = xbytes.Replace(b, srcPoweredBy, destPoweredBy, 1)

	http.ServeContent(w, req, name, modtime, bytes.NewReader(b))
}