From 78aa491fee19eb2cf1cecd49bed5744821bbafc2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 21 Jan 2015 13:31:07 -0700 Subject: [PATCH] support google drive and dropbox links --- components/desirae/desirae.js | 64 ++++++++++++++++++++++++++++++++++- views/build/build.html | 2 +- views/build/build.js | 5 ++- views/post/post.html | 3 +- views/site/site.html | 28 +++++++-------- views/site/site.js | 59 +++++++++++++++++++++++++++++++- 6 files changed, 139 insertions(+), 22 deletions(-) diff --git a/components/desirae/desirae.js b/components/desirae/desirae.js index d1ff193..8f6e56f 100644 --- a/components/desirae/desirae.js +++ b/components/desirae/desirae.js @@ -8,6 +8,65 @@ angular.module('myApp.services', []). Desi.registerDataMapper('ruhoh', window.DesiraeDatamapRuhoh || require('desirae-datamap-ruhoh').DesiraeDatamapRuhoh); Desi.registerDataMapper('ruhoh@2.6', window.DesiraeDatamapRuhoh || require('desirae-datamap-ruhoh').DesiraeDatamapRuhoh); + function gdrive2host(str) { + // https://drive.google.com/folderview?id=0ByLnfhJOd1-baUh1Wms0US16QkE&usp=sharing + // https://googledrive.com/host/0ByLnfhJOd1-baUh1Wms0US16QkE + + var m + ; + + str = str || ''; + m = str.match(/(?=drive.*google|google.*drive).*folderview.*id=([^&]+)/i); + console.log(m); + if (m && m[1]) { + return 'https://googledrive.com/host/' + m[1]; + } + } + + function dropbox2host(str) { + if (!/dropbox/.test(str)) { + return; + } + // https://dl.dropboxusercontent.com/u/146173/index.html + + // https://www.dropbox.com/s/3n20djtrs2p0j9k + // https://www.dropbox.com/s/3n20djtrs2p0j9k/index.html?dl=0 + // https://dl.dropboxusercontent.com/s/3n20djtrs2p0j9k/index.html + + str = str || ''; + if (!str.match(/dropboxusercontent\.com\/u\/([^\/]+)\/index.html/)) { + window.alert("Sorry, Desi can't use that type of dropbox link." + + "\n\n1. Open the Dropbox folder on your computer" + + "\n (The DropBox app must be installed)" + + "\n\n2. Open the Public folder" + + "\n (if you don't have a Public folder, your account doesn't support hosting websites and you're simply out of luck)" + + "\n\n2. Create a new file called index.html" + + "\n\n3. Right-click on index.html" + + "\n\n4. Select 'Copy Public Link'" + + "\n\n5. Paste that link as the URL for Desi" + ); + return; + } + + return str.replace(/\/index\.html$/, ''); + } + + function splitUrl(str) { + var m + ; + + str = str || ''; + m = str.match(/(https?:\/\/)?([^\.\/?#]+\.[^\/?#]+)(\/[^#?]+)?/i); + console.log(m); + if (!m || !m[2]) { + return; + } + return { + baseUrl: (m[1] || 'http://') + m[2] + , basePath: (m[3] && m[3].replace(/\/$/, '')) || '/' + }; + } + function getBlogdir () { return $http.get('/api/fs/rootdir').then(function (resp) { desi.blogdir = resp.data; @@ -17,7 +76,10 @@ angular.module('myApp.services', []). getBlogdir(); return { - reset: function () { + splitUrl: splitUrl + , gdrive2host: gdrive2host + , dropbox2host: dropbox2host + , reset: function () { desi = {}; return getBlogdir(); } diff --git a/views/build/build.html b/views/build/build.html index ff53f6f..ff468cb 100644 --- a/views/build/build.html +++ b/views/build/build.html @@ -29,7 +29,7 @@
Production -

+

diff --git a/views/build/build.js b/views/build/build.js index 24403a3..aad9f70 100644 --- a/views/build/build.js +++ b/views/build/build.js @@ -28,7 +28,10 @@ angular.module('myApp.build', ['ngRoute']) return; } - scope.production_url = desi.site.base_url + path.join('/', desi.site.base_path); + scope.display_url = scope.production_url = desi.site.base_url + path.join('/', desi.site.base_path); + if (/dropbox/.test(scope.display_url)) { + scope.display_url += '/index.html'; + } // this is the responsibility of the build system (Dear Desi), not the library (Desirae) scope.development_url = location.href.replace(/\/(#.*)?$/, '') + path.join('/', 'compiled_dev'); diff --git a/views/post/post.html b/views/post/post.html index 5daf928..45ec67f 100644 --- a/views/post/post.html +++ b/views/post/post.html @@ -77,11 +77,10 @@
-