From 785995b4730c3e9bf556fd4e9d2f772d457d918c Mon Sep 17 00:00:00 2001 From: yackob03 Date: Thu, 10 Oct 2013 20:53:14 -0400 Subject: [PATCH] First stab at trying to pre-render content for search crawlers. --- requirements-nover.txt | 3 ++- seo-snapshots/make_snapshot.py | 29 +++++++++++++++++++++++++++++ seo-snapshots/phantomjs-runner.js | 23 +++++++++++++++++++++++ static/js/controllers.js | 5 ++++- static/partials/guide.html | 2 +- static/partials/landing.html | 2 +- 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 seo-snapshots/make_snapshot.py create mode 100644 seo-snapshots/phantomjs-runner.js diff --git a/requirements-nover.txt b/requirements-nover.txt index 69d73fb1b..cd844d0cb 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -10,4 +10,5 @@ pymysql stripe gunicorn eventlet -mixpanel-py \ No newline at end of file +mixpanel-py +beautifulsoup4 \ No newline at end of file diff --git a/seo-snapshots/make_snapshot.py b/seo-snapshots/make_snapshot.py new file mode 100644 index 000000000..75ab0be9d --- /dev/null +++ b/seo-snapshots/make_snapshot.py @@ -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()) \ No newline at end of file diff --git a/seo-snapshots/phantomjs-runner.js b/seo-snapshots/phantomjs-runner.js new file mode 100644 index 000000000..e001b73c8 --- /dev/null +++ b/seo-snapshots/phantomjs-runner.js @@ -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); + } + }); +} diff --git a/static/js/controllers.js b/static/js/controllers.js index 57eacb213..f297c9282 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -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) { diff --git a/static/partials/guide.html b/static/partials/guide.html index 4020cb287..5ee657c1d 100644 --- a/static/partials/guide.html +++ b/static/partials/guide.html @@ -1,4 +1,4 @@ -
+
Warning: Quay requires docker version 0.6.2 or higher to work

Getting started guide

diff --git a/static/partials/landing.html b/static/partials/landing.html index b7e2d6248..2baf6baec 100644 --- a/static/partials/landing.html +++ b/static/partials/landing.html @@ -1,4 +1,4 @@ -
+