diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/README.md b/README.md index e4fa2aa..b3eb97d 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,20 @@ Not a Web Developer? You're in the wrong place. **Go to ** and follow the instructions there. --> -Did you mean to come here? -========================== +# Did you mean to come here? -If you're a normal person interested in *Desi, the DIY blog platform for normal people*, +If you're a normal person interested in _Desi, the DIY blog platform for normal people_, you might have meant to go to [DearDesi](http://dear.desi) instead. Otherwise, if you're a cyborg, wizzard, or web developer: carry on. -Dear Desi -========= +# Dear Desi These instructions cover the command line only. If you want instructions for the web interface, head over to [DearDesi](http://dear.desi). -Command Line Install (for developers) --------------------- +## Command Line Install (for developers) This assumes that you already have `git` and `node` installed, otherwise see [node-installer.sh](https://git.coolaj86.com/coolaj86/node-installer.sh) @@ -36,22 +33,20 @@ npm install -g desi That was easy -Quick Usage -------- +## Quick Usage -* desi init -d ~/Desktop/new-blog -* pushd ~/Desktop/new-blog -* desi post "my first post" -* desi build -* desi serve +- desi init -d ~/Desktop/new-blog +- pushd ~/Desktop/new-blog +- desi post "my first post" +- desi build +- desi serve **Note**: both through command line and web you need `site.yml` and `authors/xyz.yml` configured in order to create a post (as well as build). The post commands output the location of post in various formats. -Initialize your blog (step 1) --------- +## Initialize your blog (step 1) You can do this 3 ways: @@ -98,34 +93,37 @@ Obviously this is a little different for everyone, so here's what I'd recommend: 1. start by following the Automated procedure above 2. copy over your posts/articles folder(s) 3. edit `config.yml` to add a config with a permalink with your collections (posts, articles, essays, whatever you call them) -4. skip ahead to the *Setup your blog* section and make sure your `site.yml` and `authors/xxx.yml` are correct. +4. skip ahead to the _Setup your blog_ section and make sure your `site.yml` and `authors/xxx.yml` are correct. 5. run `desi build -d /path/to/blog` to test if there are any issues with your existing yaml - * if there are, you can take a look at the [normalize](https://github.com/DearDesi/desirae/blob/master/lib/transform-core.js#L72) function and perhaps hand-edit a few things (and when you're ready, you can [register your transform](https://github.com/DearDesi/deardesi/blob/master/bin/deardesi.js#L28) for collections. + +- if there are, you can take a look at the [normalize](https://github.com/DearDesi/desirae/blob/master/lib/transform-core.js#L72) function and perhaps hand-edit a few things (and when you're ready, you can [register your transform](https://github.com/DearDesi/deardesi/blob/master/bin/deardesi.js#L28) for collections. + 6. Now copy over your theme and set it to be the default in `site.yml` 7. build again. Your site probably won't look right: - * look for stuff like `urls.base_url`, `host`, `page.url` that might have an extra `/` at the beginning or end or be named slightly differently. + +- look for stuff like `urls.base_url`, `host`, `page.url` that might have an extra `/` at the beginning or end or be named slightly differently. See for disambiguation about the meaning of terms in Desi. -Setup your blog (step 2) ------------- +## Setup your blog (step 2) 1. Create an authors file in `authors/YOUR_NAME.yml` and model it after [this example](https://github.com/DearDesi/deardesi/blob/master/example/authors/johndoe.yml) - * You don't need to use all of the fields (your template might not even support them all) + +- You don't need to use all of the fields (your template might not even support them all) + 2. Create a site file as `site.yml`, similar to [this example](https://github.com/DearDesi/deardesi/blob/master/example/site.yml) **Important Things** - * `site.yml.base_url` - the point of ownership (usually blog.example.com or example.com) - * `site.yml.base_path` - where the blog is "mounted", relative to the `base_url` (usually `/` or `/blog`) - * `authors/me.yml.name` - most templates use this - * `authors/me.yml.email` - and this - * `authors/me.yml.twitter` - and this +- `site.yml.base_url` - the point of ownership (usually blog.example.com or example.com) +- `site.yml.base_path` - where the blog is "mounted", relative to the `base_url` (usually `/` or `/blog`) +- `authors/me.yml.name` - most templates use this +- `authors/me.yml.email` - and this +- `authors/me.yml.twitter` - and this -Build your blog (step 2) ------------- +## Build your blog (step 2) -The build *will* fail if you don't have `site.yml` and `authors/johndoe.yml` configured. +The build _will_ fail if you don't have `site.yml` and `authors/johndoe.yml` configured. ```bash desi build -d /path/to/blog diff --git a/app.js b/app.js index 45969d8..fd13dc1 100644 --- a/app.js +++ b/app.js @@ -1,17 +1,21 @@ -'use strict'; +"use strict"; // Declare app level module which depends on views, and components -angular.module('myApp', [ - 'ngRoute', - 'myApp.about', - 'myApp.authors', - 'myApp.site', - 'myApp.build', - 'myApp.configure', - 'myApp.post', - 'myApp.version', - 'myApp.services' -]). -config(['$routeProvider', function ($routeProvider) { - $routeProvider.otherwise({redirectTo: '/about'}); -}]); +angular + .module("myApp", [ + "ngRoute", + "myApp.about", + "myApp.authors", + "myApp.site", + "myApp.build", + "myApp.configure", + "myApp.post", + "myApp.version", + "myApp.services", + ]) + .config([ + "$routeProvider", + function ($routeProvider) { + $routeProvider.otherwise({ redirectTo: "/about" }); + }, + ]); diff --git a/bin/deardesi.js b/bin/deardesi.js index b38a940..0998c0f 100755 --- a/bin/deardesi.js +++ b/bin/deardesi.js @@ -1,157 +1,183 @@ #!/usr/bin/env node -'use strict'; +"use strict"; -var PromiseA = require('bluebird') - , fs = PromiseA.promisifyAll(require('fs')) - , fsx = PromiseA.promisifyAll(require('fs.extra')) - , tar = require('tar') +var PromiseA = require("bluebird"), + fs = PromiseA.promisifyAll(require("fs")), + fsx = PromiseA.promisifyAll(require("fs.extra")), + tar = require("tar"), //, requestAsync = PromiseA.promisify(require('request')) - , request = PromiseA.promisifyAll(require('request')) - , forEachAsync = require('foreachasync').forEachAsync + request = PromiseA.promisifyAll(require("request")), + forEachAsync = require("foreachasync").forEachAsync, //, spawn = require('child_process').spawn - , path = require('path') - , cli = require('cli') - , UUID = require('node-uuid') - , Desi - , zlib = require('zlib') - ; - + path = require("path"), + cli = require("cli"), + UUID = require("node-uuid"), + Desi, + zlib = require("zlib"); cli.parse({ - blogdir: ['d', 'Where your blog is, i.e. ~/path/to/blog', 'string', './'] -//, output: ['o', 'name of output directory within ~/path/to/blog', 'string', './compiled'] + blogdir: ["d", "Where your blog is, i.e. ~/path/to/blog", "string", "./"], + //, output: ['o', 'name of output directory within ~/path/to/blog', 'string', './compiled'] }); function init() { - Desi = require('desirae').Desirae; + Desi = require("desirae").Desirae; // // 1. Transform (yml, slug, etc) // Desi.registerTransform( - 'lint' - , require('desirae/lib/transform-core').DesiraeTransformCore.lint - , { collections: true } + "lint", + require("desirae/lib/transform-core").DesiraeTransformCore.lint, + { collections: true } ); Desi.registerTransform( - 'root' - , require('desirae/lib/transform-core').DesiraeTransformCore.root - , { root: true } + "root", + require("desirae/lib/transform-core").DesiraeTransformCore.root, + { root: true } ); Desi.registerTransform( - 'normalize' - , require('desirae/lib/transform-core').DesiraeTransformCore.normalize - , { root: true, collections: true } + "normalize", + require("desirae/lib/transform-core").DesiraeTransformCore.normalize, + { root: true, collections: true } ); Desi.registerTransform( - 'disqus' - , require('desirae/lib/transform-core').DesiraeTransformCore.disqus - , { collections: true } + "disqus", + require("desirae/lib/transform-core").DesiraeTransformCore.disqus, + { collections: true } ); // // 2. Aggregate (rss, categories, tags, etc) // - Desi.registerAggregator(require('desirae/lib/aggregate-core').DesiraeAggregateCore.collate); + Desi.registerAggregator( + require("desirae/lib/aggregate-core").DesiraeAggregateCore.collate + ); // // 3. Datamap (ruhoh, desirae, jade, mustache, liquid) // - Desi.registerDataMapper('desirae', require('desirae/lib/datamap-core').DesiraeDatamapCore); - Desi.registerDataMapper('desirae@1.0', require('desirae/lib/datamap-core').DesiraeDatamapCore); + Desi.registerDataMapper( + "desirae", + require("desirae/lib/datamap-core").DesiraeDatamapCore + ); + Desi.registerDataMapper( + "desirae@1.0", + require("desirae/lib/datamap-core").DesiraeDatamapCore + ); // TODO ruhoh versions are ruhoh-twitter (1.0) and ruhoh-boostrap-2 (2.6) - Desi.registerDataMapper('ruhoh', require('desirae-datamap-ruhoh').DesiraeDatamapRuhoh); - Desi.registerDataMapper('ruhoh@1.0', require('desirae-datamap-ruhoh').DesiraeDatamapRuhoh); - Desi.registerDataMapper('ruhoh@2.6', require('desirae-datamap-ruhoh').DesiraeDatamapRuhoh); + Desi.registerDataMapper( + "ruhoh", + require("desirae-datamap-ruhoh").DesiraeDatamapRuhoh + ); + Desi.registerDataMapper( + "ruhoh@1.0", + require("desirae-datamap-ruhoh").DesiraeDatamapRuhoh + ); + Desi.registerDataMapper( + "ruhoh@2.6", + require("desirae-datamap-ruhoh").DesiraeDatamapRuhoh + ); // // 4. Render (md -> html, less -> css, etc) // Desi.registerRenderer( - 'js' - , require('desirae/lib/render-core').DesiraeRenderJs - , { themes: true, assets: true } + "js", + require("desirae/lib/render-core").DesiraeRenderJs, + { themes: true, assets: true } ); Desi.registerRenderer( - 'css' - , require('desirae/lib/render-core').DesiraeRenderCss - , { themes: true, assets: true } + "css", + require("desirae/lib/render-core").DesiraeRenderCss, + { themes: true, assets: true } ); - ['html', 'htm', 'xhtm', 'xhtml'].forEach(function (ext) { + ["html", "htm", "xhtm", "xhtml"].forEach(function (ext) { Desi.registerRenderer( - ext - , require('desirae/lib/render-core').DesiraeRenderHtml - , { root: true, collections: true, themes: true, assets: true } + ext, + require("desirae/lib/render-core").DesiraeRenderHtml, + { root: true, collections: true, themes: true, assets: true } ); }); - ['md', 'markdown', 'mdown', 'mkdn', 'mkd', 'mdwn', 'mdtxt', 'mdtext'].forEach(function (ext) { - Desi.registerRenderer( - ext - , require('desirae/lib/render-core').DesiraeRenderMarkdown - , { root: true, collections: true } - ); - }); + ["md", "markdown", "mdown", "mkdn", "mkd", "mdwn", "mdtxt", "mdtext"].forEach( + function (ext) { + Desi.registerRenderer( + ext, + require("desirae/lib/render-core").DesiraeRenderMarkdown, + { root: true, collections: true } + ); + } + ); Desi.registerRenderer( - 'jade' - , require('desirae/lib/render-core').DesiraeRenderJade - // TODO how to support jade in place of Mustache for layouts? - , { root: true, collections: true, themes: true } + "jade", + require("desirae/lib/render-core").DesiraeRenderJade, + // TODO how to support jade in place of Mustache for layouts? + { root: true, collections: true, themes: true } ); } function serve(displayDir, blogdir) { - var http = require('http') + var http = require("http"), //, https = require('https') - , app = require('../server').create({ blogdir: blogdir }) - , server - ; + app = require("../server").create({ blogdir: blogdir }), + server; - server = http.createServer(app).listen(65080, function () { - console.info("Listening from " + displayDir); - console.info("Listening on http://local.dear.desi:" + server.address().port); - }).on('error', function (err) { - if (/EADDRINUSE/.test(err.message)) { - console.error(""); - console.error("You're already running desi in another tab."); - console.error(""); - console.error("Go to the other tab and press + c to stop her. Then you can come back here to try again."); - console.error(""); - console.error(""); - return; - } + server = http + .createServer(app) + .listen(65080, function () { + console.info("Listening from " + displayDir); + console.info( + "Listening on http://local.dear.desi:" + server.address().port + ); + }) + .on("error", function (err) { + if (/EADDRINUSE/.test(err.message)) { + console.error(""); + console.error("You're already running desi in another tab."); + console.error(""); + console.error( + "Go to the other tab and press + c to stop her. Then you can come back here to try again." + ); + console.error(""); + console.error(""); + return; + } - throw err; - }); + throw err; + }); //secureServer = https.createServer(app).listen(65043); } function build(blogdir) { - var desi = {} - , env = {} - ; - + var desi = {}, + env = {}; env.working_path = env.blogdir = blogdir; Desi.init(desi, env).then(function () { - env.url = desi.site.base_url + desi.site.base_path.replace(/^\/$/, ''); + env.url = desi.site.base_url + desi.site.base_path.replace(/^\/$/, ""); env.base_url = desi.site.base_url; env.base_path = desi.site.base_path; - env.compiled_path = 'compiled'; + env.compiled_path = "compiled"; //env.since = 0; Desi.buildAll(desi, env).then(function () { Desi.write(desi, env).then(function (info) { console.info( - 'wrote', info.numFiles - , 'files' - , '(' + (info.size && (info.size / (1024 * 1024)).toFixed(2) || 'unkown'), 'MiB)' - , 'in' - , ((info.end - info.start) / 1000).toFixed(3) + 's' + "wrote", + info.numFiles, + "files", + "(" + + ((info.size && (info.size / (1024 * 1024)).toFixed(2)) || "unkown"), + "MiB)", + "in", + ((info.end - info.start) / 1000).toFixed(3) + "s" ); - console.info('Built and saved to ' + path.join(env.working_path, env.compiled_path)); + console.info( + "Built and saved to " + path.join(env.working_path, env.compiled_path) + ); }); }); }); @@ -159,34 +185,33 @@ function build(blogdir) { function createPost(originalDir, blogdir, title, extra) { if (!title) { - console.error("Usage desi post \"My First Post\""); + console.error('Usage desi post "My First Post"'); console.error("(you didn't specify a title)"); process.exit(1); } if (extra) { - console.error("Usage desi post \"My First Post\""); - console.error("(too many arguments - maybe you didn't put your title in quotes?)"); + console.error('Usage desi post "My First Post"'); + console.error( + "(too many arguments - maybe you didn't put your title in quotes?)" + ); process.exit(1); } - var desi = {} - , env = {} - , post = {} - , slug - , filepath - , displaypath - ; + var desi = {}, + env = {}, + post = {}, + slug, + filepath, + displaypath; env.working_path = env.blogdir = blogdir; Desi.init(desi, env).then(function () { // TODO move this 'create new post' logic to desirae proper - var collectionname = Object.keys(desi.config.collections)[0] - , collection = desi.config.collections[collectionname] - , entity = {} - ; - - /* + var collectionname = Object.keys(desi.config.collections)[0], + collection = desi.config.collections[collectionname], + entity = {}; + /* Desi.init(desi, env).then(function () { env.url = desi.site.base_url + desi.site.base_path.replace(/^\/$/, ''); env.base_url = desi.site.base_url; @@ -201,75 +226,92 @@ function createPost(originalDir, blogdir, title, extra) { // TODO use site.permalink or collection.permalink or something like that slug = Desi.slugify(post.title); - + // TODO as per config post.uuid = UUID.v4(); // TODO as per config for default collection and default format (jade, md, etc) - filepath = path.join(blogdir, collectionname, slug + '.md'); - displaypath = path.join(originalDir, 'posts', slug + '.md').replace(/^\/(Users|home)\/[^\/]+\//, '~/').replace(/ /g, '\\ '); + filepath = path.join(blogdir, collectionname, slug + ".md"); + displaypath = path + .join(originalDir, "posts", slug + ".md") + .replace(/^\/(Users|home)\/[^\/]+\//, "~/") + .replace(/ /g, "\\ "); - ['updated', 'theme', 'layout', 'swatch'].forEach(function (key) { + ["updated", "theme", "layout", "swatch"].forEach(function (key) { if (!post[key]) { delete post[key]; } }); - Object.keys(post).forEach(function (key) { entity[key] = post[key]; }); entity.slug = slug; post.permalink = Desi.permalinkify( - desi - , collection.fallback_permalink || collection.permalink - , entity); - return Desi.fsapi.putFiles([{ - path: filepath - , contents: - '---\n' - + Desi.YAML.stringify(post).trim() - + '\n' - + '---\n' - + '\n' - + '\n' - }], { overwrite: false }).then(function (r) { - var err - ; + desi, + collection.fallback_permalink || collection.permalink, + entity + ); + return Desi.fsapi + .putFiles( + [ + { + path: filepath, + contents: + "---\n" + + Desi.YAML.stringify(post).trim() + + "\n" + + "---\n" + + "\n" + + "\n", + }, + ], + { overwrite: false } + ) + .then(function (r) { + var err; - if (r.error || r.errors.length) { - err = r.error || r.errors[0]; - if (/exists/i.test(err.message)) { - console.error(''); - console.error("Looks like that post already exists. Try a different name?"); - console.error(''); - console.error(''); - } else { - throw err; + if (r.error || r.errors.length) { + err = r.error || r.errors[0]; + if (/exists/i.test(err.message)) { + console.error(""); + console.error( + "Looks like that post already exists. Try a different name?" + ); + console.error(""); + console.error(""); + } else { + throw err; + } } - } - console.log(''); - console.log(displaypath); - console.log(''); - console.log('Markdown: [' + post.title + '](' - + desi.site.base_url - + path.join(desi.site.base_path, post.permalink) - + ')' - ); - console.log('HTML: ' + post.title + '' - ); - console.log(''); - console.log(''); - console.log('vim ' + displaypath); - console.log('(or emacs ' + displaypath + ', if you swing that way)'); - console.log(''); - console.log(''); - }); - /* + console.log(""); + console.log(displaypath); + console.log(""); + console.log( + "Markdown: [" + + post.title + + "](" + + desi.site.base_url + + path.join(desi.site.base_path, post.permalink) + + ")" + ); + console.log( + 'HTML: ' + + post.title + + "" + ); + console.log(""); + console.log(""); + console.log("vim " + displaypath); + console.log("(or emacs " + displaypath + ", if you swing that way)"); + console.log(""); + console.log(""); + }); + /* }); */ }); @@ -278,120 +320,132 @@ function createPost(originalDir, blogdir, title, extra) { function initialize(displayPath, blogdir) { console.info("\nCreating new blog", displayPath); - return fs.readdirAsync(blogdir).then(function (nodes) { - // ignore dotfiles (.DS_Store, etc) - nodes = nodes.filter(function (node) { - return !/^\./.test(node); - }); + return fs + .readdirAsync(blogdir) + .then(function (nodes) { + // ignore dotfiles (.DS_Store, etc) + nodes = nodes.filter(function (node) { + return !/^\./.test(node); + }); - if (nodes.length) { - console.error("\n\tOops! It looks like that directory is already being used"); - console.error("\nIf you want you can DELETE it and start from scratch:"); - console.error("\n\trm -r '" + blogdir.replace("'", "'\"'\"'") + "'"); - console.error("\nOr you can specify a different directory."); - console.error("\n"); - process.exit(1); - } - }).catch(function (/*err*/) { - // doesn't exist? No problamo (all the better, actually) - return; - }).then(function () { - return fsx.mkdirp(blogdir); - }).then(function () { - return new PromiseA(function (resolve, reject) { - var t = tar.Extract({ path: blogdir, strip: 1 }) - , gunzip = zlib.createGunzip() - ; - - console.info("Downloading blog template...", displayPath); - request.get("https://github.com/DearDesi/desirae-blog-template/archive/v1.1.0.tar.gz") - .pipe(gunzip) - .pipe(t) - .on('end', resolve) - .on('error', reject) - ; - }); - }).then(function () { - var themes - ; - - themes = [ - { name: 'ruhoh-twitter' - , url: "https://github.com/DearDesi/ruhoh-twitter/archive/v1.0.0.tar.gz" + if (nodes.length) { + console.error( + "\n\tOops! It looks like that directory is already being used" + ); + console.error( + "\nIf you want you can DELETE it and start from scratch:" + ); + console.error("\n\trm -r '" + blogdir.replace("'", "'\"'\"'") + "'"); + console.error("\nOr you can specify a different directory."); + console.error("\n"); + process.exit(1); } - , { name: 'ruhoh-bootstrap-2' - , url: "https://github.com/DearDesi/ruhoh-bootstrap-2/archive/v1.0.1.tar.gz" - } - ]; - - return forEachAsync(themes, function (theme) { + }) + .catch(function (/*err*/) { + // doesn't exist? No problamo (all the better, actually) + return; + }) + .then(function () { + return fsx.mkdirp(blogdir); + }) + .then(function () { return new PromiseA(function (resolve, reject) { - var t = tar.Extract({ path: path.join(blogdir, 'themes', theme.name), strip: 1 }) - , gunzip = zlib.createGunzip() - ; - - console.info("Downloading theme '" + theme.name + "'"); - request.get(theme.url) + var t = tar.Extract({ path: blogdir, strip: 1 }), + gunzip = zlib.createGunzip(); + console.info("Downloading blog template...", displayPath); + request + .get( + "https://github.com/DearDesi/desirae-blog-template/archive/v1.1.0.tar.gz" + ) .pipe(gunzip) .pipe(t) - .on('end', resolve) - .on('error', reject) - ; + .on("end", resolve) + .on("error", reject); }); - }); - }).then(function () { - console.info("Done."); - console.info("\nTo start the web editor run this:"); - console.info("\n\tdesi serve -d '" + blogdir.replace("'", "'\"'\"'") + "'"); - }) - ; -} + }) + .then(function () { + var themes; + themes = [ + { + name: "ruhoh-twitter", + url: + "https://github.com/DearDesi/ruhoh-twitter/archive/v1.0.0.tar.gz", + }, + { + name: "ruhoh-bootstrap-2", + url: + "https://github.com/DearDesi/ruhoh-bootstrap-2/archive/v1.0.1.tar.gz", + }, + ]; + + return forEachAsync(themes, function (theme) { + return new PromiseA(function (resolve, reject) { + var t = tar.Extract({ + path: path.join(blogdir, "themes", theme.name), + strip: 1, + }), + gunzip = zlib.createGunzip(); + console.info("Downloading theme '" + theme.name + "'"); + request + .get(theme.url) + .pipe(gunzip) + .pipe(t) + .on("end", resolve) + .on("error", reject); + }); + }); + }) + .then(function () { + console.info("Done."); + console.info("\nTo start the web editor run this:"); + console.info( + "\n\tdesi serve -d '" + blogdir.replace("'", "'\"'\"'") + "'" + ); + }); +} cli.main(function (args, options) { init(); - var command = args[0] - , blogdir = options.blogdir - , originalDir = blogdir - , displayPath - ; - + var command = args[0], + blogdir = options.blogdir, + originalDir = blogdir, + displayPath; + if (!blogdir) { - blogdir = path.resolve('./'); - originalDir = './'; + blogdir = path.resolve("./"); + originalDir = "./"; } - displayPath = path.resolve(originalDir) - .replace(/^\/(Users|home)\/[^\/]+\//, '~/') - .replace(/ /g, '\\ ') - ; + displayPath = path + .resolve(originalDir) + .replace(/^\/(Users|home)\/[^\/]+\//, "~/") + .replace(/ /g, "\\ "); - if ('init' === command) { + if ("init" === command) { initialize(displayPath, blogdir); return; } - if (!fs.existsSync(path.join(blogdir, 'site.yml'))) { + if (!fs.existsSync(path.join(blogdir, "site.yml"))) { console.error("Usage: desi [serve|init|post] -d ~/path/to/blog"); - console.error("(if ~/path/to/blog doesn't yet exist or doesn't have config.yml, site.yml, etc, " - + "try `deardesi init -d ~/path/to/blog'"); + console.error( + "(if ~/path/to/blog doesn't yet exist or doesn't have config.yml, site.yml, etc, " + + "try `deardesi init -d ~/path/to/blog'" + ); process.exit(1); return; - } - else if ('build' === command) { + } else if ("build" === command) { build(blogdir); return; - } - else if ('post' === command) { + } else if ("post" === command) { createPost(originalDir, blogdir, args[1], args[2]); return; - } - else if ('serve' === command) { + } else if ("serve" === command) { serve(displayPath, blogdir); return; - } - else { + } else { console.error("Usage: desi [serve|init|post] -d ~/path/to/blog"); return; } diff --git a/bower.json b/bower.json index d966749..cc89248 100644 --- a/bower.json +++ b/bower.json @@ -1,15 +1,10 @@ { "name": "deardesi", "version": "0.8.5", - "authors": [ - "AJ ONeal " - ], + "authors": ["AJ ONeal "], "description": "A blogging platform in the browser. Wow!", "main": "deardesi.js", - "moduleType": [ - "globals", - "node" - ], + "moduleType": ["globals", "node"], "keywords": [ "dear", "desi", @@ -21,13 +16,7 @@ ], "license": "Apache2", "homepage": "http://github.com/DearDesi/deardesi", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], + "ignore": ["**/.*", "node_modules", "bower_components", "test", "tests"], "dependencies": { "escape-string-regexp": "~1.0.2", "path": "~3.46.1", diff --git a/components/desirae/desirae.js b/components/desirae/desirae.js index a75164c..5252e11 100644 --- a/components/desirae/desirae.js +++ b/components/desirae/desirae.js @@ -1,32 +1,27 @@ -angular.module('myApp.services', []). - factory('Desirae', ['$q', '$http', function ($q, $http) { - var Desi = window.Desirae || require('./deardesi').Desirae - , desi = {/*TODO api_base: '/api'*/} - ; - +angular.module("myApp.services", []).factory("Desirae", [ + "$q", + "$http", + function ($q, $http) { + var Desi = window.Desirae || require("./deardesi").Desirae, + desi = { + /*TODO api_base: '/api'*/ + }; // // 1. Transform (yml, slug, etc) // - Desi.registerTransform( - 'lint' - , window.DesiraeTransformCore.lint - , { collections: true } - ); - Desi.registerTransform( - 'root' - , window.DesiraeTransformCore.root - , { root: true } - ); - Desi.registerTransform( - 'normalize' - , window.DesiraeTransformCore.normalize - , { root: true, collections: true } - ); - Desi.registerTransform( - 'disqus' - , window.DesiraeTransformCore.disqus - , { collections: true } - ); + Desi.registerTransform("lint", window.DesiraeTransformCore.lint, { + collections: true, + }); + Desi.registerTransform("root", window.DesiraeTransformCore.root, { + root: true, + }); + Desi.registerTransform("normalize", window.DesiraeTransformCore.normalize, { + root: true, + collections: true, + }); + Desi.registerTransform("disqus", window.DesiraeTransformCore.disqus, { + collections: true, + }); // // 2. Aggregate (rss, categories, tags, etc) @@ -36,60 +31,66 @@ angular.module('myApp.services', []). // // 3. Datamap (ruhoh, desirae, jade, mustache, liquid) // - Desi.registerDataMapper('desirae', window.DesiraeDatamapCore); - Desi.registerDataMapper('desirae@1.0', window.DesiraeDatamapCore); - Desi.registerDataMapper('ruhoh', window.DesiraeDatamapRuhoh); - Desi.registerDataMapper('ruhoh@1.0', window.DesiraeDatamapRuhoh); - Desi.registerDataMapper('ruhoh@2.6', window.DesiraeDatamapRuhoh); + Desi.registerDataMapper("desirae", window.DesiraeDatamapCore); + Desi.registerDataMapper("desirae@1.0", window.DesiraeDatamapCore); + Desi.registerDataMapper("ruhoh", window.DesiraeDatamapRuhoh); + Desi.registerDataMapper("ruhoh@1.0", window.DesiraeDatamapRuhoh); + Desi.registerDataMapper("ruhoh@2.6", window.DesiraeDatamapRuhoh); // // 4. Render (md -> html, less -> css, etc) // - Desi.registerRenderer( - 'js' - , window.DesiraeRenderCss - , { themes: true, assets: true } - ); - Desi.registerRenderer( - 'css' - , window.DesiraeRenderCss - , { themes: true, assets: true } - ); - - ['html', 'htm', 'xhtm', 'xhtml'].forEach(function (ext) { - Desi.registerRenderer( - ext - , window.DesiraeRenderHtml - , { root: true, collections: true, themes: true, assets: true } - ); + Desi.registerRenderer("js", window.DesiraeRenderCss, { + themes: true, + assets: true, + }); + Desi.registerRenderer("css", window.DesiraeRenderCss, { + themes: true, + assets: true, }); - ['md', 'markdown', 'mdown', 'mkdn', 'mkd', 'mdwn', 'mdtxt', 'mdtext'].forEach(function (ext) { - Desi.registerRenderer( - ext - , window.DesiraeRenderMarkdown - , { root: true, collections: true } - ); + ["html", "htm", "xhtm", "xhtml"].forEach(function (ext) { + Desi.registerRenderer(ext, window.DesiraeRenderHtml, { + root: true, + collections: true, + themes: true, + assets: true, + }); }); - Desi.registerRenderer( - 'jade' - , window.DesiraeRenderJade - , { root: true, collections: true, themes: true } - ); + [ + "md", + "markdown", + "mdown", + "mkdn", + "mkd", + "mdwn", + "mdtxt", + "mdtext", + ].forEach(function (ext) { + Desi.registerRenderer(ext, window.DesiraeRenderMarkdown, { + root: true, + collections: true, + }); + }); + + Desi.registerRenderer("jade", window.DesiraeRenderJade, { + root: true, + collections: true, + themes: true, + }); function gdrive2host(str) { // https://drive.google.com/folderview?id=0ByLnfhJOd1-baUh1Wms0US16QkE&usp=sharing // https://googledrive.com/host/0ByLnfhJOd1-baUh1Wms0US16QkE - var m - ; + var m; - str = str || ''; + 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]; + return "https://googledrive.com/host/" + m[1]; } } @@ -103,42 +104,42 @@ angular.module('myApp.services', []). // https://www.dropbox.com/s/3n20djtrs2p0j9k/index.html?dl=0 // https://dl.dropboxusercontent.com/s/3n20djtrs2p0j9k/index.html - str = str || ''; + 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" - ); + 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$/, ''); + return str.replace(/\/index\.html$/, ""); } function splitUrl(str) { - var m - ; + var m; - str = str || ''; + 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(/\/$/, '')) || '/' + baseUrl: (m[1] || "http://") + m[2], + basePath: (m[3] && m[3].replace(/\/$/, "")) || "/", }; } - function getBlogdir () { - return $http.get('/api/fs/rootdir').then(function (resp) { + function getBlogdir() { + return $http.get("/api/fs/rootdir").then(function (resp) { desi.blogdir = resp.data; return resp.data; }); @@ -146,18 +147,16 @@ angular.module('myApp.services', []). getBlogdir(); return { - splitUrl: splitUrl - , gdrive2host: gdrive2host - , dropbox2host: dropbox2host - , reset: function () { + splitUrl: splitUrl, + gdrive2host: gdrive2host, + dropbox2host: dropbox2host, + reset: function () { desi = {}; return getBlogdir(); - } - , toDesiDate: Desi.toLocaleDate - , meta: function () { - var d = $q.defer() - ; - + }, + toDesiDate: Desi.toLocaleDate, + meta: function () { + var d = $q.defer(); if (desi.meta) { d.resolve(desi); return d.promise; @@ -168,11 +167,9 @@ angular.module('myApp.services', []). }); return d.promise; - } - , build: function (env) { - var d = $q.defer() - ; - + }, + build: function (env) { + var d = $q.defer(); if (desi.built) { d.resolve(desi); return d.promise; @@ -183,11 +180,9 @@ angular.module('myApp.services', []). }); return d.promise; - } - , write: function (env) { - var d = $q.defer() - ; - + }, + write: function (env) { + var d = $q.defer(); if (desi.written) { d.resolve(desi); return d.promise; @@ -198,10 +193,10 @@ angular.module('myApp.services', []). }); return d.promise; - } - , putFiles: function (files) { + }, + putFiles: function (files) { return $q.when(Desi.fsapi.putFiles(files)); - } + }, }; - }] -); + }, +]); diff --git a/components/version/interpolate-filter.js b/components/version/interpolate-filter.js index 03bb198..2fc322e 100644 --- a/components/version/interpolate-filter.js +++ b/components/version/interpolate-filter.js @@ -1,9 +1,13 @@ -'use strict'; +"use strict"; -angular.module('myApp.version.interpolate-filter', []) +angular + .module("myApp.version.interpolate-filter", []) -.filter('interpolate', ['version', function(version) { - return function(text) { - return String(text).replace(/\%VERSION\%/mg, version); - }; -}]); + .filter("interpolate", [ + "version", + function (version) { + return function (text) { + return String(text).replace(/\%VERSION\%/gm, version); + }; + }, + ]); diff --git a/components/version/interpolate-filter_test.js b/components/version/interpolate-filter_test.js index ff56c52..8d67393 100644 --- a/components/version/interpolate-filter_test.js +++ b/components/version/interpolate-filter_test.js @@ -1,15 +1,19 @@ -'use strict'; +"use strict"; -describe('myApp.version module', function() { - beforeEach(module('myApp.version')); +describe("myApp.version module", function () { + beforeEach(module("myApp.version")); - describe('interpolate filter', function() { - beforeEach(module(function($provide) { - $provide.value('version', 'TEST_VER'); - })); + describe("interpolate filter", function () { + beforeEach( + module(function ($provide) { + $provide.value("version", "TEST_VER"); + }) + ); - it('should replace VERSION', inject(function(interpolateFilter) { - expect(interpolateFilter('before %VERSION% after')).toEqual('before TEST_VER after'); + it("should replace VERSION", inject(function (interpolateFilter) { + expect(interpolateFilter("before %VERSION% after")).toEqual( + "before TEST_VER after" + ); })); }); }); diff --git a/components/version/version-directive.js b/components/version/version-directive.js index 74088f8..1c159ea 100644 --- a/components/version/version-directive.js +++ b/components/version/version-directive.js @@ -1,9 +1,13 @@ -'use strict'; +"use strict"; -angular.module('myApp.version.version-directive', []) +angular + .module("myApp.version.version-directive", []) -.directive('appVersion', ['version', function(version) { - return function(scope, elm, attrs) { - elm.text(version); - }; -}]); + .directive("appVersion", [ + "version", + function (version) { + return function (scope, elm, attrs) { + elm.text(version); + }; + }, + ]); diff --git a/components/version/version-directive_test.js b/components/version/version-directive_test.js index 4a59e11..fe3e463 100644 --- a/components/version/version-directive_test.js +++ b/components/version/version-directive_test.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -describe('myApp.version module', function() { - beforeEach(module('myApp.version')); +describe("myApp.version module", function () { + beforeEach(module("myApp.version")); - describe('app-version directive', function() { - it('should print current version', function() { - module(function($provide) { - $provide.value('version', 'TEST_VER'); + describe("app-version directive", function () { + it("should print current version", function () { + module(function ($provide) { + $provide.value("version", "TEST_VER"); }); - inject(function($compile, $rootScope) { - var element = $compile('')($rootScope); - expect(element.text()).toEqual('TEST_VER'); + inject(function ($compile, $rootScope) { + var element = $compile("")($rootScope); + expect(element.text()).toEqual("TEST_VER"); }); }); }); diff --git a/components/version/version.js b/components/version/version.js index 227b913..1603561 100644 --- a/components/version/version.js +++ b/components/version/version.js @@ -1,8 +1,9 @@ -'use strict'; +"use strict"; -angular.module('myApp.version', [ - 'myApp.version.interpolate-filter', - 'myApp.version.version-directive' -]) +angular + .module("myApp.version", [ + "myApp.version.interpolate-filter", + "myApp.version.version-directive", + ]) -.value('version', '0.8.0'); + .value("version", "0.8.0"); diff --git a/components/version/version_test.js b/components/version/version_test.js index 4ca6880..b11a9b7 100644 --- a/components/version/version_test.js +++ b/components/version/version_test.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -describe('myApp.version module', function() { - beforeEach(module('myApp.version')); +describe("myApp.version module", function () { + beforeEach(module("myApp.version")); - describe('version service', function() { - it('should return current version', inject(function(version) { - expect(version).toEqual('0.1'); + describe("version service", function () { + it("should return current version", inject(function (version) { + expect(version).toEqual("0.1"); })); }); }); diff --git a/desirae-http-api.js b/desirae-http-api.js index 86e198d..4671ffc 100644 --- a/desirae-http-api.js +++ b/desirae-http-api.js @@ -1,12 +1,8 @@ -'use strict'; - -var fsapi = require('desirae/lib/node-adapters').fsapi - ; +"use strict"; +var fsapi = require("desirae/lib/node-adapters").fsapi; module.exports.create = function (options) { - var restful = {} - ; - + var restful = {}; // // Required for desirae // @@ -16,18 +12,24 @@ module.exports.create = function (options) { return; } - var opts = {} - , dirnames = req.query.dir && [req.query.dir] || (req.query.dirs && req.query.dirs.split(/,/g)) || req.body.dirs - ; - + var opts = {}, + dirnames = + (req.query.dir && [req.query.dir]) || + (req.query.dirs && req.query.dirs.split(/,/g)) || + req.body.dirs; if (!dirnames || !dirnames.length) { - res.send({ error: "please specify GET w/ req.query.dir or POST w/ _method=GET&dirs=path/to/thing,..." }); + res.send({ + error: + "please specify GET w/ req.query.dir or POST w/ _method=GET&dirs=path/to/thing,...", + }); return; } - if (!dirnames.every(function (dirname) { - return 'string' === typeof dirname; - })) { + if ( + !dirnames.every(function (dirname) { + return "string" === typeof dirname; + }) + ) { res.send({ error: "malformed request: " + JSON.stringify(dirnames) }); return; } @@ -42,13 +44,13 @@ module.exports.create = function (options) { opts.extensions = req.query.extensions.split(/,/g); } - if ('true' === req.query.dotfiles) { + if ("true" === req.query.dotfiles) { opts.dotfiles = true; } - if ('false' === req.query.sha1sum) { + if ("false" === req.query.sha1sum) { opts.sha1sum = false; } - if ('true' === req.query.contents) { + if ("true" === req.query.contents) { opts.contents = true; } @@ -68,11 +70,15 @@ module.exports.create = function (options) { return; } - var filepaths = req.query.path && [req.query.path] || (req.query.paths && req.query.paths.split(/,/g)) || req.body.paths - ; - + var filepaths = + (req.query.path && [req.query.path]) || + (req.query.paths && req.query.paths.split(/,/g)) || + req.body.paths; if (!filepaths || !filepaths.length) { - res.send({ error: "please specify GET w/ req.query.path or POST _method=GET&paths=path/to/thing,..." }); + res.send({ + error: + "please specify GET w/ req.query.path or POST _method=GET&paths=path/to/thing,...", + }); return; } @@ -86,15 +92,15 @@ module.exports.create = function (options) { }; restful.putFiles = function (req, res, next) { - if (!(/^POST|PUT$/i.test(req.method) || /^POST|PUT$/i.test(req.query._method))) { + if ( + !(/^POST|PUT$/i.test(req.method) || /^POST|PUT$/i.test(req.query._method)) + ) { next(); return; } - var opts = {} - , files = req.body.files - ; - + var opts = {}, + files = req.body.files; if (!files || !files.length) { res.send({ error: "please specify POST w/ req.body.files" }); return; @@ -107,16 +113,16 @@ module.exports.create = function (options) { }; restful.copy = function (req, res, next) { - if (!(/^POST|PUT$/i.test(req.method) || /^POST|PUT$/i.test(req.query._method))) { + if ( + !(/^POST|PUT$/i.test(req.method) || /^POST|PUT$/i.test(req.query._method)) + ) { next(); return; } - var opts = {} - , files = req.body.files - ; - - if ('object' !== typeof files || !Object.keys(files).length) { + var opts = {}, + files = req.body.files; + if ("object" !== typeof files || !Object.keys(files).length) { res.send({ error: "please specify POST w/ req.body.files" }); return; } diff --git a/index.html b/index.html index 1a71006..dc55e5f 100644 --- a/index.html +++ b/index.html @@ -2,129 +2,191 @@ - - - - + + + + + + - Desi, the DIY Blog Platform - + Desi, the DIY Blog Platform + - - - - - - + + + + + + + - - - + + + + - + + @@ -203,19 +291,26 @@ Feeds
- +
- +
- - - + diff --git a/views/authors/authors.js b/views/authors/authors.js index 1390a38..11f95a9 100644 --- a/views/authors/authors.js +++ b/views/authors/authors.js @@ -1,113 +1,134 @@ -'use strict'; +"use strict"; -angular.module('myApp.authors', ['ngRoute']) +angular + .module("myApp.authors", ["ngRoute"]) -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/authors', { - templateUrl: 'views/authors/authors.html', - controller: 'AuthorsCtrl as Authors' - }); -}]) - -.controller('AuthorsCtrl' - , ['$scope', '$timeout', '$location', 'Desirae' - , function($scope, $timeout, $location, Desirae) { - var scope = this - ; - - scope.newAuthor = function () { - console.log('new author'); - scope.new = { filename: 'new' }; - scope.selectAuthor(scope.new); - }; - - scope.selectAuthor = function (author) { - // TODO watch any change - scope.selectedAuthor = author || scope.selectedAuthor; - scope.updateHeadshotUrlNow(); - }; - - scope.upsert = function () { - var author = scope.selectedAuthor - , files = [] - , filename = author.filename - ; - - 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) }); - - console.log(files); - - Desirae.putFiles(files).then(function (results) { - console.log('updated author', results); - $location.path('/site'); - }).catch(function (e) { - author.filename = filename; - console.error(e); - window.alert("Error Nation! :/"); - throw e; - }); - }; - - scope.updateHeadshotUrlNow = function () { - var gravatar = 'http://www.gravatar.com/avatar/' + window.md5((scope.selectedAuthor.email||'foo').toLowerCase()) + '?d=identicon' - ; - - if (scope.selectedAuthor.headshot) { - scope.headshot = scope.selectedAuthor.headshot; - } - else if (scope.selectedAuthor.email) { - scope.headshot = gravatar; - } - else { - scope.headshot = 'http://www.gravatar.com/avatar/' + window.md5((scope.selectedAuthor.email||'foo').toLowerCase()) + '?d=mm'; - } - }; - - scope.updateHeadshotUrl = function () { - $timeout.cancel(scope.hslock); - scope.hslock = $timeout(function () { - scope.updateHeadshotUrlNow(); - }, 300); - }; - - function init() { - scope.newAuthor(); - - console.log('desi loading'); - Desirae.meta().then(function (desi) { - var filename - ; - - scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/'); - desi.authors = desi.authors || {}; - desi.authors.new = scope.new; - scope.authors = desi.authors; - - Object.keys(desi.authors).forEach(function (filename) { - if ('new' === filename) { - return; - } - desi.authors[filename].filename = filename; - desi.authors[filename].handle = desi.authors[filename].handle || filename; + .config([ + "$routeProvider", + function ($routeProvider) { + $routeProvider.when("/authors", { + templateUrl: "views/authors/authors.html", + controller: "AuthorsCtrl as Authors", }); + }, + ]) - filename = Object.keys(desi.authors)[0]; - scope.selectedAuthor = desi.authors[filename]; + .controller("AuthorsCtrl", [ + "$scope", + "$timeout", + "$location", + "Desirae", + function ($scope, $timeout, $location, Desirae) { + var scope = this; + scope.newAuthor = function () { + console.log("new author"); + scope.new = { filename: "new" }; + scope.selectAuthor(scope.new); + }; - scope.updateHeadshotUrlNow(); - }).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.selectAuthor = function (author) { + // TODO watch any change + scope.selectedAuthor = author || scope.selectedAuthor; + scope.updateHeadshotUrlNow(); + }; - init(); - /* + scope.upsert = function () { + var author = scope.selectedAuthor, + files = [], + filename = author.filename; + 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), + }); + + console.log(files); + + Desirae.putFiles(files) + .then(function (results) { + console.log("updated author", results); + $location.path("/site"); + }) + .catch(function (e) { + author.filename = filename; + console.error(e); + window.alert("Error Nation! :/"); + throw e; + }); + }; + + scope.updateHeadshotUrlNow = function () { + var gravatar = + "http://www.gravatar.com/avatar/" + + window.md5((scope.selectedAuthor.email || "foo").toLowerCase()) + + "?d=identicon"; + if (scope.selectedAuthor.headshot) { + scope.headshot = scope.selectedAuthor.headshot; + } else if (scope.selectedAuthor.email) { + scope.headshot = gravatar; + } else { + scope.headshot = + "http://www.gravatar.com/avatar/" + + window.md5((scope.selectedAuthor.email || "foo").toLowerCase()) + + "?d=mm"; + } + }; + + scope.updateHeadshotUrl = function () { + $timeout.cancel(scope.hslock); + scope.hslock = $timeout(function () { + scope.updateHeadshotUrlNow(); + }, 300); + }; + + function init() { + scope.newAuthor(); + + console.log("desi loading"); + Desirae.meta() + .then(function (desi) { + var filename; + + scope.blogdir = desi.blogdir.path.replace( + /^\/(Users|home)\/[^\/]+\//, + "~/" + ); + desi.authors = desi.authors || {}; + desi.authors.new = scope.new; + scope.authors = desi.authors; + + Object.keys(desi.authors).forEach(function (filename) { + if ("new" === filename) { + return; + } + desi.authors[filename].filename = filename; + desi.authors[filename].handle = + desi.authors[filename].handle || filename; + }); + + filename = Object.keys(desi.authors)[0]; + scope.selectedAuthor = desi.authors[filename]; + + scope.updateHeadshotUrlNow(); + }) + .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; + }); + } + + init(); + /* $scope.$watch(angular.bind(this, function () { return this.selectedAuthor; }), function (newValue, oldValue) { //$scope.$watch('Authors.selecteAuthor', function (newValue, oldValue) console.log(newValue, oldValue); @@ -116,4 +137,5 @@ angular.module('myApp.authors', ['ngRoute']) } }, true); */ -}]); + }, + ]); diff --git a/views/build/build.html b/views/build/build.html index ff468cb..259e112 100644 --- a/views/build/build.html +++ b/views/build/build.html @@ -3,7 +3,7 @@
@@ -11,16 +11,27 @@

Are you ready?

- Bonesaw is READY! + Bonesaw + is READY!

- +

- Push the RED button... you know you want to! + Push the RED button... you know you want to!
@@ -29,28 +40,42 @@
Production -

+

+ +

- +
- -
+ id="inputProdCanonicalUrl" + /> +
- +
- + type="text" + class="form-control" + id="inputProdOutput" + disabled + />
@@ -63,7 +88,9 @@ ng-click="Build.build(['production'])" class="btn btn-primary pull-right" type="button" - >Build Production Site + > + Build Production Site +
@@ -71,10 +98,16 @@
Development -

+

+ +

- +
-
+ id="inputDevCanonicalUrl" + /> +
- +
- + type="text" + class="form-control" + id="inputDevOutput" + disabled + />
@@ -107,13 +147,14 @@ ng-click="Build.build(['development'])" class="btn btn-primary pull-right" type="button" - >Build Development Site + > + Build Development Site +
- diff --git a/views/build/build.js b/views/build/build.js index aad9f70..7b7d780 100644 --- a/views/build/build.js +++ b/views/build/build.js @@ -1,100 +1,135 @@ -'use strict'; +"use strict"; -angular.module('myApp.build', ['ngRoute']) +angular + .module("myApp.build", ["ngRoute"]) -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/build', { - templateUrl: 'views/build/build.html', - controller: 'BuildCtrl as Build' - }); -}]) - -.controller('BuildCtrl' - , ['$scope', '$location', '$timeout', 'Desirae' - , function ($scope, $location, $timeout, DesiraeService) { - var scope = this - , path = window.path - ; - - function init() { - scope.extensions = ['md', 'html']; - - return DesiraeService.meta().then(function (desi) { - scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/'); - scope.site = desi.site; - - if (!desi.site.base_url || !desi.site.base_path) { - window.alert("Please go back to the site config and enter any mandatory missing fields (base_url, base_path)."); - return; - } - - 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'); - - return desi; - }).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.onError = function (e) { - console.error(e); - if (window.confirm("Encountered an error. Please inspect the console.\n\nWould you like to ignore the error and continue?")) { - return window.Promise.resolve(); - } else { - return window.Promise.reject(); - } - }; - - scope.buildOne = function (envstr) { - return DesiraeService.reset().then(function () { - return init().then(function () { - var env - ; - - // TODO is there a legitimate case where in addition to base_path (root of the blog) - // a user would need owner_base? i.e. school.edu/~/rogers/blog school.edu/~/rogers/assets - if ('production' === envstr) { - env = { - url: scope.production_url - , base_url: scope.production_url.replace(/(https?:\/\/[^\/#?]+).*/, '$1') - , base_path: scope.production_url.replace(/https?:\/\/[^\/#?]+/, '') - , compiled_path: 'compiled' - , since: 0 - , onError: scope.onError - }; - } else { - env = { - url: scope.development_url - , base_url: scope.development_url.replace(/(https?:\/\/[^\/#?]+).*/, '$1') - , base_path: scope.development_url.replace(/https?:\/\/[^\/#?]+/, '') - , compiled_path: 'compiled_dev' - , since: 0 - , onError: scope.onError - }; - } - - return DesiraeService.build(env).then(function () { - DesiraeService.write(env); - }); + .config([ + "$routeProvider", + function ($routeProvider) { + $routeProvider.when("/build", { + templateUrl: "views/build/build.html", + controller: "BuildCtrl as Build", }); - }); - }; + }, + ]) - scope.build = function (envs) { - window.forEachAsync(envs, function (env) { - return scope.buildOne(env); - }).then(function () { - window.alert('Build(s) Complete'); - }); - }; + .controller("BuildCtrl", [ + "$scope", + "$location", + "$timeout", + "Desirae", + function ($scope, $location, $timeout, DesiraeService) { + var scope = this, + path = window.path; + function init() { + scope.extensions = ["md", "html"]; - init(); -}]); + return DesiraeService.meta() + .then(function (desi) { + scope.blogdir = desi.blogdir.path.replace( + /^\/(Users|home)\/[^\/]+\//, + "~/" + ); + scope.site = desi.site; + + if (!desi.site.base_url || !desi.site.base_path) { + window.alert( + "Please go back to the site config and enter any mandatory missing fields (base_url, base_path)." + ); + return; + } + + 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"); + + return desi; + }) + .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.onError = function (e) { + console.error(e); + if ( + window.confirm( + "Encountered an error. Please inspect the console.\n\nWould you like to ignore the error and continue?" + ) + ) { + return window.Promise.resolve(); + } else { + return window.Promise.reject(); + } + }; + + scope.buildOne = function (envstr) { + return DesiraeService.reset().then(function () { + return init().then(function () { + var env; + + // TODO is there a legitimate case where in addition to base_path (root of the blog) + // a user would need owner_base? i.e. school.edu/~/rogers/blog school.edu/~/rogers/assets + if ("production" === envstr) { + env = { + url: scope.production_url, + base_url: scope.production_url.replace( + /(https?:\/\/[^\/#?]+).*/, + "$1" + ), + base_path: scope.production_url.replace( + /https?:\/\/[^\/#?]+/, + "" + ), + compiled_path: "compiled", + since: 0, + onError: scope.onError, + }; + } else { + env = { + url: scope.development_url, + base_url: scope.development_url.replace( + /(https?:\/\/[^\/#?]+).*/, + "$1" + ), + base_path: scope.development_url.replace( + /https?:\/\/[^\/#?]+/, + "" + ), + compiled_path: "compiled_dev", + since: 0, + onError: scope.onError, + }; + } + + return DesiraeService.build(env).then(function () { + DesiraeService.write(env); + }); + }); + }); + }; + + scope.build = function (envs) { + window + .forEachAsync(envs, function (env) { + return scope.buildOne(env); + }) + .then(function () { + window.alert("Build(s) Complete"); + }); + }; + + init(); + }, + ]); diff --git a/views/configure/configure.html b/views/configure/configure.html index b950a9a..3fe48a5 100644 --- a/views/configure/configure.html +++ b/views/configure/configure.html @@ -14,9 +14,16 @@ Advanced
- +
- +
@@ -24,9 +31,16 @@
- +
- +
@@ -34,9 +48,16 @@
- +
- +
@@ -44,9 +65,16 @@
- +
- +
@@ -54,19 +82,24 @@
- +
- +
- - +
-
diff --git a/views/configure/configure.js b/views/configure/configure.js index d931c92..6ad375b 100644 --- a/views/configure/configure.js +++ b/views/configure/configure.js @@ -1,13 +1,16 @@ -'use strict'; +"use strict"; -angular.module('myApp.configure', ['ngRoute']) +angular + .module("myApp.configure", ["ngRoute"]) -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/configure', { - templateUrl: 'views/configure/configure.html', - controller: 'ConfigureCtrl as Configure' - }); -}]) + .config([ + "$routeProvider", + function ($routeProvider) { + $routeProvider.when("/configure", { + templateUrl: "views/configure/configure.html", + controller: "ConfigureCtrl as Configure", + }); + }, + ]) -.controller('ConfigureCtrl', [function() { -}]); + .controller("ConfigureCtrl", [function () {}]); diff --git a/views/create/create.html b/views/create/create.html index 2b4a555..305e87d 100644 --- a/views/create/create.html +++ b/views/create/create.html @@ -11,27 +11,48 @@
- +
- +
- +
- +
- +
- +
- - A longer block of help text that breaks onto a new line and may extend beyond one line. + + A longer block of help text that breaks onto a new line and + may extend beyond one line.
@@ -39,13 +60,24 @@
@@ -61,7 +93,7 @@ -
+
+ />
- +
- Put your lovely post here, in github-flavored markdown! + > + Put your lovely post here, in github-flavored markdown!
@@ -63,10 +69,13 @@ ng-model="Post.selected.format" ng-change="Post.onChange()" class="form-control" - id="select"> + id="select" + > - + - + - +
- + - diff --git a/views/post/post.js b/views/post/post.js index 171c053..c91cd84 100644 --- a/views/post/post.js +++ b/views/post/post.js @@ -1,210 +1,269 @@ -'use strict'; -angular.module('myApp.post', ['ngRoute']) +"use strict"; +angular + .module("myApp.post", ["ngRoute"]) -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/post', { - templateUrl: 'views/post/post.html', - controller: 'PostCtrl as Post' - }); -}]) + .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, DesiraeService) { - var scope = this - , path = window.path - ; - - function init() { - DesiraeService.meta().then(function (desi) { - /* + .controller("PostCtrl", [ + "$scope", + "$location", + "$timeout", + "Desirae", + function ($scope, $location, $timeout, DesiraeService) { + var scope = this, + path = window.path; + function init() { + DesiraeService.meta() + .then(function (desi) { + /* if (!scope.site.base_url) { window.alert("Please go to the site tab and add a url first"); return; } */ - scope.blogdir = desi.blogdir.path.replace(/^\/(Users|home)\/[^\/]+\//, '~/'); - scope.site = desi.site; - scope.env = desi.site; - newPost(); + scope.blogdir = desi.blogdir.path.replace( + /^\/(Users|home)\/[^\/]+\//, + "~/" + ); + scope.site = desi.site; + scope.env = desi.site; + newPost(); - if (/dropbox/.test(scope.site.base_url)) { - scope.env.explicitIndexes = true; + if (/dropbox/.test(scope.site.base_url)) { + scope.env.explicitIndexes = true; + } + + updateDate(); + }) + .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.extensions = ["md", "html"]; } - updateDate(); - }).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; - }); + function newPost() { + scope.selected = { + format: "md", + permalink: "/article/new.html", + uuid: window.uuid.v4(), + abspath: scope.blogdir, + sourcepath: "", + fileepath: "", + post: { + yml: { + title: "", + permalink: "/article/new.html", + date: DesiraeService.toDesiDate(new Date()), // "YYYY-MM-DD HH:MM pm" // TODO desirae + updated: null, + description: "", + categories: [], + tags: [], + theme: null, + layout: null, + swatch: null, + }, + }, + }; + scope.selected.date = scope.selected.post.yml.date; + scope.selected.post.frontmatter = window.jsyaml + .dump(scope.selected.post.yml) + .trim(); + } - scope.extensions = ['md', 'html']; - } + scope.onChange = function () { + var post = scope.selected.post, + selected = scope.selected; + post.yml.title = post.yml.title || ""; + selected.title = post.yml.title; + post.yml.description = post.yml.description || ""; - function newPost() { - scope.selected = { - format: 'md' - , permalink: "/article/new.html" - , uuid: window.uuid.v4() - , abspath: scope.blogdir - , sourcepath: '' - , fileepath: '' - , post: { - yml: { - title: "" - , permalink: "/article/new.html" - , date: DesiraeService.toDesiDate(new Date())// "YYYY-MM-DD HH:MM pm" // TODO desirae - , updated: null - , description: "" - , categories: [] - , tags: [] - , theme: null - , layout: null - , swatch: null + scope.slug = post.yml.title + .toLowerCase() + .replace(/["']/g, "") + .replace(/\W/g, "-") + .replace(/^-+/g, "") + .replace(/-+$/g, "") + .replace(/--/g, "-"); + + if (selected.permalink === post.yml.permalink) { + selected.permalink = "/articles/" + scope.slug + "/"; + // + '.html' //+ selected.format + + post.yml.permalink = selected.permalink; } - } - }; - scope.selected.date = scope.selected.post.yml.date; - scope.selected.post.frontmatter = window.jsyaml.dump(scope.selected.post.yml).trim(); - } - - scope.onChange = function () { - var post = scope.selected.post - , selected = scope.selected - ; - - post.yml.title = post.yml.title || ''; - selected.title = post.yml.title; - post.yml.description = post.yml.description || ''; - - scope.slug = post.yml.title.toLowerCase() - .replace(/["']/g, '') - .replace(/\W/g, '-') - .replace(/^-+/g, '') - .replace(/-+$/g, '') - .replace(/--/g, '-') - ; - - if (selected.permalink === post.yml.permalink) { - selected.permalink = '/articles/' + scope.slug + '/'; - // + '.html' //+ selected.format - - post.yml.permalink = selected.permalink; - } - /* + /* if (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(); + post.frontmatter = window.jsyaml.dump(post.yml).trim(); - // TODO use some sort of filepath pattern in config.yml - selected.path = path.join((scope.env.compiled_path || 'compiled'), post.yml.permalink); - if (!/\.html?$/.test(selected.path)) { - selected.path = path.join(selected.path, 'index.html'); - } + // TODO use some sort of filepath pattern in config.yml + selected.path = path.join( + scope.env.compiled_path || "compiled", + post.yml.permalink + ); + if (!/\.html?$/.test(selected.path)) { + selected.path = path.join(selected.path, "index.html"); + } - selected.url = path.join(scope.site.base_url + path.join(scope.site.base_path, post.yml.permalink)); - if (scope.env.explicitIndexes && /\/$/.test(selected.url)) { - selected.url += 'index.html'; - } - selected.markdown = '[' + selected.title + '](' + selected.url + ')'; - selected.ahref = '' + selected.title + ''; - selected.abspath = path.join(scope.blogdir, selected.path); - selected.filepath = path.join((selected.collection || 'posts'), scope.slug + '.' + selected.format); - selected.sourcepath = path.join(scope.blogdir, (selected.collection || 'posts'), scope.slug + '.' + selected.format); - }; - scope.onFrontmatterChange = function () { - var data - , post - ; + selected.url = path.join( + scope.site.base_url + + path.join(scope.site.base_path, post.yml.permalink) + ); + if (scope.env.explicitIndexes && /\/$/.test(selected.url)) { + selected.url += "index.html"; + } + selected.markdown = "[" + selected.title + "](" + selected.url + ")"; + selected.ahref = + '' + selected.title + ""; + selected.abspath = path.join(scope.blogdir, selected.path); + selected.filepath = path.join( + selected.collection || "posts", + scope.slug + "." + selected.format + ); + selected.sourcepath = path.join( + scope.blogdir, + selected.collection || "posts", + scope.slug + "." + selected.format + ); + }; + scope.onFrontmatterChange = function () { + var data, post; - 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; + 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; - post = scope.selected.post; + post = scope.selected.post; - scope.selected.path = path.join((scope.env.compiled_path || 'compiled'), post.yml.permalink); - if (!/\.html?$/.test(path.basename(post.yml.permalink))) { - scope.selected.path = path.join(scope.selected.path.replace(/\.w+$/, ''), 'index.html'); + scope.selected.path = path.join( + scope.env.compiled_path || "compiled", + post.yml.permalink + ); + if (!/\.html?$/.test(path.basename(post.yml.permalink))) { + scope.selected.path = path.join( + scope.selected.path.replace(/\.w+$/, ""), + "index.html" + ); + } + + scope.selected.url = path.join( + scope.site.base_url + + path.join(scope.site.base_path, post.yml.permalink) + ); + if (scope.env.explicitIndexes && /\/$/.test(scope.selected.url)) { + scope.selected.url += "index.html"; + } + scope.selected.abspath = path.join( + scope.blogdir, + scope.selected.path + ); + scope.selected.sourcepath = path.join( + scope.blogdir, + scope.selected.collection || "posts", + scope.slug + "." + scope.selected.format + ); + scope.selected.filepath = path.join( + scope.selected.collection || "posts", + scope.slug + "." + scope.selected.format + ); + } 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(); + } + }; + + function updateDate() { + $timeout.cancel(scope.dtlock); + scope.dtlock = $timeout(function () { + if ( + scope.selected && + scope.selected.date === scope.selected.post.yml.date + ) { + scope.selected.date = scope.selected.post.yml.date = DesiraeService.toDesiDate( + new Date() + ); + } + scope.onChange(); + updateDate(); + }, 60 * 1000); } - scope.selected.url = path.join(scope.site.base_url + path.join(scope.site.base_path, post.yml.permalink)); - if (scope.env.explicitIndexes && /\/$/.test(scope.selected.url)) { - scope.selected.url += 'index.html'; - } - scope.selected.abspath = path.join(scope.blogdir, scope.selected.path); - scope.selected.sourcepath = path.join(scope.blogdir, (scope.selected.collection || 'posts'), scope.slug + '.' + scope.selected.format); - scope.selected.filepath = path.join((scope.selected.collection || 'posts'), scope.slug + '.' + scope.selected.format); - } 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(); - } - }; + scope.upsert = function () { + 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; + } - function updateDate() { - $timeout.cancel(scope.dtlock); - scope.dtlock = $timeout(function () { - if (scope.selected && scope.selected.date === scope.selected.post.yml.date) { - scope.selected.date = scope.selected.post.yml.date = DesiraeService.toDesiDate(new Date()); - } - scope.onChange(); - updateDate(); - }, 60 * 1000); - } + 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(); - scope.upsert = function () { - 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; - } + var files = []; + files.push({ + path: scope.selected.filepath, + contents: + "---\n" + + scope.selected.post.frontmatter.trim() + + "\n" + + "---\n" + + "\n" + + scope.selected.post.body.trim(), + }); - 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(); + DesiraeService.putFiles(files) + .then(function (results) { + console.log("TODO check for error"); + console.log(files); + console.log(results); + $location.path("/build"); + }) + .catch(function (e) { + $timeout.cancel(scope.dtlock); + console.error(scope.site); + console.error(e); + window.alert("Error Nation! :/"); + throw e; + }); + }; - var files = [] - ; - - files.push({ - path: scope.selected.filepath - , contents: - '---\n' - + scope.selected.post.frontmatter.trim() - + '\n' - + '---\n' - + '\n' - + scope.selected.post.body.trim() - }); - - DesiraeService.putFiles(files).then(function (results) { - console.log('TODO check for error'); - console.log(files); - console.log(results); - $location.path('/build'); - }).catch(function (e) { - $timeout.cancel(scope.dtlock); - console.error(scope.site); - console.error(e); - window.alert("Error Nation! :/"); - throw e; - }); - }; - - init(); -}]); + init(); + }, + ]); diff --git a/views/site/site.html b/views/site/site.html index 1e40480..54ec39f 100644 --- a/views/site/site.html +++ b/views/site/site.html @@ -2,11 +2,19 @@
-
@@ -15,42 +23,59 @@ General
- +
- + type="text" + class="form-control" + id="inputBlogTitle" + placeholder="My Awesome Blog" + />
- +
- + type="text" + class="form-control" + id="inputBlogTagline" + placeholder="i.e. I have not failed, I've just found 10,000 ways that do not work." + />
- +
+ class="form-control" + id="inputSiteDesc" + placeholder="i.e. For tips and tricks for try-hard ethical master cleanses, 3 wolf moons on Tumblr, disruptive lo-fi, preserving narwhals and eating kale chips, etc. YOLO." + >
- -
- +
-
+ id="inputProdHost" + /> +
+
- +
- + type="text" + class="form-control" + id="inputProdOutput" + disabled + />
-
-
@@ -111,47 +144,56 @@ Development
- +
-
+ disabled + /> +
- +
+ type="text" + class="form-control" + id="inputDevBase" + disabled + />
- +
+ disabled + />
-
-
@@ -159,7 +201,9 @@ Plugins
- +
-
+ /> +
Found in the Admin section of Google Analytics
- +
-
+ type="text" + class="form-control" + id="inputDisqusShortname" + /> +
Found under Admin > Settings in Disqus
-
- +
diff --git a/views/site/site.js b/views/site/site.js index a44b262..c9adad9 100644 --- a/views/site/site.js +++ b/views/site/site.js @@ -1,106 +1,124 @@ -'use strict'; +"use strict"; -angular.module('myApp.site', ['ngRoute']) +angular + .module("myApp.site", ["ngRoute"]) -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/site', { - templateUrl: 'views/site/site.html', - controller: 'SiteCtrl as Site' - }); -}]) + .config([ + "$routeProvider", + function ($routeProvider) { + $routeProvider.when("/site", { + templateUrl: "views/site/site.html", + controller: "SiteCtrl as Site", + }); + }, + ]) -.controller('SiteCtrl', ['$scope', '$location', 'Desirae', function ($scope, $location, Desirae) { - var scope = this - ; + .controller("SiteCtrl", [ + "$scope", + "$location", + "Desirae", + function ($scope, $location, 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; - 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; + } - 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); + throw e; + }); } - 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); - throw e; - }); - } + scope.onChange = function () { + console.log("new url [0]", scope.url); + var parts = Desirae.splitUrl(scope.url), + url; - 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; + } - if (!parts) { - scope.base_url = ''; - scope.base_path = ''; - return; - } + scope.base_url = parts.baseUrl; + scope.base_path = parts.basePath; - scope.base_url = parts.baseUrl; - scope.base_path = parts.basePath; + scope.dropboxIndex = ""; - scope.dropboxIndex = ''; + url = Desirae.gdrive2host(scope.url); - url = Desirae.gdrive2host(scope.url) - ; + if (!url && Desirae.dropbox2host(scope.url)) { + url = Desirae.dropbox2host(scope.url); + scope.dropboxIndex = "/index.html"; + } - if (!url && Desirae.dropbox2host(scope.url)) { + console.log("new url [1]", url); - url = Desirae.dropbox2host(scope.url); - scope.dropboxIndex = '/index.html'; - } + if (url) { + parts = Desirae.splitUrl(url); + scope.base_url = parts.baseUrl; + scope.base_path = parts.basePath; + } - console.log('new url [1]', url); + //scope.url = scope.base_url + scope.base_path; + }; - if (url) { - parts = Desirae.splitUrl(url); - scope.base_url = parts.baseUrl; - scope.base_path = parts.basePath; - } + 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 }); - //scope.url = scope.base_url + scope.base_path; - }; + 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; + }); + }; - 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); - 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(); -}]); + init(); + }, + ]); diff --git a/views/site/view1_test.js b/views/site/view1_test.js index 14ba79b..b9f6e6c 100644 --- a/views/site/view1_test.js +++ b/views/site/view1_test.js @@ -1,16 +1,13 @@ -'use strict'; +"use strict"; -describe('myApp.view1 module', function() { +describe("myApp.view1 module", function () { + beforeEach(module("myApp.view1")); - beforeEach(module('myApp.view1')); - - describe('view1 controller', function(){ - - it('should ....', inject(function($controller) { + describe("view1 controller", function () { + it("should ....", inject(function ($controller) { //spec body - var view1Ctrl = $controller('View1Ctrl'); + var view1Ctrl = $controller("View1Ctrl"); expect(view1Ctrl).toBeDefined(); })); - }); -}); \ No newline at end of file +});