mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Since the browser application cache appears not to support URL path routes in a non-buggy way (see https://github.com/meteor/meteor/pull/2926), applications using the appcache package will want to use hash fragment routes instead. This PR adds support to the spiderable package for hash fragment routes. An original URL such as `http://example.com/#!a=1&b=2` will be encoded by a search engine as an escaped fragment, decoded by the spiderable package, passed through to the phantomjs process, and appear to the phantom client as `#!a=1&b=2` in `window.location.hash` (the same as when the original URL is opened in a regular browser).
40 lines
1013 B
JavaScript
40 lines
1013 B
JavaScript
// 'url' is assigned to in a statement before this.
|
|
var page = require('webpage').create();
|
|
|
|
var isReady = function () {
|
|
return page.evaluate(function () {
|
|
if (typeof Meteor === 'undefined'
|
|
|| Meteor.status === undefined
|
|
|| !Meteor.status().connected) {
|
|
return false;
|
|
}
|
|
if (typeof Package === 'undefined'
|
|
|| Package.spiderable === undefined
|
|
|| Package.spiderable.Spiderable === undefined
|
|
|| !Package.spiderable.Spiderable._initialSubscriptionsStarted) {
|
|
return false;
|
|
}
|
|
Tracker.flush();
|
|
return DDP._allSubscriptionsReady();
|
|
});
|
|
};
|
|
|
|
var dumpPageContent = function () {
|
|
var out = page.content;
|
|
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
|
|
out = out.replace('<meta name="fragment" content="!">', '');
|
|
console.log(out);
|
|
};
|
|
|
|
page.open(url, function(status) {
|
|
if (status === 'fail')
|
|
phantom.exit();
|
|
});
|
|
|
|
setInterval(function() {
|
|
if (isReady()) {
|
|
dumpPageContent();
|
|
phantom.exit();
|
|
}
|
|
}, 100);
|