Example #1
0
func ShowTagTemplate(writer http.ResponseWriter, r *http.Request, slug string, page int) error {
	// Read lock templates and global blog
	compiledTemplates.RLock()
	defer compiledTemplates.RUnlock()
	methods.Blog.RLock()
	defer methods.Blog.RUnlock()
	postIndex := int64(page - 1)
	if postIndex < 0 {
		postIndex = 0
	}
	tag, err := database.RetrieveTagBySlug(slug)
	if err != nil {
		return err
	}
	posts, err := database.RetrievePostsByTag(tag.Id, methods.Blog.PostsPerPage, (methods.Blog.PostsPerPage * postIndex))
	if err != nil {
		return err
	}
	requestData := structure.RequestData{Posts: posts, Blog: methods.Blog, CurrentIndexPage: page, CurrentTag: tag, CurrentTemplate: 2, CurrentPath: r.URL.Path} // CurrentTemplate = tag
	if template, ok := compiledTemplates.m["tag"]; ok {
		_, err = writer.Write(executeHelper(template, &requestData, 0)) // context = index
	} else {
		_, err = writer.Write(executeHelper(compiledTemplates.m["index"], &requestData, 0)) // context = index
	}
	if requestData.PluginVMs != nil {
		// Put the lua state map back into the pool
		plugins.LuaPool.Put(requestData.PluginVMs)
	}
	return err
}
Example #2
0
func ShowTagRss(writer http.ResponseWriter, slug string) error {
	// Read lock global blog
	methods.Blog.RLock()
	defer methods.Blog.RUnlock()
	tag, err := database.RetrieveTagBySlug(slug)
	if err != nil {
		return err
	}
	// 15 posts in rss for now
	posts, err := database.RetrievePostsByTag(tag.Id, 15, 0)
	if err != nil {
		return err
	}
	blogData := &structure.RequestData{Posts: posts, Blog: methods.Blog}
	feed := createFeed(blogData)
	err = feed.WriteRss(writer)
	return err
}