How to use blog - 10 common examples

To help you get started, we’ve selected a few blog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidmerfield / Blot / app / clients / dropbox / routes / change_dropbox / save-credentials.js View on Github external
// console.log('HERE!');

      // return res.redirect('/folder/change-dropbox');
    }

    // Save the old credentials in the session temporarily
    // so we can copy the files from the old acount in future
    req.session.old_credentials = req.blog.credentials;

    var updates = {dropbox: req.blog.dropbox};

    updates.dropbox.id = new_account_id;
    updates.dropbox.token = token;
    updates.dropbox.cursor = '';

    Blog.set(blogID, updates, function(err){

      if (err) return next(err);

      res.redirect('/folder/change-dropbox/copy-files');
    });
  });
};
github davidmerfield / Blot / app / clients / git / disconnect.js View on Github external
module.exports = function disconnect(blogID, callback) {
  var liveRepoDirectory = localPath(blogID, "/");
  var liveRepo;

  // Throws an error if directory does not exist
  try {
    liveRepo = Git(liveRepoDirectory).silent(true);    
  } catch (err) {
    return callback(err);
  }

  // TODO, this shit should be handled at the next layer up
  // we shouldn't worry about setting blog.client to ""
  Blog.get({ id: blogID }, function(err, blog) {
    if (err || !blog) {
      return callback(err || new Error("No blog"));
    }

    Blog.set(blogID, { client: "" }, function(err) {
      if (err) return callback(err);

      database.flush(blog.owner, function(err) {
        if (err) return callback(err);

        // Remove the bare git repo in /repos
        fs.remove(dataDir + "/" + blog.handle + ".git", function(err) {
          if (err) return callback(err);

          // Remove the .git directory in the user's blog folder?
          // maybe don't do this... they might want it...
github davidmerfield / Blot / app / dashboard / routes / preferences / index.js View on Github external
.post(saveRedirects, form, function(req, res, next){

      var blog = req.blog;
      var blogID = blog.id;
      var updates = req.body;

      Blog.set(blogID, updates, function(err, changes){

        if (err) return next(err);

        if (changes && changes.length)
          res.message({success: 'Made changes successfully!'});

        // We now need to save every entry so that
        // changes to permalink format take effect.
        if (changes.indexOf('timeZone') > -1 ||
            changes.indexOf('dateDisplay') > -1 ||
            changes.indexOf('permalink') > -1) {
          resaveEntries(blogID, function(){});
        }

        // We need to build all the blog's entries if the user
        // has changed any of the plugins or their permalink
github davidmerfield / Blot / app / dashboard / routes / settings / save / finish.js View on Github external
module.exports = function(req, res, next) {
  var blog = req.blog;
  var blogID = blog.id;
  var updates = req.updates || {};
  var redirect = req.body.redirect || req.path;

  Blog.set(blogID, updates, function(errors, changes) {

    if (errors)
      for (var i in errors)
        if (errors[i] instanceof Error)
          return next(errors[i]);

    if (errors) return next(errors);


    // We now need to save every entry so that
    // changes to permalink format take effect.
    if (
      changes.indexOf("timeZone") > -1 ||
      changes.indexOf("dateDisplay") > -1 ||
      changes.indexOf("permalink") > -1
    ) {
github davidmerfield / Blot / app / sync / index.js View on Github external
driftFactor: options.driftFactor || 0.01, // time in ms

    // the max number of times Redlock will attempt
    // to lock a resource before erroring
    retryCount: options.retryCount || 10,

    // the time in ms between attempts
    retryDelay: options.retryDelay || 200, // time in ms

    // the max time in ms randomly added to retries
    // to improve performance under high contention
    // see https://www.awsarchitectureblog.com/2015/03/backoff.html
    retryJitter: options.retryJitter || 200 // time in ms
  });

  Blog.get({ id: blogID }, function(err, blog) {
    // It would be nice to get an error from Blog.get instead of this...
    if (err || !blog || !blog.id || blog.isDisabled) {
      return callback(new Error("Cannot sync blog " + blogID));
    }

    redlock.lock(resource, ttl, function(err, lock) {
      // We failed to acquire a lock on the resource
      if (err) return callback(err);

      // Store list of locks created by this process
      // so if it dies, we can unlock them all...
      locks[blogID] = lock;

      folder = {
        path: localPath(blogID, "/"),
        update: new Update(blog)
github davidmerfield / Blot / app / sync / start.js View on Github external
function start (blogID, callback) {

  ensure(blogID, 'string')
    .and(callback, 'function');

  var options = {};

  Blog.get({id: blogID}, function(err, blog){

    if (!blog || !blog.id)
      return callback(blogID + ' ' + ERROR.NO_BLOG);

    if (blog.isDisabled)
      return callback(blogID + ' ' + ERROR.DISABLED);

    // Tag all the logs for this sync process
    var log = new Log({uid: blogID, process: 'Sync'});

    // Allow debug passed in options
    if (options.debug) log.debug = log;

    // Pass in option logging function
    options.log = options.log || log;
github davidmerfield / Blot / app / blog / vhosts.js View on Github external
// this should be req.locals.originalHost
  req.originalHost = host;

  // We don't want to serve a blog in place of
  // the main blot site so leave now.
  if (host === config.host) return next();

  handle = extractHandle(host);

  if (handle) {
    identifier = { handle: handle };
  } else {
    identifier = { domain: host };
  }

  Blog.get(identifier, function(err, blog) {
    if (err) return next(err);

    if (!blog || blog.isDisabled || blog.isUnpaid) {
      err = new Error("No blog");
      err.code = "ENOENT";
      return next(err);
    }

    // Probably a www -> apex redirect
    if (identifier.domain && blog.domain !== identifier.domain)
      redirect = req.protocol + "://" + blog.domain + req.url;

    // Redirect HTTP to HTTPS
    if (identifier.domain && blog.forceSSL && req.protocol !== "https")
      redirect = "https://" + blog.domain + req.url;
github davidmerfield / Blot / app / clients / dropbox / routes / sync / .index.js View on Github external
buildFromFolder(blog.id, function(err){

          if (err) return callback(err);

          blog.dropbox.cursor = latest_cursor;

          Blog.set(blogID, blog, function(err){

            if (err) return callback(err);

            // No we make sure that the changes
            // from dropbox conform to what we expect
            // There was a bug where json.parse(json.string(change))
            // was not equal to the change. so we do this in advance
            callback(null, changes);
          });
        });
      });
github davidmerfield / Blot / app / sync / dropbox / index.js View on Github external
changes = changes.concat(res.changes || []);

        // If Dropbox says there are more changes
        // we get them before returning the callback.
        // This is important because a rename could
        // be split across two pages of file events.
        if (more) return client.delta(newState, onFetch);

        // Nothing has changed so we leave early
        if (!changes.length) return callback();

        // We save the state before dealing with the changes
        // to avoid an infinite loop if one of these changes
        // causes an exception. If sync enounters an exception
        // it will verify the folder at a later date
        Blog.set(blogID, {folderState: newState}, function(err){

          if (err) throw err;

          // No we make sure that the changes
          // from dropbox conform to what we expect
          // There was a bug where json.parse(json.string(change))
          // was not equal to the change. so we do this in advance
          changes = changes.map(model);

          time('handle');

          handle(blog, client, changes, function(err){

            time.end('handle');

            callback(err);
github davidmerfield / Blot / app / site / routes / sites.js View on Github external
function handle() {
        if (is_subdomain) {
          by = { handle: domain.split(".blot.im").join("") };
        } else {
          by = { domain: domain };
        }

        Blog.get(by, function(err, blog) {
          if (err || !blog) {
            console.log(domain, "is not in the database");
            return next();
          }

          if (!is_subdomain && response !== blog.handle) {
            console.log(domain, "is not on blot it points to...");
            return next();
          }

          template = blog.template;

          protocol = domain.indexOf("blot.im") > -1 ? "http" : "https";

          url = protocol + "://" + site[0];
          display_url = domain.split("www.").join("");

blog

I've just started development on this node module. When i'm done, it will be a generic blog backend for new users to use and try out!

ISC
Latest version published 6 years ago

Package Health Score

40 / 100
Full package analysis

Popular blog functions