diff --git a/app.js b/app.js index c9cae7f..45969d8 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,7 @@ angular.module('myApp', [ 'myApp.site', 'myApp.build', 'myApp.configure', - 'myApp.create', + 'myApp.post', 'myApp.version', 'myApp.services' ]). diff --git a/index.html b/index.html index 464743f..5e10e7a 100644 --- a/index.html +++ b/index.html @@ -40,8 +40,8 @@ @@ -111,7 +111,7 @@ - + diff --git a/lib/deardesi-browser.js b/lib/deardesi-browser.js index 42935d0..b588b6d 100644 --- a/lib/deardesi-browser.js +++ b/lib/deardesi-browser.js @@ -368,7 +368,21 @@ }; fsapi.putFiles = function (files) { - var body = { files: files }; + var body = { files: files } + ; + + files.forEach(function (file) { + if (!file.contents || 'string' === typeof file.contents) { + return; + } + if (/\.json$/i.test(file.path)) { + file.contents = JSON.stringify(file.contents); + } + else if (/\.ya?ml$/i.test(file.path)) { + file.contents = exports.jsyaml.dump(file.contents); + } + }); + body = JSON.stringify(body); // this is more or less instant for a few MiB of posts return request.post('/api/fs/files', body).then(function (resp) { var response = JSON.parse(resp) diff --git a/views/create/create.js b/views/create/create.js deleted file mode 100644 index 22a97ea..0000000 --- a/views/create/create.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -angular.module('myApp.create', ['ngRoute']) - -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/create', { - templateUrl: 'views/create/create.html', - controller: 'CreateCtrl as Create' - }); -}]) - -.controller('CreateCtrl', [function() { - var Desi = window.Desi || require('./deardesi').Desi - , scope = this - , desi = {} - ; - - Desi.init(desi).then(function () { - scope.run = function () { - return Desi.runDesi(desi).then(function () { Desi.otherStuff(); }) - .catch(function (e) { - console.error('A great and uncatchable error has befallen the land. Read ye here for das detalles..'); - console.error(e.message); - console.error(e); - throw e; - }); - }; - }); -}]); diff --git a/views/post/post.html b/views/post/post.html new file mode 100644 index 0000000..271ad84 --- /dev/null +++ b/views/post/post.html @@ -0,0 +1,145 @@ +
+
+ +
+ +
+
+
+
+
+
+ +
+ +
+
+ +
+ +
+ + Put your lovely post here, in github-flavored markdown! +
+
+ +
+ +
+ +
+
+ + + + + + + + + +
+ +
+ + +
+
+ +
+
+ + +
+
+
+
+
diff --git a/views/post/post.js b/views/post/post.js new file mode 100644 index 0000000..992ad19 --- /dev/null +++ b/views/post/post.js @@ -0,0 +1,98 @@ +'use strict'; +angular.module('myApp.post', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/post', { + templateUrl: 'views/post/post.html', + controller: 'PostCtrl as Post' + }); +}]) + +.controller('PostCtrl' + , ['$scope', '$location', '$timeout', 'Desirae' + , function ($scope, $location, $timeout, Desirae) { + 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; + }).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); + throw e; + }); + } + + scope.selected = { + title: "" + , format: 'md' + , description: "" + , permalink: "/article/new.md" + , post: { + yml: { + title: "" + , description: "" + , uuid: window.uuid.v4() + , date: "YYYY-MM-DD HH:MM pm" // TODO desirae + , permalink: "/article/new.md" + , categories: [] + , tags: [] + , theme: null + , layout: null + , swatch: null + } + } + }; + scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml); + + scope.onChange = function () { + scope.selected.post.yml.title = scope.selected.title; + scope.selected.post.yml.description = scope.selected.description; + if (scope.selected.permalink === scope.selected.post.yml.permalink) { + scope.selected.permalink = '/articles/' + scope.selected.title.toLowerCase() + .replace(/["']/g, '') + .replace(/\W/g, '-') + + '.' + scope.selected.format + ; + scope.selected.post.yml.permalink = scope.selected.permalink; + } + scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml); + }; + scope.onFrontmatterChange = function () { + scope.selected.post.yml = window.jsyaml.load(scope.selected.post.frontmatter); + scope.selected.title = scope.selected.post.yml.title; + scope.selected.description = scope.selected.post.yml.description; + }; + + $timeout(function () { + if (scope.selected && scope.selected.date === scope.selected.post.yml.date) { + scope.selected.date = scope.selected.post.yml.date = new Date().toISOString(); + } + scope.onChange(); + }, 60 * 1000); + + scope.upsert = function () { + console.log(scope.selected.format) + var files = [] + ; + + files.push({ path: 'site.yml', contents: scope.site }); + + console.log(files); + Desirae.putFiles(files).then(function (results) { + console.log('TODO check for error'); + console.log(results); + $location.path('/post'); + }).catch(function (e) { + console.error(scope.site); + console.error(e); + window.alert("Error Nation! :/"); + throw e; + }); + }; + + init(); +}]); diff --git a/views/site/site.html b/views/site/site.html index 3de34f7..d70d199 100644 --- a/views/site/site.html +++ b/views/site/site.html @@ -19,6 +19,7 @@
@@ -39,7 +40,9 @@
-
@@ -69,6 +72,7 @@
Base Path
@@ -92,7 +97,7 @@
diff --git a/views/site/site.js b/views/site/site.js index 9ab98d8..e11e6a7 100644 --- a/views/site/site.js +++ b/views/site/site.js @@ -9,7 +9,7 @@ angular.module('myApp.site', ['ngRoute']) }); }]) -.controller('SiteCtrl', ['$scope', 'Desirae', function($scope, Desirae) { +.controller('SiteCtrl', ['$scope', '$location', 'Desirae', function ($scope, $location, Desirae) { var scope = this ; @@ -27,26 +27,18 @@ angular.module('myApp.site', ['ngRoute']) } scope.upsert = function () { - console.log('yolo!'); - return; - var author = scope.selectedAuthor - , files = [] - , filename = author.filename + var files = [] ; - delete author.filename; - if ('new' !== filename && filename !== author.handle) { - files.push({ path: 'authors/' + filename + '.yml', contents: '', delete: true }); - } - files.push({ path: 'authors/' + author.handle + '.yml', contents: window.jsyaml.dump(author) }); + files.push({ path: 'site.yml', contents: scope.site }); console.log(files); - Desirae.putFiles(files).then(function (results) { - console.log('updated author', results); + console.log('TODO check for error'); + console.log(results); $location.path('/post'); }).catch(function (e) { - author.filename = filename; + console.error(scope.site); console.error(e); window.alert("Error Nation! :/"); throw e;