Exemple #1
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
}
Exemple #2
0
func GetRSS(blog_config map[string]interface{}) func(w http.ResponseWriter, req *http.Request) {
	template_dir := "templates/"
	l := func(w http.ResponseWriter, req *http.Request) {
		limit, err := getLimit(blog_config)
		if err != nil {
			panic(err)
		}

		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"])

		keys, err := post.GetPostsMatchingTag(appcontext, "visible")
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}

		idx := len(keys)

		offset := 0

		entries := new(bytes.Buffer)
		if idx >= 1 {
			postchan := make(chan post.FullPost, 16)
			errchan := make(chan error)

			go post.GetPosts(appcontext, keys, offset, limit, postchan, errchan)
			for p := range postchan {
				con := bytes.NewBuffer(blackfriday.MarkdownCommon(bytes.NewBufferString(p.Content).Bytes())).String()
				context := map[string]interface{}{"c": con,
					"link_to_entry": urlprefix + "article/" + p.Post.StickyUrl,
					"post_date":     p.Post.Postdate.Format("Jan 02 2006"),
					"post_title":    p.Post.Title}
				total_con := config.Stringify_map(config.Merge(blog_config, context))
				c := mustache.RenderFile(template_dir+"rss_entry.html.mustache", total_con)
				io.WriteString(entries, c)
			}
			err, ok := <-errchan
			if ok {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}

		}

		context := map[string]interface{}{
			"lastmod_date": post.GetLatestDate(appcontext).Format("2006-01-02"),
			"content":      entries,
		}

		total_con := config.Stringify_map(config.Merge(blog_config, context))
		c := mustache.RenderFile(template_dir+"rss.mustache", total_con)
		io.WriteString(w, c)
	}
	return l
}