Пример #1
0
func ShowAuthorTemplate(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
	}
	author, err := database.RetrieveUserBySlug(slug)
	if err != nil {
		return err
	}
	posts, err := database.RetrievePostsByUser(author.Id, methods.Blog.PostsPerPage, (methods.Blog.PostsPerPage * postIndex))
	if err != nil {
		return err
	}
	requestData := structure.RequestData{Posts: posts, Blog: methods.Blog, CurrentIndexPage: page, CurrentTemplate: 3, CurrentPath: r.URL.Path} // CurrentTemplate = author
	if template, ok := compiledTemplates.m["author"]; 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
}
Пример #2
0
func ShowAuthorRss(writer http.ResponseWriter, slug string) error {
	// Read lock global blog
	methods.Blog.RLock()
	defer methods.Blog.RUnlock()
	author, err := database.RetrieveUserBySlug(slug)
	if err != nil {
		return err
	}
	// 15 posts in rss for now
	posts, err := database.RetrievePostsByUser(author.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
}