First stab at trying to pre-render content for search crawlers.

This commit is contained in:
yackob03 2013-10-10 20:53:14 -04:00
parent ce81431cd3
commit 785995b473
6 changed files with 60 additions and 4 deletions

View file

@ -10,4 +10,5 @@ pymysql
stripe
gunicorn
eventlet
mixpanel-py
mixpanel-py
beautifulsoup4

View file

@ -0,0 +1,29 @@
import subprocess
import urllib
from BeautifulSoup import BeautifulSoup
BASE_URL = 'http://localhost:5000'
OUTPUT_PATH = 'snapshots/'
URLS = [
('/', 'index.html')
]
for url, output in URLS:
final_url = BASE_URL + url
out_html = subprocess.check_output(['phantomjs', 'phantomjs-runner.js',
final_url])
# Remove script tags
soup = BeautifulSoup(out_html)
to_extract = soup.findAll('script')
for item in to_extract:
item.extract()
to_write = OUTPUT_PATH + output
with open(to_write, 'w') as output_file:
output_file.write(soup.prettify())

View file

@ -0,0 +1,23 @@
var system = require('system');
var url = system.args[1] || '';
if(url.length > 0) {
var page = require('webpage').create();
page.open(url, function (status) {
if (status == 'success') {
var delay, checker = (function() {
var html = page.evaluate(function () {
var ready = document.getElementsByClassName('ready-indicator')[0];
if(ready.getAttribute('data-status') == 'ready') {
return document.getElementsByTagName('html')[0].outerHTML;
}
});
if(html) {
clearTimeout(delay);
console.log(html);
phantom.exit();
}
});
delay = setInterval(checker, 100);
}
});
}

View file

@ -93,7 +93,8 @@ function PlansCtrl($scope, UserService, PlanService) {
};
}
function GuideCtrl($scope, Restangular) {
function GuideCtrl($scope) {
$scope.status = 'ready';
}
function RepoListCtrl($scope, Restangular, UserService) {
@ -194,6 +195,8 @@ function LandingCtrl($scope, $timeout, Restangular, UserService, KeyService) {
$scope.loadingmyrepos = false;
});
};
$scope.status = 'ready';
}
function RepoCtrl($scope, Restangular, $routeParams, $rootScope) {

View file

@ -1,4 +1,4 @@
<div class="container">
<div class="container ready-indicator" data-status="{{ status }}">
<div class="alert alert-warning">Warning: Quay requires docker version 0.6.2 or higher to work</div>
<h2>Getting started guide</h2>

View file

@ -1,4 +1,4 @@
<div class="jumbotron landing">
<div class="jumbotron landing ready-indicator" data-status="{{ status }}">
<div class="container">
<div class="row messages">
<div class="col-md-7">