让typecho 1.0文章内链接新窗口打开并添加nofollow

typecho 1.0文章内链接都是在本窗口打开

每个版本修改位置略有不同,本文针对typecho 1.0

或许是小不习惯点击关闭按钮多于后退按钮,所以强迫症又复发了。于是发生了后面的事儿,每一次小不发文绝大可能都是因为将搜索引擎翻了个底朝天都没有然后,然后却又无疑撞到“玄机”,经历对typecho 1.0的var目录刨根,黄土厚爱有人心,最终也算解决了typecho 1.0文章内链接从新窗口打开及给文章内链接增加nofollow的问题。

可能方案并不完美也不规范,小不是不提倡修改程序源码的,但是介于小不不会php做不到写插件及通过修改模板达到相同效果也就只能动程序了,谁让你“不乖”。当然如果大牛看到了本文请略过,然后再大法神功写过模板函数或者造个插件都是极好的。

打开HtmlRenderer.php文件,
文件所在目录位置:typecho1.0根目录下/var/CommonMark
104行 case CommonMark_Element_InlineElement::TYPE_LINK:下面增加代码段,根据需求增加,小不是2个都加了了,那么就是这样:

        case CommonMark_Element_InlineElement::TYPE_LINK:
                $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
                $attrs['target'] = $this->escape(_blank, true);
                $attrs['rel'] = $this->escape(nofollow, true);
                if ($title = $inline->getAttribute('title')) {
                    $attrs['title'] = $this->escape($title, true);
                }

请对比源代码

typecho 1.0文章内连接新窗口打开

增加代码段:
$attrs['target'] = $this->escape(_blank, true);

typecho 1.0文章内链接加上nofollow

增加代码段:
$attrs['rel'] = $this->escape(nofollow, true);

Relay Tips: 一极乐https://yijile.com/log/494/