<commit_before>'use strict';
var React = require('react');
var config = require('config');
var Paths = require('../mixins/PathsMixin');

module.exports = React.createClass({
  displayName: 'NavigationLink',
  mixins: [Paths],
  propTypes: {
    location: React.PropTypes.object
  },
  render: function() {
    var props = this.props;
    var page = props.page;

    if(!page) {
      console.warn('NavigationLink - missing page');

      return;
    }

    var title = page.title;
    var url = page.url;
    var pathName, prefix, wholeUrl;

    if(url.indexOf('http://') || url.indexOf('https://')) {
      wholeUrl = url;
    }
    else {
      pathName = this.props.location.pathname;
      prefix = this.getPathPrefix(pathName);

      if(url.length > 1) {
        url = url.slice(1);
      }
      else if(prefix) {
        // strip extra slash from prefix for relative root
        prefix = prefix.slice(0, -1);
      }

      wholeUrl = prefix + url;

      if(wholeUrl === '/') {
        wholeUrl = './';
      }
    }

    return <a href={wholeUrl}>{title}</a>;
  }
});<commit_msg>Simplify the implementation of NavigationLink<commit_after>'use strict';
var React = require('react');

module.exports = React.createClass({
  displayName: 'NavigationLink',
  propTypes: {
    location: React.PropTypes.object
  },
  render: function() {
    var props = this.props;
    var page = props.page;

    if(!page) {
      console.warn('NavigationLink - missing page');

      return;
    }

    var title = page.title;
    var url = page.url;
    var pathName, prefix, wholeUrl;

    if(url.indexOf('http://') || url.indexOf('https://')) {
      wholeUrl = url;
    }
    else {
      pathName = this.props.location.pathname;
      prefix = getPathPrefix(pathName);

      if(url.length > 1) {
        url = url.slice(1);
      }
      else if(prefix) {
        // strip extra slash from prefix for relative root
        prefix = prefix.slice(0, -1);
      }

      wholeUrl = prefix + url;

      if(wholeUrl === '/') {
        wholeUrl = './';
      }
    }

    return <a href={wholeUrl}>{title}</a>;
  }
});

function getPathPrefix(pathName) {
  return pathName.split('/').map(function() {
    return '';
  }).join('../');
}
{'fraction_non_alphanumeric': 0.15978456014362658, 'fraction_numerical': 0.003590664272890485, 'mean_word_length': 2.336826347305389, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5498843', 'n_tokens_mistral': 720, 'n_tokens_neox': 692, 'n_words': 156}