Ejemplo n.º 1
0
func SiteMap(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	println(baseUrl)
	article, _ := model.GetPublishArticleList(1, 50)
	navigators := model.GetNavigators()
	now := time.Unix(utils.Now(), 0).Format(time.RFC3339)

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
		articleMap[i] = m
	}

	navMap := make([]map[string]string, 0)
	for _, n := range navigators {
		m := make(map[string]string)
		if n.Link == "/" {
			continue
		}
		if strings.HasPrefix(n.Link, "/") {
			m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
		} else {
			m["Link"] = n.Link
		}
		m["Created"] = now
		navMap = append(navMap, m)
	}

	ctx.ContentType("text/xml")
	bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
		"Title":      model.GetSetting("site_title"),
		"Link":       baseUrl,
		"Created":    now,
		"Articles":   articleMap,
		"Navigators": navMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes

}
Ejemplo n.º 2
0
func AdminSetting(context *GoInk.Context) {
	if context.Method == "POST" {
		data := context.Input()
		for k, v := range data {
			if v == "" {
				if data[k+"_def"] != "" {
					v = data[k+"_def"]
				}
			}
			model.SetSetting(k, v)
		}
		model.SyncSettings()
		Json(context, true).End()
		context.Do("setting_saved")
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/setting", map[string]interface{}{
		"Title":      "配置",
		"Custom":     model.GetCustomSettings(),
		"Navigators": model.GetNavigators(),
	})
}