From 9bb3079b61da0634fe77a3bb074695ea28f4c449 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 13 Jan 2015 04:55:16 -0700 Subject: [PATCH] fix redirect --- desirae | 2 +- views/build/build.js | 10 ++-------- views/post/post.js | 24 +++++++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/desirae b/desirae index f023315..574ab20 160000 --- a/desirae +++ b/desirae @@ -1 +1 @@ -Subproject commit f023315cfc91001e608b00892de5379e9b2c0eee +Subproject commit 574ab2045361ce2980f9f4b71e5fb12430a1fffb diff --git a/views/build/build.js b/views/build/build.js index 9533557..12ce5bb 100644 --- a/views/build/build.js +++ b/views/build/build.js @@ -17,20 +17,14 @@ angular.module('myApp.build', ['ngRoute']) ; function init() { - console.log('desi loading'); DesiraeService.meta().then(function (desi) { scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/'); scope.site = desi.site; - console.log(desi.site.base_url); - console.log(desi.site.base_path); scope.production_url = desi.site.base_url + path.join('/', desi.site.base_path); - console.log(scope.production_url); // this is the responsibility of the build system (Dear Desi), not the library (Desirae) scope.development_url = location.href.replace(/\/(#.*)?$/, '') + path.join('/', 'compiled_dev'); - console.log(scope.development_url); - }).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); @@ -58,7 +52,7 @@ angular.module('myApp.build', ['ngRoute']) if ('production' === envstr) { env = { url: scope.production_url - , base_url: scope.development_url.replace(/(https?:\/\/[^\/#?]+)/, '$1') + , base_url: scope.development_url.replace(/(https?:\/\/[^\/#?]+).*/, '$1') , compiled_path: 'compiled' , since: 0 , onError: scope.onError @@ -66,7 +60,7 @@ angular.module('myApp.build', ['ngRoute']) } else { env = { url: scope.development_url - , base_url: scope.development_url.replace(/(https?:\/\/[^\/#?]+)/, '$1') + , base_url: scope.development_url.replace(/(https?:\/\/[^\/#?]+).*/, '$1') , base_path: scope.development_url.replace(/https?:\/\/[^\/#?]+/, '') , compiled_path: 'compiled_dev' , since: 0 diff --git a/views/post/post.js b/views/post/post.js index e3f40fe..b200168 100644 --- a/views/post/post.js +++ b/views/post/post.js @@ -15,7 +15,6 @@ angular.module('myApp.post', ['ngRoute']) ; function init() { - console.log('desi loading'); Desirae.meta().then(function (desi) { scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/'); scope.site = desi.site; @@ -34,13 +33,13 @@ angular.module('myApp.post', ['ngRoute']) function newPost() { scope.selected = { format: 'md' - , permalink: "/article/new.md" + , permalink: "/article/new.html" , uuid: window.uuid.v4() , abspath: scope.blogdir , post: { yml: { title: "" - , permalink: "/article/new.md" + , permalink: "/article/new.html" , date: Desirae.toDesiDate(new Date())// "YYYY-MM-DD HH:MM pm" // TODO desirae , updated: null , description: "" @@ -71,23 +70,29 @@ angular.module('myApp.post', ['ngRoute']) .replace(/^-+/g, '') .replace(/-+$/g, '') .replace(/--/g, '-') - + '.' + selected.format + + '/' // + '.html' //+ selected.format ; post.yml.permalink = selected.permalink; } + /* if (window.path.extname(post.yml.permalink) !== '.' + selected.format) { post.yml.permalink = post.yml.permalink.replace(/\.\w+$/, '.' + selected.format); } + */ post.frontmatter = window.jsyaml.dump(post.yml).trim(); // TODO use some sort of filepath pattern in config.yml selected.path = window.path.join((selected.collection || 'posts'), window.path.basename(post.yml.permalink)); + if (!/\.html?$/.test(selected.path)) { + selected.path = window.path.join(selected.path, 'index.html'); + } selected.abspath = window.path.join(scope.blogdir, selected.path); }; scope.onFrontmatterChange = function () { var data + , post ; try { @@ -95,11 +100,17 @@ angular.module('myApp.post', ['ngRoute']) throw new Error('deleted frontmatter'); } data = window.jsyaml.load(scope.selected.post.frontmatter); - scope.selected.format = data.permalink.replace(/.*\.(\w+$)/, '$1'); + //scope.selected.format = data.permalink.replace(/.*\.(\w+$)/, '$1'); if (!data.permalink) { data = scope.selected.permalink; } scope.selected.post.yml = data; + + post = scope.selected.post; + scope.selected.path = window.path.join((scope.selected.collection || 'posts'), window.path.basename(post.yml.permalink)); + if (!/\.html?$/.test(scope.selected.path)) { + scope.selected.path = window.path.join(scope.selected.path, 'index.html'); + } } catch(e) { console.error(e); console.error('ignoring update that created parse error'); @@ -119,7 +130,6 @@ angular.module('myApp.post', ['ngRoute']) } scope.upsert = function () { - console.log('upserted'); if (-1 === scope.extensions.indexOf(scope.selected.format)) { window.alert('.' + scope.selected.format + ' is not a supported extension.\n\nPlease choose from: .' + scope.extensions.join(' .')); return; @@ -147,9 +157,9 @@ angular.module('myApp.post', ['ngRoute']) + scope.selected.post.body.trim() }); - console.log(files); Desirae.putFiles(files).then(function (results) { console.log('TODO check for error'); + console.log(files); console.log(results); $location.path('/build'); }).catch(function (e) {