Browse Source

Settings, robots.txt update action

Vova Tkach 6 years ago
parent
commit
febf330d84
2 changed files with 22 additions and 2 deletions
  1. 2 2
      hosts/localhost/template/robots.txt
  2. 20 0
      modules/module_settings.go

+ 2 - 2
hosts/localhost/template/robots.txt

@@ -1,2 +1,2 @@
-User-agent: *
-Disallow: /
+User-agent: *
+Disallow: /

+ 20 - 0
modules/module_settings.go

@@ -65,3 +65,23 @@ func (this *Modules) RegisterModule_Settings() *Module {
 		return this.getSidebarModules(wrap), content, sidebar
 	})
 }
+
+func (this *Modules) RegisterAction_SettingsRobotsTxt() *Action {
+	return this.newAction(AInfo{
+		WantDB:    true,
+		Mount:     "settings-robots-txt",
+		WantAdmin: true,
+	}, func(wrap *wrapper.Wrapper) {
+		pf_content := wrap.R.FormValue("content")
+
+		// Save robots.txt content
+		err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+"robots.txt", []byte(pf_content), 0664)
+		if err != nil {
+			wrap.MsgError(err.Error())
+			return
+		}
+
+		// Reload current page
+		wrap.Write(`window.location.reload(false);`)
+	})
+}