Example #1
0
func IndexHandler(rr render.Render, w http.ResponseWriter, r *http.Request) {
	var pp models.Post
	p := make([]models.Post, 0)
	namefs := utils.Getlistfileindirectory(Pathposts)
	tnamefs := namefs
	vsegopost := len(namefs)
	if len(namefs) != 0 {
		namefs = utils.SorttoDown(namefs)
		if Kolpost > len(namefs) {
			tnamefs = namefs[:]
		} else {
			tnamefs = namefs[:Kolpost]
		}

		for _, namef := range tnamefs {
			pp.GetPostfromFileMd(Pathposts + string(os.PathSeparator) + namef)
			if !pp.GetDraft() { // не отражаются черновики
				p = append(p, pp)
			}
		}
	} else {
		p = append(p, models.Post{Id: "ПОСТОВ НЕТ", Title: "ЭТОТ БЛОГ ПУСТ. ПРИХОДИТЕ ПОЗЖЕ ;)", ContentText: ""})
	}

	rr.HTML(200, "index", &models.PagePost{TitlePage: "Блог проектов kaefik", Posts: p, Postright: vsegopost - Kolpost})
}
Example #2
0
// просмотр посты блога
func ViewHandler(rr render.Render, w http.ResponseWriter, r *http.Request, params martini.Params) {
	var pp models.Post
	p := make([]models.Post, 0)
	numpost, _ := strconv.Atoi(params["numpost"])
	namefs := utils.Getlistfileindirectory(Pathposts)
	namefs = utils.SorttoUp(namefs)
	tnamefs := namefs
	vsegopost := len(namefs)

	if numpost <= 0 {
		numpost = len(namefs)
	}

	if numpost >= len(namefs) {
		if Kolpost > len(namefs) {
			tnamefs = namefs[:]
		} else {
			tnamefs = namefs[len(namefs)-Kolpost:]
		}

		if len(namefs) != 0 {
			for k := len(tnamefs) - 1; k >= 0; k-- {
				namef := tnamefs[k]
				pp.GetPostfromFileMd(Pathposts + string(os.PathSeparator) + namef)
				p = append(p, pp)
			}
		} else {
			p = append(p, models.Post{Id: "ПОСТОВ НЕТ", Title: "ЭТОТ БЛОГ ПУСТ. ПРИХОДИТЕ ПОЗЖЕ ;)", ContentText: ""})
		}
		rr.HTML(200, "view", &models.PagePost{TitlePage: "Блог проектов kaefik", Posts: p, Postright: vsegopost - Kolpost})
		return
	}
	if len(namefs) != 0 {
		kk := numpost - Kolpost
		if kk <= 0 {
			kk = 0
		} else {
			kk = numpost - Kolpost // - 1
		}
		tnamefs := namefs[kk:numpost]

		if len(namefs) != 0 {
			for k := len(tnamefs) - 1; k >= 0; k-- {
				namef := tnamefs[k]
				pp.GetPostfromFileMd(Pathposts + string(os.PathSeparator) + namef)
				p = append(p, pp)
			}
		}
	} else {
		rr.Redirect("/")
		return
	}
	rr.HTML(200, "view", &models.PagePost{TitlePage: "Блог проектов kaefik", Posts: p, Postleft: numpost + Kolpost, Postright: numpost - Kolpost})
}
Example #3
0
func parseCmdArgs() bool {
	res := false
	var p models.Post
	lenargs := len(os.Args)
	if lenargs == 2 {
		if os.Args[1] == "help" {
			fmt.Println("new post -  create new post")
			res = true
		}
	}
	if lenargs == 3 { // два аргумента
		if (os.Args[1] == "new") && (os.Args[2] == "post") {
			fmt.Println("create new post in directory: ", routes.Pathposts)
			p.New()
			p.SavetoFile(routes.Pathposts + string(os.PathSeparator) + "newfile.md")
			res = true
		}
	}
	return res
}