主题备份

逸风小站 / 2023-07-05 / 原文

image

页面定制CSS
image


页首html代码


页脚html

<script type="text/javascript" language="javascript">
    const obj = {
        favicon: 'https://img.alicdn.com/imgextra/i1/O1CN01HvRSoA1yfb7WcDsXJ_!!6000000006606-73-tps-32-32.ico'
    }
    if (obj.favicon) {
        // 替换网站icon
        var linkObject = document.createElement('link');
        linkObject.rel = "shortcut icon";
        linkObject.href = obj.favicon;
        document.getElementsByTagName("head")[0].appendChild(linkObject);
    }
    // 处理单天合并文章
    const manyArticle = $('.day');
    if (manyArticle && manyArticle.length) {
        let newArticlesStr = '';
        for (let i = 0; i < manyArticle.length; i++) {
            const article = manyArticle[i];
            // console.log(article)
            // console.log(article.outerHTML)           
            if (article && article.children && article.children.length >= 12) {
                // console.log(article.children)
                const articleChildren = article.children;
                const str = `
                        <div class="day">
                            ${articleChildren[0].outerHTML}
                            ${articleChildren[1].outerHTML}
                            ${articleChildren[2].outerHTML}
                            <div class="clear"></div>
                            ${articleChildren[4].outerHTML}
                            <div class="clear"></div>
                        </div>
                        <div class="day">
                            ${articleChildren[7].outerHTML}
                            ${articleChildren[8].outerHTML}
                            ${articleChildren[9].outerHTML}
                            <div class="clear"></div>
                            ${articleChildren[10].outerHTML}
                            <div class="clear"></div>
                        </div>
                `
                
                newArticlesStr += str
            } else {
                newArticlesStr += article.outerHTML
            }
            // console.log(article.children.length)
        }
        // console.log(newArticlesStr)
        // 分页显示
        const forFlow = $('.forFlow')[0].children;
        let pageHtml = '';
        // console.log($('.forFlow'))
        if (forFlow && forFlow.length) {
            pageHtml = forFlow[forFlow.length - 2].outerHTML
        }
        
        // console.log(newArticlesStr)
        $('#mainContent')[0].innerHTML = `<div class="forFlow"> ${newArticlesStr} </div> ${pageHtml}`;
        // $('.forFlow').empty();
        // $('.forFlow').append(newArticlesStr)
        // $(".forFlow").css("visibility","visible");
    }

    // 替换摘要下的作者、时间等
    const postDesc = $('.postDesc');
    if (postDesc && postDesc.length) {
        for (let i = 0; i < postDesc.length; i++) {
            const postDescEle = postDesc[i];
            const firstChildData = postDesc[i].firstChild.data;

            const firstChildDataArr = firstChildData.split('\n');
            const timeStr = firstChildDataArr[0];
            const timeStrNew = timeStr.replace('posted @ ', '');
            let postDescStr = `<span class="create_time">${timeStrNew}</span>&nbsp;&nbsp;&nbsp;&nbsp;`;
            const postDescChildren = postDescEle.children;
            if (postDescChildren && postDescChildren.length) {
                for (let y = 0; y < postDescChildren.length; y++) {
                    const postDescChild = postDescChildren[y];
                    const postDescChildrenHtml = postDescChild.outerHTML;
                    postDescStr += `&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildrenHtml} `;
                }

            }
            postDesc[i].innerHTML = postDescStr;

        }
    }

    // 文章详情 - 将文章阅读量等信息移动到标题下边
    const postDom = $('.post');
    if (postDom && postDom[0] && postDom[0].children && postDom[0].children.length) {
        const postChildren = postDom[0].children;
        console.log(postChildren[3].children)
        const postDescChildren = postChildren[3].children;
        const newPostDescStr = `
            <div class="postDesc"> 创建时间:${postDescChildren[1].outerHTML} &nbsp;&nbsp;&nbsp;&nbsp;作者:${postDescChildren[2].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp; 阅读:${postDescChildren[3].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;评论:${postDescChildren[4].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[5].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[6].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[7].outerHTML}&nbsp;&nbsp;&nbsp;&nbsp;${postDescChildren[8].outerHTML}</div>
        `
        const str = `      
            ${postChildren[0].outerHTML}
            ${newPostDescStr}
            ${postChildren[1].outerHTML}
            ${postChildren[2].outerHTML}
        `;
         $('.post')[0].innerHTML = str;
        // console.log(postDom.children)
    }
</script>