module_settings_act_robots_txt.go 585 B

123456789101112131415161718192021222324252627
  1. package modules
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "golang-fave/engine/wrapper"
  6. )
  7. func (this *Modules) RegisterAction_SettingsRobotsTxt() *Action {
  8. return this.newAction(AInfo{
  9. Mount: "settings-robots-txt",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_content := wrap.R.FormValue("content")
  13. // Save robots.txt content
  14. err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+"robots.txt", []byte(pf_content), 0664)
  15. if err != nil {
  16. wrap.MsgError(err.Error())
  17. return
  18. }
  19. // Reload current page
  20. wrap.Write(`window.location.reload(false);`)
  21. })
  22. }