Tùy chỉnh giao diện Blog Garden (CNBlogs)

Mẫu tham khảo:

Kho lưu trữ GitHub: https://github.com/Summertime-Wu/make_cnblogs_better
Bài viết tham khảo: https://www.cnblogs.com/summertime-wu/p/9356736.html
Ảnh chụp mẫu:
Mẫu giao diện

Mã nguồn tùy chỉnh:

  1. Thiết lập Theme mặc định như sau:
    Cấu hình theme
  2. CSS cho trang (Page Custom CSS)
Page Custom CSS
/* --- Chỉnh sửa style mặc định --- */
#sideBar {
    display: none;
}
#mainContent {
    width: 100%;
    box-shadow: 0 0 0;
    border-radius: 0;
    opacity: 0;
    transition: 0.5s;
    margin-top: 40px;
}
#main {
    width: 50%;
    background-color: white;
}
@media screen and (max-width: 1000px) {
    #main { width: 100%; }
}
body {
    background-image: none;
    background-color: white;
    font-family: Menlo, Bitstream Vera Sans Mono, DejaVu Sans Mono, Monaco, Consolas, monospace !important;
    line-height: 1.8;
}
#cnblogs_post_body {
    font-size: 16px;
}
#green_channel {
    display: none;
}
#post_next_prev {
    display: none;
}
.forFlow img {
    margin-top: 0;
}
#cnblogs_post_body img {
    max-width: 100%;
}
/* Ẩn quảng cáo */
#cb_post_title_url {
    display: none;
}
#cnblogs_c1, #cnblogs_c2, #ad_t2, #kb_block, #under_post_news, #header, #BlogPostCategory, #comment_nav, #author_profile_follow {
    display: none;
}
.postDesc {
    border-bottom: none;
}
/* --- Style tùy chỉnh --- */
/* Thanh tiến trình */
#myProgressBar {
    width: 15%;
    height: 2px;
    background-color: #eb5055;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
}
#nprogress {
    pointer-events: none;
}
#nprogress .bar {
    background: #eb5055;
    position: fixed;
    z-index: 1031;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
}
#nprogress .peg {
    display: block;
    position: absolute;
    right: 0;
    width: 100px;
    height: 100%;
    box-shadow: 0 0 10px #eb5055, 0 0 5px #eb5055;
    opacity: 1;
    transform: rotate(3deg) translate(0px, -4px);
}
#nprogress .spinner {
    display: block;
    position: fixed;
    z-index: 1031;
    top: 15px;
    right: 15px;
}
#nprogress .spinner-icon {
    width: 18px;
    height: 18px;
    border: solid 2px transparent;
    border-top-color: #eb5055;
    border-left-color: #eb5055;
    border-radius: 50%;
    animation: nprogress-spinner 400ms linear infinite;
}
.nprogress-custom-parent {
    overflow: hidden;
    position: relative;
}
.nprogress-custom-parent #nprogress .spinner,
.nprogress-custom-parent #nprogress .bar {
    position: absolute;
}
@keyframes nprogress-spinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Thanh điều hướng */
#mynavbar {
    width: 100%;
    height: 70px;
    position: fixed;
    display: block;
    top: 0;
    z-index: 100;
    background-color: white;
    transition: 0.5s ease-in-out;
    box-shadow: 0 1px 5px rgba(0,0,0,0.1);
}
#mynavbar_menu {
    display: inline-block;
    width: auto;
    position: relative;
    float: right;
    text-align: right;
    line-height: 68px;
}
#mynavbar_menu a {
    padding: 0 15px;
    font-size: 14px;
    outline: 0;
    color: #313131;
    text-decoration: none;
}
#mynavbar_menu a:hover {
    color: #eb5055 !important;
}
/* Phần tiêu đề */
#myheader {
    background-color: #2175bc !important;
    margin-top: 70px;
    position: relative;
    width: 100%;
    height: 300px;
}
#myheader_bg {
    width: 100%;
    height: 300px;
    background-position: center;
    background-size: cover;
    filter: blur(3px);
    position: absolute;
}
#myheader_cover {
    position: relative;
    margin-top: 70px;
    width: 100%;
    height: 300px;
    background-color: rgba(0,0,0,0.5);
    box-shadow: 0 1px 5px rgba(0,0,0,0.3);
}
#mypost_title {
    position: relative;
    top: 105pt;
    margin: 0 auto;
    padding: 30px 25px 20px;
    max-width: 700px;
    color: white;
    transition: 0.5s;
    opacity: 0;
}
#mypost_title_e {
    margin: 0;
    padding: 5px 0 15px;
}
#mypost_title_e a {
    border: 1px solid #6fa3ef;
    border-radius: 15px;
    background: #6fa3ef;
    color: #fff;
    display: inline-block;
    margin: 4px 8px 0 0;
    padding: 0 15px;
    font-weight: 600;
    font-size: 13px;
    outline: 0;
    text-decoration: none;
    transition: 0.5s;
}
#mypost_title_e a:before {
    content: "# ";
}
#mypost_title_e a:hover {
    background-color: white;
    border: 1px solid white;
    color: black;
}
#mypost_title_f a {
    color: white;
}
#mypost_title_f a:hover {
    text-decoration: none;
}
/* Menu bên phải */
#right_meun {
    position: fixed;
    top: 100px;
    left: 74%;
    display: none;
    text-align: left;
    border-left: 1px solid #ddd;
    font-size: 12px;
}
#right_meun li {
    list-style: none !important;
}
#right_meun a {
    display: inline-table;
    margin-left: 5px;
    white-space: nowrap;
    text-decoration: none;
    color: #313131;
    outline: 0;
}
#right_meun a:hover {
    color: #eb5055;
}
#right_meun > li::before {
    position: relative;
    top: 0;
    left: -4px;
    display: inline-block;
    width: 7px;
    height: 7px;
    content: '';
    border-radius: 50%;
    background-color: #eb5055;
}
/* Thanh điều hướng dưới cùng */
#post-bottom-bar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2;
    height: 3pc;
    border-top: 1px solid #e0e0e0;
    background-color: #fff;
    margin: 0;
    padding: 0;
    transition: 0.5s ease-in-out;
}
#post-bottom-bar a {
    text-decoration: none !important;
}
.post-bottom-bar .bottom-bar-inner {
    margin: 0 auto;
    padding: 0 10px;
    max-width: 900px;
}
.bottom-bar-items {
    margin: 0 0 0 10px;
    color: #313131;
    font-size: 14px !important;
    line-height: 3pc;
    float: left;
}
.post-bottom-bar {
    margin: 0 0 0 10px;
    color: #313131;
    font-size: 14px;
    line-height: 3pc;
}
.post-bottom-bar .social-share .bottom-bar-item {
    padding: 4px;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-facebook a {
    background-color: #4267b2;
    color: #fff;
}
.post-bottom-bar .social-share .bottom-bar-item a {
    padding: 2px 10px;
    border-radius: 15px;
}
.post-bottom-bar .bottom-bar-item a {
    margin: 0;
    padding: 9pt;
    border: 0;
    background: 0 0;
    color: #313131;
    font-size: 14px;
    line-height: 3pc;
    cursor: pointer;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-twitter a {
    background-color: #1b95e0;
    color: #fff;
}
.post-bottom-bar .bottom-bar-item.bottom-bar-qrcode a {
    background-color: #5f5f5f;
    color: #fff;
}
.bottom-bar-item a:hover {
    color: #eb5055;
}
/* Điều chỉnh MarkDown */
.cnblogs-markdown .hljs {
    font-size: 16px !important;
    line-height: 2 !important;
    padding: 15px !important;
}
.cnblogs-markdown code {
    background: rgb(238,240,244) none !important;
    border: 0 !important;
    color: rgb(73,59,92) !important;
    font-size: 16px !important;
    tab-size: 4;
}
.cnblogs-markdown h2 {
    font-weight: 500;
    margin: 20px 0;
}
.cnblogs-markdown h2:before {
    content: "#";
    color: #eb5055;
    position: relative;
    top: 0;
    left: -12px;
}
#cnblogs_post_body h2 {
    font-weight: 500;
    margin: 20px 0;
}
#cnblogs_post_body h3 {
    font-size: 16px;
    font-weight: bold;
    line-height: 1.5;
    margin: 10px 0;
}
.cnblogs-markdown h3:before {
    content: "##";
    color: #2175bc;
    position: relative;
    top: 0;
    left: -8px;
}
.postBody blockquote, .postCon blockquote {
    background-image: none;
    border-left: 5px solid #DDDFE4;
    background-color: #EEF0F4;
    width: 100%;
    padding: 6px 0 6px 25px;
}
blockquote {
    border: 0;
}
/* Thêm số dòng cho code */
.cnblogs-markdown .syntaxhighlighter table td.code {
    width: 95% !important;
}
.cnblogs-markdown .syntaxhighlighter code {
    font-family: "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background-color: transparent !important;
}
.cnblogs-markdown .syntaxhighlighter code:before {
    letter-spacing: -0.5em;
}
.cnblogs-markdown em {
    font-style: italic;
}
/* Thay đổi thanh cuộn và màu nền chữ được chọn */
::selection {
    background-color: #eb5055;
    color: #fff;
}
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-thumb {
    min-height: 28px;
    background-color: #c2c2c2;
    background-clip: padding-box;
}
::-webkit-scrollbar-track-piece {
    background-color: #fff;
}
*, :after, :before {
    box-sizing: border-box;
}
/* Tối ưu hiển thị danh sách bài viết */
.day {
    border-radius: 10px;
    box-shadow: 0 0 20px 2px rgba(0,0,0,0.1);
    margin-top: 40px;
    transition: 0.3s;
}
.day:hover {
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.dayTitle {
    display: none;
}
/* Tối ưu khu vực bình luận */
.feedbackItem {
    background-color: ghostwhite;
    border-radius: 10px;
    padding: 20px;
    margin-top: 20px;
    border: 0;
}
.comment_textarea {
    padding: 15px;
    border-radius: 10px;
    outline: 0;
    resize: none;
    overflow: hidden;
    width: 100%;
}
.comment_btn {
    border: 1px solid #f7f7f7;
    border-radius: 30px;
    background-color: #f7f7f7;
    font-size: 13px;
    cursor: pointer;
    height: 32px;
    padding: 0 20px;
    position: absolute;
    right: 6%;
    bottom: 38px;
    width: auto;
}
.comment_btn:hover {
    border: 1px solid #eb5055;
    background-color: white;
    color: #eb5055;
    transition-duration: 0.4s;
}
.feedback_area_title {
    display: none;
}
.commentbox_main {
    margin-top: 20px;
}
HTML đầu trang


<div id="myProgressBar" style="display: none;"></div>


<div id="mynavbar" style="margin-top: 0;">
    <div style="position: relative; width: 65pc; height: 70px; margin: 0 auto;">
        <a style="width: auto; height: 22px; margin-left: 25px;" class="c-c" href="https://www.cnblogs.com/summertime-wu">
            <img id="nv-icon" style="width: auto; height: 22px; outline: 0; margin-top: 25px;">
        </a>
        <div id="mynavbar_menu">
            <a href="https://www.cnblogs.com/summertime-wu" class="c-c">Trang chủ</a>
            <a href="https://msg.cnblogs.com/send/summertime-wu" class="c-c">Liên hệ</a>
            <a id="myGayhubUrl" href="https://github.com/Summertime-Wu" class="c-c">Github</a>
            <a id="friendLink" href="#">Liên kết bạn bè</a>
            <a href="https://www.cnblogs.com/">Blog Garden</a>
            <a href="https://i.cnblogs.com/posts">Quản lý</a>
            <a id="aboutMe" href="#">Giới thiệu</a>
        </div>
    </div>
</div>


<a name="mtop"></a>


<div id="myheader">
    <div id="myheader_bg"></div>
    <div id="myheader_cover" title="Nhấp vào tôi">
        <div id="mypost_title">
            <div id="mypost_title_h" style="font-weight: 500; font-size: 21px;"></div>
            <div id="mypost_title_f"></div>
            <div id="mypost_title_e">
                <a href="https://www.cnblogs.com/" class="c-c" style="">Chưa phân loại</a>
            </div>
        </div>
    </div>
</div>

HTML chân trang

<div id="post-bottom-bar" class="post-bottom-bar" style="bottom: 0;">
    <div class="bottom-bar-inner">
        <div class="bottom-bar-items social-share" style="float: left;">
            <span class="bottom-bar-item bottom-bar-facebook">
                <a id="bottom-d" href="javascript:void(0)" target="_blank">Hay thì like</a>
            </span>
            <span class="bottom-bar-item bottom-bar-twitter">
                <a id="bottom-g" href="javascript:void(0)" target="_blank">Theo dõi tôi</a>
            </span>
            <span class="bottom-bar-item bottom-bar-qrcode">
                <a id="bottom-s" href="javascript:void(0)" target="_blank">Lưu bài viết</a>
            </span>
        </div>
        <div class="bottom-bar-items right" style="float: right;">
            <span class="bottom-bar-item"><a id="mbottom-left" href="javascript:void(0);">←</a></span>
            <span class="bottom-bar-item"><a id="mbottom-right" href="javascript:void(0);">→</a></span>
            <span class="bottom-bar-item"><a href="#mfooter">↓</a></span>
            <span class="bottom-bar-item"><a href="#mtop">↑</a></span>
        </div>
    </div>
</div>
<a name="mfooter"></a>


<script type="text/javascript" src="https://blog-static.cnblogs.com/files/summertime-wu/nprogress.js"></script>
<script type="text/javascript">
    var nickName = null;
    var slogan = 'Không sinh mã, chỉ là người vận chuyển mã';
    var icon = "https://images.cnblogs.com/cnblogs_com/blogs/678980/galleries/2069151/o_211202145135_block.png";
    var defaultPic = "https://images.cnblogs.com/cnblogs_com/blogs/678980/galleries/2069151/o_211202142624_pexels-johannes-plenio-1435075.jpg";
    var iconB = "https://images.cnblogs.com/cnblogs_com/blogs/678980/galleries/2069151/o_211202151647_s.png";
    var friendLink = "https://www.cnblogs.com/summertime-wu/p/9350833.html";
    var aboutMe = "https://www.cnblogs.com/summertime-wu/p/9350808.html";
    var myGayhubUrl = "https://github.com/CVKakashi";

    $(document).ready(function() {
        if (nickName == null) {
            var footerOverTestArray = $($("#footer")[0].childNodes[2]).text().trim().split(" ");
            nickName = footerOverTestArray[footerOverTestArray.length - 1];
        }
        NProgress.start();
        NProgress.done();
        $("#myProgressBar").hide();
        if ($("#head_bg_img").val() != null && $("#head_bg_img").val() != "") {
            $("#myheader_bg").css("background-image", "url(" + $("#head_bg_img").val() + ")");
        } else {
            $("#myheader_bg").css("background-image", "url(" + defaultPic + ")");
        }
        if ($("#cb_post_title_url").html()) {
            $("#mypost_title_h").html($("#cb_post_title_url").html());
        } else {
            $("#mypost_title_h").html(nickName);
        }
        $("#mainContent").css("opacity", "1");
        $("#mainContent").css("margin-top", "0");
        $("#mypost_title").css("opacity", "1");
        $("#mypost_title").css("top", "75pt");

        var ccList = $(".c-c");
        ccList.each(function() {
            $(this).attr("href", $(this).attr("href").replace("summertime-wu", currentBlogApp));
        });
        if (myGayhubUrl != null) {
            $("#myGayhubUrl").attr("href", myGayhubUrl);
        }
        $("#friendLink").attr("href", friendLink);
        $("#aboutMe").attr("href", aboutMe);
        $("#nv-icon").attr("src", icon);
        var linkObject = document.createElement("link");
        linkObject.rel = "shortcut icon";
        linkObject.href = iconB;
        document.getElementsByTagName("head")[0].appendChild(linkObject);

        if (window.location.href == "https://www.cnblogs.com/" + currentBlogApp ||
            window.location.href == "https://www.cnblogs.com/" + currentBlogApp + "/" ||
            window.location.href == "http://www.cnblogs.com/" + currentBlogApp ||
            window.location.href == "http://www.cnblogs.com/" + currentBlogApp + "/") {
            $("#bottom-d").html("Liên kết bạn bè");
            $("#bottom-d").attr("href", friendLink);
        } else {
            var url = window.location.href;
            var lastUrl = url.substring(url.lastIndexOf("/") + 1);
            var mpageId = lastUrl.substring(0, lastUrl.indexOf("."));
            $("#bottom-d").click(function() {
                DiggIt(mpageId, cb_blogId, 1);
                green_channel_success(this, 'Cảm ơn đã đề xuất!');
            });
        }
    });

    setTimeout(afterAjax, 1000);
    function afterAjax() {
        if (window.location.href == "https://www.cnblogs.com/" + currentBlogApp ||
            window.location.href == "https://www.cnblogs.com/" + currentBlogApp + "/" ||
            window.location.href == "http://www.cnblogs.com/" + currentBlogApp ||
            window.location.href == "http://www.cnblogs.com/" + currentBlogApp + "/") {
            $("#mypost_title_e").html('<a href="https://cnblogs.com/' + currentBlogApp + '">' + slogan + '</a>');
        } else {
            var classification = null;
            if ($("#BlogPostCategory").html() != null && $("#BlogPostCategory").html() != "") {
                classification = $("#BlogPostCategory").html();
                classification = classification.substring(3, classification.length);
            } else {
                classification = '<a href="https://cnblogs.com/' + currentBlogApp + '">Chưa phân loại</a>';
            }
            var ftitle = 'Xuất bản ngày ' + $("#post-date").html() + ' trong ' + classification +
                ' với <a href="https://cnblogs.com/' + currentBlogApp + '">' + nickName + '</a>';
            $("#mypost_title_f").html(ftitle);
            $("#mypost_title_e").html(classification);
            var pnp = $("#post_next_prev a");
            $("#mbottom-left").attr("href", pnp[1].href);
            if (pnp.length > 2) {
                $("#mbottom-right").attr("href", pnp[3].href);
            }
        }
        $("#myheader_bg").css("filter", "blur(0px)");
        $("#comment_form_container p:last").hide();
        $("#commentbox_opt a:last").hide();
        $("#tbCommentBody").attr('placeholder', 'Nhập bình luận của bạn. Hãy lịch sự.');
    }

    $("#bottom-g").click(function() {
        $('#green_channel_follow').click();
        return false;
    });
    $("#bottom-s").click(function() {
        AddToWz(cb_entryId);
        return false;
    });

    var oldScrollNum = 0;
    window.onscroll = function() {
        var t = document.documentElement.scrollTop || document.body.scrollTop;
        if (t > oldScrollNum) {
            if (t > 120) {
                $("#mynavbar").css("margin-top", "-70px");
                $("#post-bottom-bar").css("bottom", "-3pc");
            }
            if (t > 300) {
                $("#right_meun").css("display", "inline-block");
            }
        } else {
            if (oldScrollNum - t < 20) {
                $("#mynavbar").css("margin-top", "0px");
                $("#post-bottom-bar").css("bottom", "0");
            }
            if (t <= 300) {
                $("#right_meun").css("display", "none");
            }
        }
        oldScrollNum = t;
    };

    $("#myheader_cover").click(function() {
        if ($("#myheader_bg").css("filter") == "blur(3px)") {
            $("#myheader_bg").css("filter", "blur(0px)");
        } else {
            $("#myheader_bg").css("filter", "blur(3px)");
        }
    });
</script>

<script type="text/javascript">
    var setMyBlog = {
        setCopyright: function() {
            var info_str = '<p>Tác giả: <a target="_blank">@gzdaijie</a><br>' +
                'Bài viết gốc, vui lòng ghi rõ nguồn: <a class="uri"></a></p><hr></hr>';
            var info = $(info_str);
            var info_a = info.find("a");
            var url = window.location.href;
            $(info_a[0]).attr("href", "https://github.com/gzdaijie");
            $(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, ""));
                    item.removeClass().addClass("brush: " + lang + ";");
                    SyntaxHighlighter.all();
                });
            }
        },
        setAtarget: function() {
            $("#cnblogs_post_body a").each(function() {
                this.target = "_blank";
            });
        },
        setContent: function() {
            var captions_ori = $("#cnblogs_post_body h2");
            var captions_ori2 = $("#cnblogs_post_body h3");
            var captions = $("#cnblogs_post_body h2, #cnblogs_post_body h3").clone();
            var content = $("<ul id='right_meun'></ul>");
            $("#cnblogs_post_body").prepend(content.append(captions));
            var index = -1,
                index2 = -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 '<li id="' + index + 'li"><a href="#_caption_' + index + '">' + self.innerHTML + '</a><ul></ul></li>';
                } else {
                    index2 += 1;
                    $('<a name="_caption' + index2 + '"></a>').insertBefore(captions_ori2[index2]);
                    $("#" + index + "li ul").append('<li><a href="#_caption' + index2 + '" style="color:#5f5f5f;">' + self.innerHTML + "</a></li>");
                    return;
                }
            });
        },
        runAll: function() {
            this.setAtarget();
            if (document.body.clientWidth >= 1000) {
                this.setContent();
            }
            this.setCodeRow();
        }
    };
    setMyBlog.runAll();
</script>

<script src="//cdn.bootcss.com/highlightjs-line-numbers.js/1.1.0/highlightjs-line-numbers.min.js"></script>
<script>hljs.initLineNumbersOnLoad();</script>

Giao diện được triển khai dựa trên kho lưu trữ GitHub và bài viết được liên kết ở trên. Mã nguồn tùy chỉnh đã được mô tả chi tiết, bạn có thể tùy chỉnh theo hướng dẫn.

Thẻ: CNBlogs Blog Garden css Custom Theme NProgress

Đăng vào ngày 27 tháng 5 lúc 08:15