can create post!
This commit is contained in:
parent
93e493acbb
commit
9c2e43a8c7
|
@ -54,7 +54,7 @@
|
||||||
<p>
|
<p>
|
||||||
<!-- http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html -->
|
<!-- http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html -->
|
||||||
<!-- also needs updating at http://plus.google.com/me/about/edit/co -->
|
<!-- also needs updating at http://plus.google.com/me/about/edit/co -->
|
||||||
<a href="mailto:develop@dear.deis" rel="me">develop@dear.desi</a>
|
<a href="mailto:develop@dear.desi" rel="me">develop@dear.desi</a>
|
||||||
|
|
|
|
||||||
<a href="https://twitter.com/dearbesiblog?rel=author" rel="me">Twitter</a>
|
<a href="https://twitter.com/dearbesiblog?rel=author" rel="me">Twitter</a>
|
||||||
<!--a href="https://www.facebook.com/coolaj86?rel=author" rel="me">Facebook</a-->
|
<!--a href="https://www.facebook.com/coolaj86?rel=author" rel="me">Facebook</a-->
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
<div class="well bs-component">
|
<div class="well bs-component">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="inputPostTitle" class="col-lg-2 control-label">Title</label>
|
<label for="inputPostTitle" class="col-lg-2 control-label">Title*</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<input
|
<input
|
||||||
required
|
required="required"
|
||||||
ng-model="Post.selected.title"
|
ng-model="Post.selected.post.yml.title"
|
||||||
ng-change="Post.onChange()"
|
ng-change="Post.onChange()"
|
||||||
type="text"
|
type="text"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
@ -39,9 +39,10 @@
|
||||||
</div>
|
</div>
|
||||||
-->
|
-->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="textAreaPost" class="col-lg-2 control-label">Post</label>
|
<label for="textAreaPost" class="col-lg-2 control-label">Post*</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<textarea
|
<textarea
|
||||||
|
required="required"
|
||||||
ng-model="Post.selected.post.body"
|
ng-model="Post.selected.post.body"
|
||||||
ng-change="Post.onChange()"
|
ng-change="Post.onChange()"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
@ -53,10 +54,48 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="select" class="col-lg-2 control-label">Format*</label>
|
||||||
|
<div class="col-lg-10">
|
||||||
|
<select
|
||||||
|
required="required"
|
||||||
|
ng-model="Post.selected.format"
|
||||||
|
ng-change="Post.onChange()"
|
||||||
|
class="form-control"
|
||||||
|
id="select">
|
||||||
|
<option value="html">HTML</option>
|
||||||
|
<option selected="selected" value="md">Markdown</option>
|
||||||
|
<option disabled="disabled" value="jade">Jade (Not Implemented)</option>
|
||||||
|
</select>
|
||||||
|
<!--div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox"> Draft
|
||||||
|
</label>
|
||||||
|
</div-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<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"
|
||||||
|
class="form-control"
|
||||||
|
rows="2"
|
||||||
|
id="textAreaDesc"></textarea>
|
||||||
|
<span class="help-block">The description is often used by search engines as the snippit shown in search results.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="textAreaYaml" class="col-lg-2 control-label">Frontmatter</label>
|
<label for="textAreaYaml" class="col-lg-2 control-label">Frontmatter</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<textarea
|
<textarea
|
||||||
|
required="required"
|
||||||
ng-change="Post.onFrontmatterChange()"
|
ng-change="Post.onFrontmatterChange()"
|
||||||
ng-model="Post.selected.post.frontmatter"
|
ng-model="Post.selected.post.frontmatter"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
@ -101,7 +140,7 @@
|
||||||
<label for="inputPostPermalink" class="col-lg-2 control-label">Permalink</label>
|
<label for="inputPostPermalink" class="col-lg-2 control-label">Permalink</label>
|
||||||
<div class="col-lg-10">
|
<div class="col-lg-10">
|
||||||
<input
|
<input
|
||||||
required
|
required="required"
|
||||||
type="text"
|
type="text"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="inputPostPermalink"
|
id="inputPostPermalink"
|
||||||
|
@ -111,26 +150,6 @@
|
||||||
</div>
|
</div>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="select" class="col-lg-2 control-label">Format</label>
|
|
||||||
<div class="col-lg-10">
|
|
||||||
<select
|
|
||||||
ng-model="Post.selected.format"
|
|
||||||
ng-change="Post.onChange()"
|
|
||||||
class="form-control"
|
|
||||||
id="select">
|
|
||||||
<option value="html">HTML</option>
|
|
||||||
<option selected="selected" value="md">Markdown</option>
|
|
||||||
<option disabled="disabled" value="jade">Jade (Not Implemented)</option>
|
|
||||||
</select>
|
|
||||||
<!--div class="checkbox">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox"> Draft
|
|
||||||
</label>
|
|
||||||
</div-->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-lg-10 col-lg-offset-2">
|
<div class="col-lg-10 col-lg-offset-2">
|
||||||
<!--button class="btn btn-default">Save Draft</button-->
|
<!--button class="btn btn-default">Save Draft</button-->
|
||||||
|
|
|
@ -19,6 +19,7 @@ angular.module('myApp.post', ['ngRoute'])
|
||||||
Desirae.meta().then(function (desi) {
|
Desirae.meta().then(function (desi) {
|
||||||
scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/');
|
scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/');
|
||||||
scope.site = desi.site;
|
scope.site = desi.site;
|
||||||
|
updateDate();
|
||||||
}).catch(function (e) {
|
}).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.");
|
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);
|
console.error(e);
|
||||||
|
@ -26,18 +27,19 @@ angular.module('myApp.post', ['ngRoute'])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope.extensions = ['md', 'html'];
|
||||||
|
|
||||||
scope.selected = {
|
scope.selected = {
|
||||||
title: ""
|
format: 'md'
|
||||||
, format: 'md'
|
|
||||||
, description: ""
|
|
||||||
, permalink: "/article/new.md"
|
, permalink: "/article/new.md"
|
||||||
|
, uuid: window.uuid.v4()
|
||||||
, post: {
|
, post: {
|
||||||
yml: {
|
yml: {
|
||||||
title: ""
|
title: ""
|
||||||
, description: ""
|
|
||||||
, uuid: window.uuid.v4()
|
|
||||||
, date: Desirae.toDesiDate(new Date())// "YYYY-MM-DD HH:MM pm" // TODO desirae
|
|
||||||
, permalink: "/article/new.md"
|
, permalink: "/article/new.md"
|
||||||
|
, date: Desirae.toDesiDate(new Date())// "YYYY-MM-DD HH:MM pm" // TODO desirae
|
||||||
|
, updated: null
|
||||||
|
, description: ""
|
||||||
, categories: []
|
, categories: []
|
||||||
, tags: []
|
, tags: []
|
||||||
, theme: null
|
, theme: null
|
||||||
|
@ -47,50 +49,105 @@ angular.module('myApp.post', ['ngRoute'])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
scope.selected.date = scope.selected.post.yml.date;
|
scope.selected.date = scope.selected.post.yml.date;
|
||||||
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml);
|
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml).trim();
|
||||||
|
|
||||||
scope.onChange = function () {
|
scope.onChange = function () {
|
||||||
scope.selected.post.yml.title = scope.selected.title;
|
var post = scope.selected.post
|
||||||
scope.selected.post.yml.description = scope.selected.description;
|
, selected = scope.selected
|
||||||
if (scope.selected.permalink === scope.selected.post.yml.permalink) {
|
;
|
||||||
scope.selected.permalink = '/articles/' + scope.selected.title.toLowerCase()
|
|
||||||
|
post.yml.title = post.yml.title || '';
|
||||||
|
post.yml.description = post.yml.description || '';
|
||||||
|
|
||||||
|
if (selected.permalink === post.yml.permalink) {
|
||||||
|
selected.permalink = '/articles/' + post.yml.title.toLowerCase()
|
||||||
.replace(/["']/g, '')
|
.replace(/["']/g, '')
|
||||||
.replace(/\W/g, '-')
|
.replace(/\W/g, '-')
|
||||||
.replace(/^-/g, '')
|
.replace(/^-+/g, '')
|
||||||
.replace(/-$/g, '')
|
.replace(/-+$/g, '')
|
||||||
.replace(/--/g, '-')
|
.replace(/--/g, '-')
|
||||||
+ '.' + scope.selected.format
|
+ '.' + selected.format
|
||||||
;
|
;
|
||||||
scope.selected.post.yml.permalink = scope.selected.permalink;
|
|
||||||
|
post.yml.permalink = selected.permalink;
|
||||||
}
|
}
|
||||||
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml);
|
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));
|
||||||
};
|
};
|
||||||
scope.onFrontmatterChange = function () {
|
scope.onFrontmatterChange = function () {
|
||||||
scope.selected.post.yml = window.jsyaml.load(scope.selected.post.frontmatter);
|
var data
|
||||||
scope.selected.title = scope.selected.post.yml.title;
|
;
|
||||||
scope.selected.description = scope.selected.post.yml.description;
|
|
||||||
|
try {
|
||||||
|
if (!scope.selected.post.frontmatter || !scope.selected.post.frontmatter.trim()) {
|
||||||
|
throw new Error('deleted frontmatter');
|
||||||
|
}
|
||||||
|
data = window.jsyaml.load(scope.selected.post.frontmatter);
|
||||||
|
scope.selected.format = data.permalink.replace(/.*\.(\w+$)/, '$1');
|
||||||
|
if (!data.permalink) {
|
||||||
|
data = scope.selected.permalink;
|
||||||
|
}
|
||||||
|
scope.selected.post.yml = data;
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
console.error('ignoring update that created parse error');
|
||||||
|
scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml).trim();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$timeout(function () {
|
function updateDate() {
|
||||||
if (scope.selected && scope.selected.date === scope.selected.post.yml.date) {
|
$timeout.cancel(scope.dtlock);
|
||||||
scope.selected.date = scope.selected.post.yml.date = Desirae.toDesiDate(new Date());
|
scope.dtlock = $timeout(function () {
|
||||||
}
|
if (scope.selected && scope.selected.date === scope.selected.post.yml.date) {
|
||||||
scope.onChange();
|
scope.selected.date = scope.selected.post.yml.date = Desirae.toDesiDate(new Date());
|
||||||
}, 60 * 1000);
|
}
|
||||||
|
scope.onChange();
|
||||||
|
updateDate();
|
||||||
|
}, 60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
scope.upsert = function () {
|
scope.upsert = function () {
|
||||||
console.log(scope.selected.format);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.selected.post.yml.uuid = scope.selected.uuid;
|
||||||
|
['updated', 'theme', 'layout', 'swatch'].forEach(function (key) {
|
||||||
|
if (!scope.selected.post.yml[key]) {
|
||||||
|
delete scope.selected.post.yml[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
scope.onChange();
|
||||||
|
|
||||||
var files = []
|
var files = []
|
||||||
;
|
;
|
||||||
|
|
||||||
files.push({ path: 'site.yml', contents: scope.site });
|
files.push({
|
||||||
|
path: scope.selected.path
|
||||||
|
, contents:
|
||||||
|
'---\n'
|
||||||
|
+ scope.selected.post.frontmatter.trim()
|
||||||
|
+ '\n'
|
||||||
|
+ '---\n'
|
||||||
|
+ '\n'
|
||||||
|
+ scope.selected.post.body.trim()
|
||||||
|
});
|
||||||
|
|
||||||
console.log(files);
|
console.log(files);
|
||||||
Desirae.putFiles(files).then(function (results) {
|
Desirae.putFiles(files).then(function (results) {
|
||||||
console.log('TODO check for error');
|
console.log('TODO check for error');
|
||||||
console.log(results);
|
console.log(results);
|
||||||
$location.path('/post');
|
$location.path('/build');
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
|
$timeout.cancel(scope.dtlock);
|
||||||
console.error(scope.site);
|
console.error(scope.site);
|
||||||
console.error(e);
|
console.error(e);
|
||||||
window.alert("Error Nation! :/");
|
window.alert("Error Nation! :/");
|
||||||
|
|
Loading…
Reference in New Issue