Exemplo n.º 1
0
exports.resolver = function (name, options) {
    if (path.isAbsolute(name)) {
        return path.join(options.dirname, name);
    }

    return path.resolve(path.dirname(options.parent), name);
};
Exemplo n.º 2
0
var add = function (from, to, method) {
    var fromRet = parse(from);
    var toRet = parse(to);

    if (toRet.origin) {
        return to;
    }

    toRet.origin = fromRet.origin;

    if (method === RESOLVE) {
        fromRet.pathname = path.dirname(fromRet.pathname);
    }

    toRet.pathname = path[method](fromRet.pathname, toRet.pathname);

    return stringify(toRet);
};
Exemplo n.º 3
0
    the.renderer('link', function (href, title, text, auto) {
        var blank = false;
        var nofollow = false;
        var hostname;
        var port;
        var parseRet;
        var faviconHref = href;

        if (reMailTo.test(href)) {
            hostname = href.match(/@(.*)$/)[1];
            faviconHref = 'http://' + hostname;

            if(auto) {
                // 如果是自动链接,则将文字全部编码成实体符
                text = string.escapeHTML(text, true);
            }
        } else if (path.isStatic(href)) {
            parseRet = url.parse(href);

            if (!parseRet.protocol && href.slice(0, 1) !== '/') {
                href = '//' + href;
                parseRet = url.parse(href);
            }

            hostname = parseRet.hostname;
            port = parseRet.port;

            if (hostname && !reExcludeDomain.test(hostname)) {
                nofollow = true;
                blank = true;
            }
        }

        if (auto && parseRet && options.linkAutoShort) {
            text = hostname + (port ? ':' : '') + port;
        }

        return ''.concat(
            options.linkFavicon && hostname ?
                '<img class="' + options.linkFaviconClass + '" width="16" height="16"' +
                ' src="https://f.ydr.me/' + faviconHref + '">' :
                '',
            '<a',
            ' href="' + href + '"',
            title ? ' title="' + title + '"' : '',
            nofollow ? ' rel="nofollow"' : '',
            blank ? ' target="blank"' : '',
            '>',
            text,
            '</a>'
        );
    });