support google drive and dropbox links

This commit is contained in:
AJ ONeal 2015-01-21 13:31:07 -07:00
parent 43e6333377
commit 78aa491fee
6 changed files with 139 additions and 22 deletions

View File

@ -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();
}

View File

@ -29,7 +29,7 @@
<div class="well bs-component">
<fieldset>
<legend>Production</legend>
<p><a ng-href="{{Build.production_url}}" target="_blank"><span ng-bind="Build.production_url"></span></a></p>
<p><a ng-href="{{Build.display_url}}" target="_blank"><span ng-bind="Build.display_url"></span></a></p>
<div class="form-group">
<label for="inputProdCanonicalUrl" class="col-lg-2 control-label">Canonical URL</label>

View File

@ -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');

View File

@ -77,11 +77,10 @@
</div>
<div class="form-group">
<label for="textAreaDesc" class="col-lg-2 control-label">Description*
<label for="textAreaDesc" class="col-lg-2 control-label">Description
<small>(<span ng-bind="Post.selected.post.yml.description.length || 0"></span>/140)</small></label>
<div class="col-lg-10">
<textarea
required="required"
ng-change="Post.onChange()"
ng-model="Post.selected.post.yml.description"
placeholder="i.e. An alternate recipe for Peeta Mellarks's famous apple goat cheese tarts using only ingredients available in district 10"

View File

@ -69,27 +69,23 @@
-->
<div class="form-group">
<label for="inputProdHost" class="col-lg-3 control-label">Base URL</label>
<label for="inputProdUrl" class="col-lg-3 control-label">URL</label>
<div class="col-lg-9">
<input ng-model="Site.site.base_url"
<input
ng-model="Site.url"
ng-change="Site.onChange()"
required="required"
placeholder="i.e. https://example.com in https://example.com/myblog"
type="url"
placeholder="i.e. https://example.com/myblog"
type="text"
class="form-control"
id="inputProdHost">
<br/>
</div>
</div>
<div class="form-group">
<label for="inputProdBase" class="col-lg-3 control-label">Base Path</label>
<div class="col-lg-9">
<input ng-model="Site.site.base_path"
required="required"
placeholder="i.e. / for blog.test.com or /blog for test.com/blog"
type="text"
class="form-control"
id="inputProdBase">
<span class="help-block"
><span class="text-muted" ng-bind="Site.base_url"></span
><strong
><span ng-bind="Site.base_path"></span
><span ng-bind="Site.dropboxIndex"></span
></strong>
</div>
</div>

View File

@ -13,12 +13,22 @@ angular.module('myApp.site', ['ngRoute'])
var scope = this
;
function init() {
console.log('desi loading');
Desirae.meta().then(function (desi) {
scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/');
scope.site = desi.site;
var parts = Desirae.splitUrl(scope.site.base_url + (scope.site.base_path || '/'))
;
if (parts) {
scope.base_url = scope.site.base_url;
scope.base_path = scope.site.base_path;
scope.url = scope.base_url + scope.site.base_path;
}
scope.onChange();
}).catch(function (e) {
window.alert("An Error Occured. Most errors that occur in the init phase are parse errors in the config files or permissions errors on files or directories, but check the error console for details.");
console.error(e);
@ -26,10 +36,57 @@ angular.module('myApp.site', ['ngRoute'])
});
}
scope.onChange = function () {
console.log('new url [0]', scope.url);
var parts = Desirae.splitUrl(scope.url)
, url
;
if (!parts) {
scope.base_url = '';
scope.base_path = '';
return;
}
scope.base_url = parts.baseUrl;
scope.base_path = parts.basePath;
scope.dropboxIndex = '';
url = Desirae.gdrive2host(scope.url)
;
if (!url && Desirae.dropbox2host(scope.url)) {
url = Desirae.dropbox2host(scope.url);
scope.dropboxIndex = '/index.html';
}
console.log('new url [1]', url);
if (url) {
parts = Desirae.splitUrl(url);
scope.base_url = parts.baseUrl;
scope.base_path = parts.basePath;
}
//scope.url = scope.base_url + scope.base_path;
};
scope.upsert = function () {
var files = []
;
if (!scope.base_url || !scope.base_path) {
window.alert("URL: " + (scope.url) + "\nSomething about your URL doesn't look right.");
return;
}
// Just in case of http://blog.com/me/ + /blog vs http://blog.com + /me/blog
// don't change it unless it's truly different.
if ((scope.base_url + scope.base_path) !== (scope.site.base_url + scope.site.base_path)) {
scope.site.base_url = scope.base_url;
scope.site.base_path = scope.base_path;
}
files.push({ path: 'site.yml', contents: scope.site });
console.log(files);