mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
24 lines
810 B
JavaScript
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;
|