Files
discourse/app/assets/javascripts/discourse/models/static-page.js.es6
2016-07-11 12:57:05 -04:00

24 lines
810 B
JavaScript

import { ajax } from 'discourse/lib/ajax';
const StaticPage = Ember.Object.extend();
StaticPage.reopenClass({
find(path) {
return new Ember.RSVP.Promise(resolve => {
// Models shouldn't really be doing Ajax request, but this is a huge speed boost if we
// preload content.
const $preloaded = $("noscript[data-path=\"/" + path + "\"]");
if ($preloaded.length) {
let text = $preloaded.text();
text = text.match(/<!-- preload-content: -->((?:.|[\n\r])*)<!-- :preload-content -->/)[1];
resolve(StaticPage.create({path: path, html: text}));
} else {
ajax(path + ".html", {dataType: 'html'}).then(function (result) {
resolve(StaticPage.create({path: path, html: result}));
});
}
});
}
});
export default StaticPage;