<commit_before>'use strict';

var path = require('path');
var red = require('ansi-red');
var relativePath = require('relative-dest');

module.exports = function linkTo(key, collectionName) {
  var name = collectionName;
  if (typeof name === 'object') {
    name = null;
  }

  name = name || 'pages';

  if (typeof this.app[name] === 'undefined') {
    var msg = 'Invalid collection `' + name + '`';
    console.error(red(msg));
    return '';
  }

  var current = this.context.view;
  var target = this.app.find(key, name);

  if (!target || !Object.keys(target).length) {
    var msg = 'Unable target find `' + key + '` in `' + name + '`';
    console.error(red(msg));
    return '';
  }

  var data = this.app.cache.data;
  var fromDest = current.data.dest;
  var targetDest = target.data.dest;

  return relativePath(fromDest, targetDest);
};<commit_msg>update "link-to" helper to respect permalinks plugin if available<commit_after>'use strict';

var path = require('path');
var red = require('ansi-red');
var relativePath = require('relative-dest');

module.exports = function linkTo(key, collectionName) {
  var name = collectionName;
  if (typeof name === 'object') {
    name = null;
  }

  name = name || 'pages';

  if (typeof this.app[name] === 'undefined') {
    var msg = 'Invalid collection `' + name + '`';
    console.error(red(msg));
    return '';
  }

  var current = this.context.view;
  var target = this.app.find(key, name);

  if (!target || !Object.keys(target).length) {
    var msg = 'Unable target find `' + key + '` in `' + name + '`';
    console.error(red(msg));
    return '';
  }

  var fromDest = current.data.permalinks ||current.data.dest;
  var targetDest = target.data.permalinks || target.data.dest;

  return relativePath(fromDest, targetDest);
};
{'fraction_non_alphanumeric': 0.17002237136465326, 'fraction_numerical': 0.0, 'mean_word_length': 3.563775510204082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5967057', 'n_tokens_mistral': 588, 'n_tokens_neox': 575, 'n_words': 147}