Skip to content

bumi/travels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

my location log stored in git commits (in the locations branch). Have a look at where.is.michaelbumann.com for a nice map and list of recent places.

Got a recommendation for a place I should visit? Please create an issue.

Development

All in one:

adds location entries to an ul.location-list, fills .current-location and .next-locaton

$.get('https://api.github.com/repos/bumi/travels/commits?sha=locations', function(commits) {
  var max = commits.length;// > 11 ? 11 : commits.length;
  var future = [];
  var past = [];
  commits = commits.sort(function(c1, c2) { 
    var d1 = new Date(c1.commit.author.date);
    var d2 = new Date(c2.commit.author.date); 
    if(d1 < d2) { return 1; }
    if(d1 > d2) { return -1; }
    return 0;
  });
  for(var i=0; i < max; i++) {
    try {
      var c = commits[i].commit;
      var commitMessage = c.message.split("\n");
      var data = JSON.parse(commitMessage[commitMessage.length-1]);
      var arrival = new Date(c.author.date);
      var area = data.city || data.state || 'somewhere';
          
      var message = area + ', ' + data.country;
      if(arrival > new Date()) {
        $('.next-location').html('Planned: ' + message + ' (' + arrival.toDateString() + ')'); // assumin the last commit in the future is the next stop. which is wrong, needs to get smarter and calculate the nearest in the future
        $('.location-list').append('<li class="future">' + message + ' (' + arrival.toDateString() + ')</li>');
        future.push(c);
      } else {
        if(past.length === 0) { 
            $('.current-location').html(message); // assuming the first in the past is the current location
        }
        $('.location-list').append('<li class="past">' + message + '</li>');
        past.push(c);
      }
      
      $('.location').show();
      
    } catch(e) {
      // ignore
    } 
  };
});

Get latest location:

$.get('https://api.github.com/repos/bumi/travels/commits?sha=locations', function(commits) {
  for(var i=0; i < commits.length; i++) {
    try {
      var c = commits[i].commit;
      var commitMessage = c.message.split("\n");
      var data = JSON.parse(commitMessage[commitMessage.length-1]);
      var area = data.city || data.state || 'somewhere';
      $('.current-location').html(area + ' in ' + data.country);
      $('.location').show();
      return true;
    } catch(e) {
    } 
  };
});

Get list of locations:

$.get('https://api.github.com/repos/bumi/travels/commits?sha=locations', function(commits) {
  commits.forEach(function(commit) {
    try {
      var c = commit.commit;
      var commitMessage = c.message.split("\n");
      var data = JSON.parse(commitMessage[commitMessage.length-1]);
      var area = data.city || data.state || 'somewhere';
      $('.location-list').append('<li>' + area + ' in ' + data.country + '</li>');
      $('.location').show();
      return true;
    } catch(e) {
    } 
  });
});