FEATURE: Allow customization of robots.txt (#7884)

* FEATURE: Allow customization of robots.txt

This allows admins to customize/override the content of the robots.txt
file at /admin/customize/robots. That page is not linked to anywhere in
the UI -- admins have to manually type the URL to access that page.

* use Ember.computed.not

* Jeff feedback

* Feedback

* Remove unused import
This commit is contained in:
Osama Sayegh
2019-07-15 20:47:44 +03:00
committed by GitHub
parent 90e0f1b378
commit 6515ff19e5
12 changed files with 282 additions and 7 deletions

View File

@@ -0,0 +1,45 @@
import { ajax } from "discourse/lib/ajax";
import { bufferedProperty } from "discourse/mixins/buffered-content";
import { propertyEqual } from "discourse/lib/computed";
export default Ember.Controller.extend(bufferedProperty("model"), {
saved: false,
isSaving: false,
saveDisabled: propertyEqual("model.robots_txt", "buffered.robots_txt"),
resetDisbaled: Ember.computed.not("model.overridden"),
actions: {
save() {
this.setProperties({
isSaving: true,
saved: false
});
ajax("robots.json", {
method: "PUT",
data: { robots_txt: this.buffered.get("robots_txt") }
})
.then(data => {
this.commitBuffer();
this.set("saved", true);
this.set("model.overridden", data.overridden);
})
.finally(() => this.set("isSaving", false));
},
reset() {
this.setProperties({
isSaving: true,
saved: false
});
ajax("robots.json", { method: "DELETE" })
.then(data => {
this.buffered.set("robots_txt", data.robots_txt);
this.commitBuffer();
this.set("saved", true);
this.set("model.overridden", false);
})
.finally(() => this.set("isSaving", false));
}
}
});

View File

@@ -0,0 +1,7 @@
import { ajax } from "discourse/lib/ajax";
export default Ember.Route.extend({
model() {
return ajax("/admin/customize/robots");
}
});

View File

@@ -86,6 +86,10 @@ export default function() {
this.route("edit", { path: "/:id" });
}
);
this.route("adminCustomizeRobotsTxt", {
path: "/robots",
resetNamespace: true
});
}
);

View File

@@ -0,0 +1,20 @@
<div class="robots-txt-edit">
<h3>{{i18n "admin.customize.robots.title"}}</h3>
<p>{{i18n "admin.customize.robots.warning"}}</p>
{{#if model.overridden}}
<div class="overridden">
{{i18n "admin.customize.robots.overridden"}}
</div>
{{/if}}
{{textarea
value=buffered.robots_txt
class="robots-txt-input"}}
{{#save-controls model=this action=(action "save") saved=saved saveDisabled=saveDisabled}}
{{d-button
class="btn-default"
disabled=resetDisbaled
icon="undo"
action=(action "reset")
label="admin.settings.reset"}}
{{/save-controls}}
</div>

View File

@@ -777,3 +777,16 @@
margin-left: 1em;
}
}
.robots-txt-edit {
div.overridden {
background: $highlight-medium;
padding: 7px;
margin-bottom: 7px;
}
.robots-txt-input {
width: 100%;
box-sizing: border-box;
height: 600px;
}
}