博客园美化:添加目录,标题设置,代码高亮,主题设置

博客园标题

点开“管理”,“设置”
在”页面定制CSS代码“中输入一下代码javascript

//博客园标题
#cnblogs_post_body
{
    color: black;      
    font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif;
    font-size: 15px;
}
#cnblogs_post_body h1    {
    background: #333366;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 23px;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h2    {
    background: #006699;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 20px;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h3    {
    background: #2B6695;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 18px;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h4{
    background: #2B6600;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 16px;
    font-weight: bold;
    height: 24px;
    line-height: 23px;
    margin: 12px 0 !important;
    padding: 5px 0 5px 10px;
    text-shadow: 2px 2px 3px #222222;
}

代码高亮

参考连接
点开“管理”,“设置”
在”页面定制CSS代码“中输入一下代码css

/*
 代码高亮开始,使用了一个叫Monokai Sublime的黑色主题皮肤,直接拿过来还不行,有一些样式冲突,还要本身稍微改一些地方
Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
*/
pre {
/*控制代码不换行*/
    white-space: pre;
    word-wrap: normal;
}
.cnblogs-markdown .hljs {
    display: block;
    overflow-x: auto;
    padding: 0.5em;
    background: #23241f !important;
    color: #FFF;
    white-space: pre;
    word-break: normal;
}

.hljs,
.hljs-tag,
.hljs-subst {
  color: #f8f8f2;
}

.hljs-strong,
.hljs-emphasis {
  color: #a8a8a2;
}

.hljs-bullet,
.hljs-quote,
.hljs-number,
.hljs-regexp,
.hljs-literal,
.hljs-link {
  color: #ae81ff;
}

.hljs-code,
.hljs-title,
.hljs-section,
.hljs-selector-class {
  color: #a6e22e;
}

.hljs-strong {
  font-weight: bold;
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-name,
.hljs-attr {
  color: #f92672;
}

.hljs-symbol,
.hljs-attribute {
  color: #66d9ef;
}

.hljs-params,
.hljs-class .hljs-title {
  color: #f8f8f2;
}

.hljs-string,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-id,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-variable {
  color: #e6db74;
}

.hljs-comment,
.hljs-deletion,
.hljs-meta {
  color: #75715e;
}

/*黑色主题皮肤结束*/

目录设置

参考连接
在”页脚HTML代码“中添加html

<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
//一下两个连接最好本身保存下来,再上传到本身的博客园的“文件”选项中
<link href="https://files.cnblogs.com/files/wudongwei/mulu.css" rel="stylesheet">
<script type="text/javascript" src="https://files.cnblogs.com/files/wudongwei/mulu.js"></script>

设置版权信息

参考连接
在"页脚Html代码"中添加java

<script type="text/javascript">  
        var setMyBlog = {
            setCopyright: function() {
                //设置版权信息,转载出处自动根据页面url生成
                //记得把个人乌冬味的连接改了,不然就是个人github地址了
                var info_str = '<p>做者:<a target="_blank">@乌冬味</a><br>'+
                    '本文为做者原创,转载请注明出处:<a class="uri"></a></p><hr></hr>', 
                    info = $(info_str),
                    info_a = info.find("a"),
                    url = window.location.href;
                $(info_a[0]).attr("href","https://github.com/xdwkeep");
                $(info_a[1]).attr("href",url).text(url);
                $("#cnblogs_post_body").prepend(info);
            },
            setCodeRow: function(){
                // 代码行号显示
                var pre = $("pre.sourceCode"); //选中须要更改的部分
                if(pre && pre.length){
                    pre.each(function() {
                        var item = $(this);
                        var lang = item.attr("class").split(" ")[1]; //判断高亮的语言
                        item.html(item.html().replace(/<[^>]+>/g,"")); //将<pre>标签中的html标签去掉
                        item.removeClass().addClass("brush: " + lang +";"); //根据语言添加笔刷
                        SyntaxHighlighter.all();
                    })
                }
            },
            setAtarget: function() {
                // 博客内的连接在新窗口打开
                $("#cnblogs_post_body a").each(function(){
                    this.target = "_blank";
                }) 
            },
            setContent: function() {
                // 这个是在文章开头的目录,我不喜欢因此注释了
                // 根据h二、h3标签自动生成目录
                var captions_ori = $("#cnblogs_post_body h2"),
                    captions = $("#cnblogs_post_body h2,#cnblogs_post_body h3").clone(),
                    content = $("<blockquote><h4>目录</h4></blockquote>");
                $("#cnblogs_post_body").prepend(content.append(captions));
                var index = -1;
                captions.replaceWith(function(){
                    var self = this;
                    if(self.tagName == "H2" || self.tagName == "h2"){
                        // 设置点击目录跳转
                        index += 1;
                        $('<a name="' + '_caption_' + index + '"></a>').insertBefore(captions_ori[index]); 
                        return '<a href="#_caption_' + index + '"><strong>' + self.innerHTML + '</strong></a><br>';
                    } else {
                        return self.innerHTML + "<br>";
                    }
                });
            },
            runAll: function() {
                /* 运行全部方法
                 * setAtarget() 博客园内标签新窗口打开
                 * setContent() 设置目录
                 * setCopyright() 设置版权信息
                 * setCodeRow() 代码行号显示,
                 */ 
                this.setAtarget(); 
                //this.setContent();
                this.setCopyright();
                //this.setCodeRow();//和黑色高亮主题冲突了,因此注释了
            }
        }
        setMyBlog.runAll();
</script>

博客园主题

我选择的是SimpleMemory,简洁美git

Changlog

2019-06-07:已更改格式,详见文章地址github

相关文章
相关标签/搜索