mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Move spiderable phantom script to an asset
This commit is contained in:
@@ -11,6 +11,8 @@ Package.on_use(function (api) {
|
||||
|
||||
api.add_files('spiderable.html', 'client');
|
||||
api.add_files('spiderable.js', 'server');
|
||||
|
||||
api.add_files('phantom_script.js', 'server', { isAsset: true });
|
||||
});
|
||||
|
||||
Package.on_test(function (api) {
|
||||
|
||||
22
packages/spiderable/phantom_script.js
Normal file
22
packages/spiderable/phantom_script.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// 'url' is assigned to in a statement before this.
|
||||
var page = require('webpage').create();
|
||||
page.open(url);
|
||||
setInterval(function() {
|
||||
var ready = page.evaluate(function () {
|
||||
if (typeof Meteor !== 'undefined'
|
||||
&& typeof(Meteor.status) !== 'undefined'
|
||||
&& Meteor.status().connected) {
|
||||
Deps.flush();
|
||||
return DDP._allSubscriptionsReady();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (ready) {
|
||||
var out = page.content;
|
||||
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
|
||||
out = out.replace('<meta name="fragment" content="!">', '');
|
||||
console.log(out);
|
||||
phantom.exit();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
@@ -47,6 +47,8 @@ Spiderable._urlForPhantom = function (siteAbsoluteUrl, requestUrl) {
|
||||
return urlParser.format(parsedAbsoluteUrl);
|
||||
};
|
||||
|
||||
var PHANTOM_SCRIPT = Assets.getText("phantom_script.js");
|
||||
|
||||
WebApp.connectHandlers.use(function (req, res, next) {
|
||||
// _escaped_fragment_ comes from Google's AJAX crawling spec:
|
||||
// https://developers.google.com/webmasters/ajax-crawling/docs/specification
|
||||
@@ -68,26 +70,7 @@ WebApp.connectHandlers.use(function (req, res, next) {
|
||||
// be able to contain newlines, it should be unable to exploit bash as
|
||||
// well.
|
||||
var phantomScript = "var url = " + JSON.stringify(url) + ";" +
|
||||
"var page = require('webpage').create();" +
|
||||
"page.open(url);" +
|
||||
"setInterval(function() {" +
|
||||
" var ready = page.evaluate(function () {" +
|
||||
" if (typeof Meteor !== 'undefined' " +
|
||||
" && typeof(Meteor.status) !== 'undefined' " +
|
||||
" && Meteor.status().connected) {" +
|
||||
" Deps.flush();" +
|
||||
" return DDP._allSubscriptionsReady();" +
|
||||
" }" +
|
||||
" return false;" +
|
||||
" });" +
|
||||
" if (ready) {" +
|
||||
" var out = page.content;" +
|
||||
" out = out.replace(/<script[^>]+>(.|\\n|\\r)*?<\\/script\\s*>/ig, '');" +
|
||||
" out = out.replace('<meta name=\"fragment\" content=\"!\">', '');" +
|
||||
" console.log(out);" +
|
||||
" phantom.exit();" +
|
||||
" }" +
|
||||
"}, 100);\n";
|
||||
PHANTOM_SCRIPT;
|
||||
|
||||
// Run phantomjs.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user