module_settings_act_robots_txt.go 604 B

12345678910111213141516171819202122232425262728
  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. WantDB: true,
  10. Mount: "settings-robots-txt",
  11. WantAdmin: true,
  12. }, func(wrap *wrapper.Wrapper) {
  13. pf_content := wrap.R.FormValue("content")
  14. // Save robots.txt content
  15. err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+"robots.txt", []byte(pf_content), 0664)
  16. if err != nil {
  17. wrap.MsgError(err.Error())
  18. return
  19. }
  20. // Reload current page
  21. wrap.Write(`window.location.reload(false);`)
  22. })
  23. }