Exemplo n.º 1
0
func entrybar(blog_config map[string]interface{}, w http.ResponseWriter, req *http.Request) {
	template_dir := "templates/"
	appcontext := appengine.NewContext(req)
	myurl, err := realhostname(req, appcontext)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	scheme := "http://"
	if req.TLS != nil {
		scheme = "https://"
	}

	urlprefix := scheme + myurl + config.Stringify(blog_config["blog_root"])

	postchan := make(chan post.Post, 16)
	errchan := make(chan error)
	go post.ExecuteQuery(appcontext, post.GetAllPosts(), -1, -1, func(post.Post) bool { return true }, postchan, errchan)

	for p := range postchan {
		context := map[string]interface{}{"url": urlprefix + "article/" + p.StickyUrl,
			"lastmod_date": p.Postdate.Format("2006-01-02")}
		total_con := config.Stringify_map(config.Merge(blog_config, context))
		c := mustache.RenderFile(template_dir+"edit_entrybar.html.mustache", total_con)
		io.WriteString(w, c)
	}

	err, ok := <-errchan
	if ok {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}
Exemplo n.º 2
0
func GetSitemap(blog_config map[string]interface{}) func(w http.ResponseWriter, req *http.Request) {
	template_dir := "templates/"
	l := func(w http.ResponseWriter, req *http.Request) {
		appcontext := appengine.NewContext(req)

		myurl, err := realhostname(req, appcontext)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		scheme := "http://"
		if req.TLS != nil {
			scheme = "https://"
		}

		urlprefix := scheme + myurl + config.Stringify(blog_config["blog_root"])

		postchan := make(chan post.Post, 16)
		errchan := make(chan error)
		go post.ExecuteQuery(appcontext, post.GetAllPosts(), -1, -1, post.NullFilter, postchan, errchan)

		entries := bytes.NewBufferString("")

		me_context := map[string]interface{}{"url": urlprefix,
			"lastmod_date": post.GetLatestDate(appcontext).Format("2006-01-02")}
		me_total_con := config.Stringify_map(config.Merge(blog_config, me_context))
		me_c := mustache.RenderFile(template_dir+"sitemap_entry.mustache", me_total_con)
		io.WriteString(entries, me_c)
		for p := range postchan {
			context := map[string]interface{}{"url": urlprefix + "article/" + p.StickyUrl,
				"lastmod_date": p.Postdate.Format("2006-01-02")}
			total_con := config.Stringify_map(config.Merge(blog_config, context))
			c := mustache.RenderFile(template_dir+"sitemap_entry.mustache", total_con)
			io.WriteString(entries, c)
		}

		err, ok := <-errchan
		if ok {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		context := map[string]interface{}{"content": entries}
		total_con := config.Stringify_map(config.Merge(blog_config, context))
		c := mustache.RenderFile(template_dir+"sitemap.mustache", total_con)
		io.WriteString(w, c)
	}
	return l
}