function urlFor(context, data, absolute) {
    var urlPath = '/',
        secure, imagePathRe,
        knownObjects = ['post', 'tag', 'author', 'image', 'nav'], baseUrl,
        hostname,

    // this will become really big
    knownPaths = {
        home: '/',
        rss: '/rss/',
        api: '/ghost/api/v0.1'
    };

    // Make data properly optional
    if (_.isBoolean(data)) {
        absolute = data;
        data = null;
    }

    // Can pass 'secure' flag in either context or data arg
    secure = (context && context.secure) || (data && data.secure);

    if (_.isObject(context) && context.relativeUrl) {
        urlPath = context.relativeUrl;
    } else if (_.isString(context) && _.indexOf(knownObjects, context) !== -1) {
        // trying to create a url for an object
        if (context === 'post' && data.post) {
            urlPath = data.post.url;
            secure = data.secure;
        } else if (context === 'tag' && data.tag) {
            urlPath = '/' + ghostConfig.routeKeywords.tag + '/' + data.tag.slug + '/';
            secure = data.tag.secure;
        } else if (context === 'author' && data.author) {
            urlPath = '/' + ghostConfig.routeKeywords.author  + '/' + data.author.slug + '/';
            secure = data.author.secure;
        } else if (context === 'image' && data.image) {
            urlPath = data.image;
            imagePathRe = new RegExp('^' + ghostConfig.paths.subdir + '/' + ghostConfig.paths.imagesRelPath);
            absolute = imagePathRe.test(data.image) ? absolute : false;
            secure = data.image.secure;

            if (absolute) {
                // Remove the sub-directory from the URL because ghostConfig will add it back.
                urlPath = urlPath.replace(new RegExp('^' + ghostConfig.paths.subdir), '');
                baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
                baseUrl = baseUrl.replace(/\/$/, '');
                urlPath = baseUrl + urlPath;
            }

            return urlPath;
        } else if (context === 'sitemap-xsl') {
            absolute = true;
            urlPath = '/sitemap.xsl';
        } else if (context === 'nav' && data.nav) {
            urlPath = data.nav.url;
            baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
            hostname = baseUrl.split('//')[1] + ghostConfig.paths.subdir;
            if (urlPath.indexOf(hostname) > -1 && urlPath.indexOf('.' + hostname) === -1) {
                // make link relative to account for possible
                // mismatch in http/https etc, force absolute
                // do not do so if link is a subdomain of blog url
                urlPath = urlPath.split(hostname)[1];
                if (urlPath.substring(0, 1) !== '/') {
                    urlPath = '/' + urlPath;
                }
                absolute = true;
            }
        }
        // other objects are recognised but not yet supported
    } else if (_.isString(context) && _.indexOf(_.keys(knownPaths), context) !== -1) {
        // trying to create a url for a named path
        urlPath = knownPaths[context] || '/';
    }

    // This url already has a protocol so is likely an external url to be returned
    if (urlPath && (urlPath.indexOf('://') !== -1 || urlPath.indexOf('mailto:') === 0)) {
        return urlPath;
    }

    return createUrl(urlPath, absolute, secure);
}
// This is probably not the right place for this, but it's the best place for now
This is probably not the right place for this, but it's the best place for now
This is probably not the right place for this but it ' s the best place for now
function urlFor(context, data, absolute) {
    var urlPath = '/',
        secure, imagePathRe,
        knownObjects = ['post', 'tag', 'author', 'image', 'nav'], baseUrl,
        hostname,
    knownPaths = {
        home: '/',
        rss: '/rss/',
        api: '/ghost/api/v0.1'
    };
    if (_.isBoolean(data)) {
        absolute = data;
        data = null;
    }
    secure = (context && context.secure) || (data && data.secure);
    if (_.isObject(context) && context.relativeUrl) {
        urlPath = context.relativeUrl;
    } else if (_.isString(context) && _.indexOf(knownObjects, context) !== -1) {
        if (context === 'post' && data.post) {
            urlPath = data.post.url;
            secure = data.secure;
        } else if (context === 'tag' && data.tag) {
            urlPath = '/' + ghostConfig.routeKeywords.tag + '/' + data.tag.slug + '/';
            secure = data.tag.secure;
        } else if (context === 'author' && data.author) {
            urlPath = '/' + ghostConfig.routeKeywords.author  + '/' + data.author.slug + '/';
            secure = data.author.secure;
        } else if (context === 'image' && data.image) {
            urlPath = data.image;
            imagePathRe = new RegExp('^' + ghostConfig.paths.subdir + '/' + ghostConfig.paths.imagesRelPath);
            absolute = imagePathRe.test(data.image) ? absolute : false;
            secure = data.image.secure;
            if (absolute) {
                urlPath = urlPath.replace(new RegExp('^' + ghostConfig.paths.subdir), '');
                baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
                baseUrl = baseUrl.replace(/\/$/, '');
                urlPath = baseUrl + urlPath;
            }
            return urlPath;
        } else if (context === 'sitemap-xsl') {
            absolute = true;
            urlPath = '/sitemap.xsl';
        } else if (context === 'nav' && data.nav) {
            urlPath = data.nav.url;
            baseUrl = (secure && ghostConfig.urlSSL) ? ghostConfig.urlSSL : ghostConfig.url;
            hostname = baseUrl.split('//')[1] + ghostConfig.paths.subdir;
            if (urlPath.indexOf(hostname) > -1 && urlPath.indexOf('.' + hostname) === -1) {
                urlPath = urlPath.split(hostname)[1];
                if (urlPath.substring(0, 1) !== '/') {
                    urlPath = '/' + urlPath;
                }
                absolute = true;
            }
        }
    } else if (_.isString(context) && _.indexOf(_.keys(knownPaths), context) !== -1) {
        urlPath = knownPaths[context] || '/';
    }
    if (urlPath && (urlPath.indexOf('://') !== -1 || urlPath.indexOf('mailto:') === 0)) {
        return urlPath;
    }
    return createUrl(urlPath, absolute, secure);
}
function urlFor ( context , data , absolute ) { var urlPath = '/' , secure , imagePathRe , knownObjects = [ 'post' , 'tag' , 'author' , 'image' , 'nav' ] , baseUrl , hostname , knownPaths = { home : '/' , rss : '/rss/' , api : '/ghost/api/v0.1' } ; if ( _ . isBoolean ( data ) ) { absolute = data ; data = null ; } secure = ( context && context . secure ) || ( data && data . secure ) ; if ( _ . isObject ( context ) && context . relativeUrl ) { urlPath = context . relativeUrl ; } else if ( _ . isString ( context ) && _ . indexOf ( knownObjects , context ) !== - 1 ) { if ( context === 'post' && data . post ) { urlPath = data . post . url ; secure = data . secure ; } else if ( context === 'tag' && data . tag ) { urlPath = '/' + ghostConfig . routeKeywords . tag + '/' + data . tag . slug + '/' ; secure = data . tag . secure ; } else if ( context === 'author' && data . author ) { urlPath = '/' + ghostConfig . routeKeywords . author + '/' + data . author . slug + '/' ; secure = data . author . secure ; } else if ( context === 'image' && data . image ) { urlPath = data . image ; imagePathRe = new RegExp ( '^' + ghostConfig . paths . subdir + '/' + ghostConfig . paths . imagesRelPath ) ; absolute = imagePathRe . test ( data . image ) ? absolute : false ; secure = data . image . secure ; if ( absolute ) { urlPath = urlPath . replace ( new RegExp ( '^' + ghostConfig . paths . subdir ) , '' ) ; baseUrl = ( secure && ghostConfig . urlSSL ) ? ghostConfig . urlSSL : ghostConfig . url ; baseUrl = baseUrl . replace ( / \/$ / , '' ) ; urlPath = baseUrl + urlPath ; } return urlPath ; } else if ( context === 'sitemap-xsl' ) { absolute = true ; urlPath = '/sitemap.xsl' ; } else if ( context === 'nav' && data . nav ) { urlPath = data . nav . url ; baseUrl = ( secure && ghostConfig . urlSSL ) ? ghostConfig . urlSSL : ghostConfig . url ; hostname = baseUrl . split ( '//' ) [ 1 ] + ghostConfig . paths . subdir ; if ( urlPath . indexOf ( hostname ) > - 1 && urlPath . indexOf ( '.' + hostname ) === - 1 ) { urlPath = urlPath . split ( hostname ) [ 1 ] ; if ( urlPath . substring ( 0 , 1 ) !== '/' ) { urlPath = '/' + urlPath ; } absolute = true ; } } } else if ( _ . isString ( context ) && _ . indexOf ( _ . keys ( knownPaths ) , context ) !== - 1 ) { urlPath = knownPaths [ context ] || '/' ; } if ( urlPath && ( urlPath . indexOf ( '://' ) !== - 1 || urlPath . indexOf ( 'mailto:' ) === 0 ) ) { return urlPath ; } return createUrl ( urlPath , absolute , secure ) ; }
This is probably not the right place for this, but it's the best place for now
This is probably not the right place for this but it ' s the best place for now
// this will become really big // Make data properly optional // Can pass 'secure' flag in either context or data arg // trying to create a url for an object // Remove the sub-directory from the URL because ghostConfig will add it back. // make link relative to account for possible // mismatch in http/https etc, force absolute // do not do so if link is a subdomain of blog url // other objects are recognised but not yet supported // trying to create a url for a named path // This url already has a protocol so is likely an external url to be returned