目前网上的修改方法都是老版本的,行号没参考意义,但修改方法是有参考意义的,照猫画虎修改了,实测很好用。

修改处在 /typecho/var/Utils/HyperDown.php 527行

修改前:

    // link
    $text = preg_replace_callback(
        "/\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]\(((?:[^\)]|\\\\\)|\\\\\()+?)\)/",
        function ($matches) {
            $escaped = $this->parseInline(
                $this->escapeBracket($matches[1]), '', false, false
            );
            $url = $this->escapeBracket($matches[2]);
            [$url, $title] = $this->cleanUrl($url, true);
            $title = empty($title) ? '' : " title=\"{$title}\"";

            return $this->makeHolder("<a href=\"{$url}\"{$title}>{$escaped}</a>");
        },
        $text
    );

修改后:

    // link
    $text = preg_replace_callback(
        "/\[((?:[^\]]|\\\\\]|\\\\\[)+?)\]\(((?:[^\)]|\\\\\)|\\\\\()+?)\)/",
        function ($matches) {
            $escaped = $this->parseInline(
                $this->escapeBracket($matches[1]), '', false, false
            );
            $url = $this->escapeBracket($matches[2]);
            [$url, $title] = $this->cleanUrl($url, true);
            $title = empty($title) ? '' : " title=\"{$title}\"";

            if( (strstr($url,'//4041314.xyz') == false )  &&   (strstr($url,'//www.4041314.xyz') == false )  ){
               return $this->makeHolder("<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\"{$title}>{$escaped}</a>");
            } else {
               return $this->makeHolder("<a href=\"{$url}\" target=\"_blank\"{$title}>{$escaped}</a>");
            }
        },
        $text
    );

将直接写的链接自动添加nofollow,566行直接改为以下内容

return "{$matches[1]}<a href=\"{$url}\"  target=\"_blank\" rel=\"nofollow\">{$link} </a>{$matches[5]}";

标签: typecho, nofollow, _blank, 外链, seo

添加新评论