예제 #1
0
func loadPage(filePath string, fullPost bool) Post {
	var contentString bytes.Buffer
	fileName := parseFilePathForFileName(filePath)

	// Read the file's contents
	contentByte, err := ioutil.ReadFile(filePath)
	common.CheckError(err)

	if !fullPost && len(contentByte) > trimByteLength {
		var contentByteTrimmed []byte

		for index, element := range contentByte {
			if index < trimByteLength {
				contentByteTrimmed = append(contentByteTrimmed, element)
			}
		}

		contentString.WriteString(string(contentByteTrimmed))
		contentString.WriteString(".. <a href='/blog/")
		contentString.WriteString(fileName)
		contentString.WriteString("'><small>Read more</small></a></div>")
	} else {
		contentString.WriteString(string(contentByte))
	}

	contentHTML := template.HTML(contentString.String())

	return Post{FileName: fileName, Title: parseFilePathForTitle(filePath), Date: parseFilePathForDate(filePath), Content: contentHTML, OneOfMany: !fullPost}
}
예제 #2
0
func main() {
	http.HandleFunc("/", blogPage)
	http.HandleFunc("/blog", blogPage)
	http.HandleFunc("/blog/", blogPage)

	http.HandleFunc("/about", aboutPage)
	http.HandleFunc("/about/", aboutPage)

	http.HandleFunc("/showcase/tmp/logictree", logictreehome.GetHomePage)

	http.HandleFunc("/showcase", showcasePage)
	http.HandleFunc("/showcase/", showcasePage)

	fileServer := http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
	http.Handle("/static/", fileServer)

	fileServer = http.StripPrefix("/logictree-static/", http.FileServer(http.Dir(logictreecommon.AppDir+"logictree-static")))
	http.Handle("/logictree-static/", fileServer)

	fileServer = http.StripPrefix("/resources/", http.FileServer(http.Dir("resources")))
	http.Handle("/resources/", fileServer)

	err := http.ListenAndServe(":8080", nil)
	common.CheckError(err)
}
예제 #3
0
func loadEmberTreetableShowcase(rw http.ResponseWriter) {
    type ShowCase struct {
        Additional  template.HTML
    }

    type Page struct {
        Title               string
        CurrentShowcase     string
        ShowCase            ShowCase
    }

    filePaths := []string{
        "resources/showcases/ember_treetable/templates/app.html",
        "resources/showcases/ember_treetable/templates/tree.html",
    }

    var contentString bytes.Buffer

    for _, filePath := range filePaths {
        // Read the file's contents
        contentByte, err := ioutil.ReadFile(filePath)
        common.CheckError(err)

        contentString.WriteString(string(contentByte))
    }

    contentHTML := template.HTML(contentString.String())

    s := ShowCase{Additional: contentHTML}
    p := Page{Title: "showcase", CurrentShowcase: "ember_treetable", ShowCase: s}

    tmpl := make(map[string]*template.Template)
    tmpl["showcase.html"] = template.Must(template.ParseFiles("resources/html/showcase.html", "resources/html/index.html", "resources/showcases/ember_treetable/showcase.html"))
    tmpl["showcase.html"].ExecuteTemplate(rw, "base", p)
}