魔改方案

修改主题文件

  1. 覆盖themes\anzhiyu\layout\includes\mixins\article-sort.pug 归档,标签,分类页卡片

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    mixin articleSort(posts)
    .article-sort
    - var year
    - posts.each(function (article) {
    - let tempYear = date(article.date, 'YYYY')
    - let no_cover = article.cover === false || !theme.cover.archives_enable ? 'no-article-cover' : ''
    - let title = article.title || _p('no_title')
    if tempYear !== year
    - year = tempYear
    .article-sort-item.year= year
    .article-sort-item(class=no_cover)
    a.article-sort-item-a(href=url_for(article.path) title=title)
    if article.cover && theme.cover.archives_enable
    a.article-sort-item-img(href=url_for(article.path) title=title)
    img(src=url_for(article.cover) alt=title onerror=`this.onerror=null;this.src='${url_for(theme.error_img.post_page)}'`)
    .article-sort-item-info
    div
    a.article-sort-item-title(href=url_for(article.path) title=title)= title
    .article-sort-description= article.description
    .article-sort-meta
    .article-meta-wrap
    if (theme.post_meta.page.categories && article.categories.data.length > 0)
    span.article-sort-item-categories
    each item, index in article.categories.data
    a(href=url_for(item.path)).article-meta__categories #[=item.name]
    if (index < article.categories.data.length - 1)
    i.fas.fa-angle-right
    if (theme.post_meta.page.tags && article.tags.data.length > 0)
    span.article-sort-item-tags
    each item, index in article.tags.data
    a(href=url_for(item.path)).article-meta__tags #[=item.name]
    if (index < article.tags.data.length - 1)
    span.article-meta__link #[=' ']
    .article-sort-item-time
    i.far.fa-calendar-alt
    time.post-meta-date-created(datetime=date_xml(article.date) title=_p('post.created') + ' ' + full_date(article.date))= date(article.date, config.date_format)
    i.fas.fa-chevron-right
    - })
  2. 覆盖themes\anzhiyu\source\css_page\archives.styl archives美化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    .article-sort
    margin-left: 10px
    padding-left: 20px
    border-left: 2px solid lighten($light-blue, 20)

    &-title
    position: relative
    margin-left: 10px
    padding-bottom: 20px
    padding-left: 20px
    font-size: 1.72em
    margin: 0.25rem;
    padding: 0;
    border: none;
    font-weight: bold;
    font-size: 2em;

    &:hover
    &:before
    border-color: var(--pseudo-hover)

    &:before
    position: absolute
    top: calc(((100% - 36px) / 2))
    left: -9px
    z-index: 1
    width: w = 10px
    height: h = w
    border: .5 * w solid $light-blue
    border-radius: w
    background: var(--card-bg)
    content: ''
    line-height: h
    transition: all .2s ease-in-out

    &:after
    position: absolute
    bottom: 0
    left: 0
    z-index: 0
    width: 2px
    height: 1.5em
    background: lighten($light-blue, 20)
    content: ''

    &-item
    position: relative
    display: flex
    align-items: center
    margin: 0 0 20px 10px
    transition: all .2s ease-in-out

    &:hover
    &:before
    border-color: var(--pseudo-hover)

    &:before
    $w = 6px
    position: absolute
    left: calc(-20px - 17px)
    width: w = $w
    height: h = w
    border: .5 * w solid $light-blue
    border-radius: w
    background: var(--card-bg)
    content: ''
    transition: all .2s ease-in-out

    &.no-article-cover
    height: 80px

    .article-sort-item-info
    padding: 0

    &.year
    font-size: 1.43em

    &:hover
    &:before
    border-color: $light-blue

    &:before
    border-color: var(--pseudo-hover)

    &-time
    color: $theme-meta-color
    font-size: 95%

    time
    padding-left: 6px
    cursor: default

    &-title
    @extend .limit-more-line
    color: var(--font-color)
    font-size: 1.1em
    transition: all .3s
    -webkit-line-clamp: 2

    &:hover
    color: $text-hover
    transform: translateX(10px)

    &-img
    overflow: hidden
    width: 80px
    height: 80px

    :first-child
    @extend .imgHover

    &-info
    flex: 1
    padding: 0 0 0 16px
  3. 新建themes\anzhiyu\layout\charts.pug 文章统计

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    extends includes/layout.pug

    block content
    include ./includes/mixins/article-sort.pug
    #archive
    <div id="posts-chart" data-start="2023-01" style="height: 300px; padding: 10px;"></div>
    if theme.category_ui == 'index'
    include ./includes/mixins/post-ui.pug
    #recent-posts.recent-posts.category_ui
    +postUI
    include includes/pagination.pug
    else
    include ./includes/mixins/article-sort.pug
    #category
    <div id="categories-chart" data-parent="true" style="height: 300px; padding: 10px;"></div>
    if theme.tag_ui == 'index'
    include ./includes/mixins/post-ui.pug
    #recent-posts.recent-posts
    +postUI
    include includes/pagination.pug
    else
    include ./includes/mixins/article-sort.pug
    #tag
    <div id="tags-chart" data-length="10" style="height: 300px; padding: 10px;"></div>
  4. 新建themes\anzhiyu\scripts\helpers\charts.js 文章统计

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    const cheerio = require('cheerio')
    const moment = require('moment')

    hexo.extend.filter.register('after_render:html', function (locals) {
    const $ = cheerio.load(locals)
    const post = $('#posts-chart')
    const tag = $('#tags-chart')
    const category = $('#categories-chart')
    const htmlEncode = false

    if (post.length > 0 || tag.length > 0 || category.length > 0) {
    if (post.length > 0 && $('#postsChart').length === 0) {
    if (post.attr('data-encode') === 'true') htmlEncode = true
    post.after(postsChart(post.attr('data-start')))
    }
    if (tag.length > 0 && $('#tagsChart').length === 0) {
    if (tag.attr('data-encode') === 'true') htmlEncode = true
    tag.after(tagsChart(tag.attr('data-length')))
    }
    if (category.length > 0 && $('#categoriesChart').length === 0) {
    if (category.attr('data-encode') === 'true') htmlEncode = true
    category.after(categoriesChart(category.attr('data-parent')))
    }

    if (htmlEncode) {
    return $.root().html().replace(/&amp;#/g, '&#')
    } else {
    return $.root().html()
    }
    } else {
    return locals
    }
    }, 15)

    function postsChart(startMonth) {
    const startDate = moment(startMonth || '2023-01')
    const endDate = moment()

    const monthMap = new Map()
    const dayTime = 3600 * 24 * 1000
    for (let time = startDate; time <= endDate; time += dayTime) {
    const month = moment(time).format('YYYY-MM')
    if (!monthMap.has(month)) {
    monthMap.set(month, 0)
    }
    }
    hexo.locals.get('posts').forEach(function (post) {
    const month = post.date.format('YYYY-MM')
    if (monthMap.has(month)) {
    monthMap.set(month, monthMap.get(month) + 1)
    }
    })
    const monthArr = JSON.stringify([...monthMap.keys()])
    const monthValueArr = JSON.stringify([...monthMap.values()])

    return `
    <script id="postsChart">
    var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'
    var postsChart = echarts.init(document.getElementById('posts-chart'), 'light');
    var postsOption = {
    title: {
    text: '文章发布统计图',
    x: 'center',
    textStyle: {
    color: color
    }
    },
    tooltip: {
    trigger: 'axis'
    },
    xAxis: {
    name: '日期',
    type: 'category',
    boundaryGap: false,
    nameTextStyle: {
    color: color
    },
    axisTick: {
    show: false
    },
    axisLabel: {
    show: true,
    color: color
    },
    axisLine: {
    show: true,
    lineStyle: {
    color: color
    }
    },
    data: ${monthArr}
    },
    yAxis: {
    name: '文章篇数',
    type: 'value',
    nameTextStyle: {
    color: color
    },
    splitLine: {
    show: false
    },
    axisTick: {
    show: false
    },
    axisLabel: {
    show: true,
    color: color
    },
    axisLine: {
    show: true,
    lineStyle: {
    color: color
    }
    }
    },
    series: [{
    name: '文章篇数',
    type: 'line',
    smooth: true,
    lineStyle: {
    width: 0
    },
    showSymbol: false,
    itemStyle: {
    opacity: 1,
    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    offset: 0,
    color: 'rgba(128, 255, 165)'
    },
    {
    offset: 1,
    color: 'rgba(1, 191, 236)'
    }])
    },
    areaStyle: {
    opacity: 1,
    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    offset: 0,
    color: 'rgba(128, 255, 165)'
    }, {
    offset: 1,
    color: 'rgba(1, 191, 236)'
    }])
    },
    data: ${monthValueArr},
    markLine: {
    data: [{
    name: '平均值',
    type: 'average',
    label: {
    color: color
    }
    }]
    }
    }]
    };
    postsChart.setOption(postsOption);
    window.addEventListener('resize', () => {
    postsChart.resize();
    });
    postsChart.on('click', 'series', (event) => {
    if (event.componentType === 'series') window.location.href = '/archives/' + event.name.replace('-', '/');
    });
    </script>`
    }

    function tagsChart(len) {
    const tagArr = []
    hexo.locals.get('tags').map(function (tag) {
    tagArr.push({ name: tag.name, value: tag.length, path: tag.path })
    })
    tagArr.sort((a, b) => { return b.value - a.value })

    const dataLength = Math.min(tagArr.length, len) || tagArr.length
    const tagNameArr = []
    for (let i = 0; i < dataLength; i++) {
    tagNameArr.push(tagArr[i].name)
    }
    const tagNameArrJson = JSON.stringify(tagNameArr)
    const tagArrJson = JSON.stringify(tagArr)

    return `
    <script id="tagsChart">
    var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'
    var tagsChart = echarts.init(document.getElementById('tags-chart'), 'light');
    var tagsOption = {
    title: {
    text: 'Top ${dataLength} 标签统计图',
    x: 'center',
    textStyle: {
    color: color
    }
    },
    tooltip: {},
    xAxis: {
    name: '标签',
    type: 'category',
    nameTextStyle: {
    color: color
    },
    axisTick: {
    show: false
    },
    axisLabel: {
    show: true,
    color: color,
    interval: 0
    },
    axisLine: {
    show: true,
    lineStyle: {
    color: color
    }
    },
    data: ${tagNameArrJson}
    },
    yAxis: {
    name: '文章篇数',
    type: 'value',
    splitLine: {
    show: false
    },
    nameTextStyle: {
    color: color
    },
    axisTick: {
    show: false
    },
    axisLabel: {
    show: true,
    color: color
    },
    axisLine: {
    show: true,
    lineStyle: {
    color: color
    }
    }
    },
    series: [{
    name: '文章篇数',
    type: 'bar',
    data: ${tagArrJson},
    itemStyle: {
    borderRadius: [5, 5, 0, 0],
    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    offset: 0,
    color: 'rgba(128, 255, 165)'
    },
    {
    offset: 1,
    color: 'rgba(1, 191, 236)'
    }])
    },
    emphasis: {
    itemStyle: {
    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
    offset: 0,
    color: 'rgba(128, 255, 195)'
    },
    {
    offset: 1,
    color: 'rgba(1, 211, 255)'
    }])
    }
    },
    markLine: {
    data: [{
    name: '平均值',
    type: 'average',
    label: {
    color: color
    }
    }]
    }
    }]
    };
    tagsChart.setOption(tagsOption);
    window.addEventListener('resize', () => {
    tagsChart.resize();
    });
    tagsChart.on('click', 'series', (event) => {
    if(event.data.path) window.location.href = '/' + event.data.path;
    });
    </script>`
    }

    function categoriesChart(dataParent) {
    const categoryArr = []
    let categoryParentFlag = false
    hexo.locals.get('categories').map(function (category) {
    if (category.parent) categoryParentFlag = true
    categoryArr.push({
    name: category.name,
    value: category.length,
    path: category.path,
    id: category._id,
    parentId: category.parent || '0'
    })
    })
    categoryParentFlag = categoryParentFlag && dataParent === 'true'
    categoryArr.sort((a, b) => { return b.value - a.value })
    function translateListToTree(data, parent) {
    let tree = []
    let temp
    data.forEach((item, index) => {
    if (data[index].parentId == parent) {
    let obj = data[index];
    temp = translateListToTree(data, data[index].id);
    if (temp.length > 0) {
    obj.children = temp
    }
    if (tree.indexOf())
    tree.push(obj)
    }
    })
    return tree
    }
    const categoryNameJson = JSON.stringify(categoryArr.map(function (category) { return category.name }))
    const categoryArrJson = JSON.stringify(categoryArr)
    const categoryArrParentJson = JSON.stringify(translateListToTree(categoryArr, '0'))

    return `
    <script id="categoriesChart">
    var color = document.documentElement.getAttribute('data-theme') === 'light' ? '#4c4948' : 'rgba(255,255,255,0.7)'
    var categoriesChart = echarts.init(document.getElementById('categories-chart'), 'light');
    var categoryParentFlag = ${categoryParentFlag}
    var categoriesOption = {
    title: {
    text: '文章分类统计图',
    x: 'center',
    textStyle: {
    color: color
    }
    },
    legend: {
    top: 'bottom',
    data: ${categoryNameJson},
    textStyle: {
    color: color
    }
    },
    tooltip: {
    trigger: 'item'
    },
    series: []
    };
    categoriesOption.series.push(
    categoryParentFlag ?
    {
    nodeClick :false,
    name: '文章篇数',
    type: 'sunburst',
    radius: ['15%', '90%'],
    center: ['50%', '55%'],
    sort: 'desc',
    data: ${categoryArrParentJson},
    itemStyle: {
    borderColor: '#fff',
    borderWidth: 2,
    emphasis: {
    focus: 'ancestor',
    shadowBlur: 10,
    shadowOffsetX: 0,
    shadowColor: 'rgba(255, 255, 255, 0.5)'
    }
    }
    }
    :
    {
    name: '文章篇数',
    type: 'pie',
    radius: [30, 80],
    roseType: 'area',
    label: {
    color: color,
    formatter: '{b} : {c} ({d}%)'
    },
    data: ${categoryArrJson},
    itemStyle: {
    emphasis: {
    shadowBlur: 10,
    shadowOffsetX: 0,
    shadowColor: 'rgba(255, 255, 255, 0.5)'
    }
    }
    }
    )
    categoriesChart.setOption(categoriesOption);
    window.addEventListener('resize', () => {
    categoriesChart.resize();
    });
    categoriesChart.on('click', 'series', (event) => {
    if(event.data.path) window.location.href = '/' + event.data.path;
    });
    </script>`
    }
  5. 新建[BlogRoot]\themes\anzhiyu\layout\includes\custom\sun_moon.pug 夜间模式切换动画

    1
    2
    3
    4
    5
    6
    7
    8
    9
    svg(aria-hidden='true', style='position:absolute; overflow:hidden; width:0; height:0')
    symbol#icon-sun(viewBox='0 0 1024 1024')
    path(d='M960 512l-128 128v192h-192l-128 128-128-128H192v-192l-128-128 128-128V192h192l128-128 128 128h192v192z', fill='#FFD878', p-id='8420')
    path(d='M736 512a224 224 0 1 0-448 0 224 224 0 1 0 448 0z', fill='#FFE4A9', p-id='8421')
    path(d='M512 109.248L626.752 224H800v173.248L914.752 512 800 626.752V800h-173.248L512 914.752 397.248 800H224v-173.248L109.248 512 224 397.248V224h173.248L512 109.248M512 64l-128 128H192v192l-128 128 128 128v192h192l128 128 128-128h192v-192l128-128-128-128V192h-192l-128-128z', fill='#4D5152', p-id='8422')
    path(d='M512 320c105.888 0 192 86.112 192 192s-86.112 192-192 192-192-86.112-192-192 86.112-192 192-192m0-32a224 224 0 1 0 0 448 224 224 0 0 0 0-448z', fill='#4D5152', p-id='8423')
    symbol#icon-moon(viewBox='0 0 1024 1024')
    path(d='M611.370667 167.082667a445.013333 445.013333 0 0 1-38.4 161.834666 477.824 477.824 0 0 1-244.736 244.394667 445.141333 445.141333 0 0 1-161.109334 38.058667 85.077333 85.077333 0 0 0-65.066666 135.722666A462.08 462.08 0 1 0 747.093333 102.058667a85.077333 85.077333 0 0 0-135.722666 65.024z', fill='#FFB531', p-id='11345')
    path(d='M329.728 274.133333l35.157333-35.157333a21.333333 21.333333 0 1 0-30.165333-30.165333l-35.157333 35.157333-35.114667-35.157333a21.333333 21.333333 0 0 0-30.165333 30.165333l35.114666 35.157333-35.114666 35.157334a21.333333 21.333333 0 1 0 30.165333 30.165333l35.114667-35.157333 35.157333 35.157333a21.333333 21.333333 0 1 0 30.165333-30.165333z', fill='#030835', p-id='11346')
  6. 修改[BlogRoot]\themes\anzhiyu\layout\includes\head.pug 夜间模式切换动画,文件末尾添加

    1
    2
    //- 夜间模式切换动画
    include ./custom/sun_moon.pug
  7. 新建[BlogRoot]\themes\anzhiyu\source\css_layout\sun_moon.sty 夜间模式切换动画

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    .Cuteen_DarkSky,
    .Cuteen_DarkSky:before
    content ''
    position fixed
    left 0
    right 0
    top 0
    bottom 0
    z-index 88888888

    .Cuteen_DarkSky
    background linear-gradient(to top, #f8cd71 0, #5bfde9 80%)
    &:before
    transition 2s ease all
    opacity 0
    background linear-gradient(to top, #30cfd0 0, #330867 100%)

    .DarkMode
    .Cuteen_DarkSky
    &:before
    opacity 1

    .Cuteen_DarkPlanet
    z-index 99999999
    position fixed
    left -50%
    top -50%
    width 200%
    height 200%
    -webkit-animation CuteenPlanetMove 2s cubic-bezier(0.7, 0, 0, 1)
    animation CuteenPlanetMove 2s cubic-bezier(0.7, 0, 0, 1)
    transform-origin center bottom


    @-webkit-keyframes CuteenPlanetMove {
    0% {
    transform: rotate(0);
    }
    to {
    transform: rotate(360deg);
    }
    }
    @keyframes CuteenPlanetMove {
    0% {
    transform: rotate(0);
    }
    to {
    transform: rotate(360deg);
    }
    }
    .Cuteen_DarkPlanet
    #sun
    position absolute
    border-radius 100%
    left 44%
    top 30%
    height 6rem
    width 6rem
    background #ffee94
    box-shadow 0 0 40px #ffee94
    // opacity 0

    #moon
    position absolute
    border-radius 100%
    left 44%
    top 30%
    position absolute
    border-radius 100%
    height 6rem
    width 6rem
    box-shadow -1.8em 1.8em 0 0.2em #fff
    // opacity 1

    // &:after
    // position absolute
    // left 42%
    // top 30%
    // width 6rem
    // height 6rem
    // border-radius 50%
    // content ''
    // background #ffef9e
    // box-shadow 0 0 30px #ffef9e

    .search
    span
    display none

    .menus_item
    a
    text-decoration none!important
    //按钮相关,对侧栏按钮做过魔改的可以调整这里的数值
    // .icon-V
    // padding 5px
  8. 新建[BlogRoot]\themes\anzhiyu\source\js\sun_moon.js 夜间模式切换动画

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    function switchNightMode() {
    document.querySelector('body').insertAdjacentHTML('beforeend', '<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"><div id="sun"></div><div id="moon"></div></div></div>'),
    setTimeout(function () {
    document.querySelector('body').classList.contains('DarkMode') ? (document.querySelector('body').classList.remove('DarkMode'), localStorage.setItem('isDark', '0'), document.getElementById('modeicon').setAttribute('xlink:href', '#icon-moon')) : (document.querySelector('body').classList.add('DarkMode'), localStorage.setItem('isDark', '1'), document.getElementById('modeicon').setAttribute('xlink:href', '#icon-sun')),
    setTimeout(function () {
    document.getElementsByClassName('Cuteen_DarkSky')[0].style.transition = 'opacity 3s';
    document.getElementsByClassName('Cuteen_DarkSky')[0].style.opacity = '0';
    setTimeout(function () {
    document.getElementsByClassName('Cuteen_DarkSky')[0].remove();
    }, 1e3);
    }, 2e3)
    })
    const nowMode = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
    if (nowMode === 'light') {
    // 先设置太阳月亮透明度
    document.getElementById("sun").style.opacity = "1";
    document.getElementById("moon").style.opacity = "0";
    setTimeout(function () {
    document.getElementById("sun").style.opacity = "0";
    document.getElementById("moon").style.opacity = "1";
    }, 1000);

    activateDarkMode()
    saveToLocal.set('theme', 'dark', 2)
    // GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night)
    document.getElementById('modeicon').setAttribute('xlink:href', '#icon-sun')
    // 延时弹窗提醒
    setTimeout(() => {
    new Vue({
    data: function () {
    this.$notify({
    title: "关灯啦🌙",
    message: "当前已成功切换至夜间模式!",
    position: 'top-left',
    offset: 50,
    showClose: true,
    type: "success",
    duration: 5000
    });
    }
    })
    }, 2000)
    } else {
    // 先设置太阳月亮透明度
    document.getElementById("sun").style.opacity = "0";
    document.getElementById("moon").style.opacity = "1";
    setTimeout(function () {
    document.getElementById("sun").style.opacity = "1";
    document.getElementById("moon").style.opacity = "0";
    }, 1000);

    activateLightMode()
    saveToLocal.set('theme', 'light', 2)
    document.querySelector('body').classList.add('DarkMode'), document.getElementById('modeicon').setAttribute('xlink:href', '#icon-moon')
    setTimeout(() => {
    new Vue({
    data: function () {
    this.$notify({
    title: "开灯啦🌞",
    message: "当前已成功切换至白天模式!",
    position: 'top-left',
    offset: 50,
    showClose: true,
    type: "success",
    duration: 5000
    });
    }
    })
    }, 2000)
    }
    // handle some cases
    typeof utterancesTheme === 'function' && utterancesTheme()
    typeof FB === 'object' && window.loadFBComment()
    window.DISQUS && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200)
    }
  9. 修改\themes\anzhiyu\layout\includes\rightside.pug 右侧悬浮按钮,
    夜间模式切换:

    1
    2
    3
    4
    5
    when 'darkmode'
    if darkmode.enable && darkmode.button
    a.icon-V.hidden(onclick='switchNightMode()', title=_p('rightside.night_mode_title'))
    svg(width='25', height='25', viewBox='0 0 1024 1024')
    use#modeicon(xlink:href='#icon-moon')

    背景壁纸切换

    1
    2
    3
    when 'bg'
    button(type="button" title='切换背景' onclick="toggleWinbox()")
    i.fas.fa-display
  10. \themes\butterfly\layout\page.pug中添加如下代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    when 'tags'
    include includes/page/tags.pug
    when 'link'
    include includes/page/flink.pug
    when 'categories'
    include includes/page/categories.pug
    +when 'collect'
    + include includes/page/collect.pug
    default
    include includes/page/default-page.pug

    [blogRoot]\themes\butterfly\layout\includes\page下新建collect.pug文件并粘贴如下代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    #article-container
    .collect
    - let collectPageContent = page.content
    if site.data.collect
    - let result = ""
    each i in site.data.collect
    - let className = i.class_name ? `<h2 ${i.class_desc?'':'style="margin-bottom:12px"'}>${i.class_name} (${i.link_list.length})</h2>` : ""
    - let classDesc = i.class_desc ? `<div class="collect-desc">${i.class_desc}</div>` : ""
    - let listResult = ""
    each j in i.link_list
    -
    listResult += `
    <div title="${j.name}" referrerPolicy="no-referrer" class="collect_box" style="${j.img?`background-image: url(${j.img})`:'background-color: #333;'}">
    <div class="collect_top">
    <i class="${j.icon?j.icon:'fa-solid fa-film'}"></i>
    <span>${j.tip?j.tip:'电影'}</span>
    </div>
    <div class="collect_content">
    <span>${j.name?j.name:'未知'}</span>
    <div>${j.score?toStar(j.score):toStar(0)}</div>
    </div>
    </div>
    `
    -
    - result += `${className}${classDesc} <div class="collect-list">${listResult}</div>`
    - collectPageContent = collectPageContent + result
    != collectPageContent

    [blogRoot]\themes\butterfly\source\css\_page下新建collect.styl文件并粘贴如下代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    .collect
    h2
    margin-bottom: 0
    .collect-desc
    margin-bottom: 10px
    .collect-list
    display: flex
    gap: 18px
    flex-wrap: wrap
    .collect_box
    --w: calc(100% / 6 - 15px)
    width: var(--w)
    display: flex
    justify-content: space-between
    flex-direction: column
    background-position: center
    background-size: cover
    border-radius: 12px
    position: relative
    overflow: hidden
    padding: 10px
    color: #fff
    transition: .5s
    &::after
    content: ''
    position: absolute
    height: 100%
    width: 100%
    left: 0
    top: 0
    background: rgba(0,0,0,0.3)
    z-index: 0
    transition: .5s
    &:hover
    transform: translateY(-10px)
    &::after
    background: rgba(0,0,0,0.1)
    .collect_top
    display: flex
    z-index: 1
    align-items: center
    justify-content: space-between
    .collect_content
    z-index: 1
    margin-top: 86%
    span
    display: block
    font-size: 18px
    font-weight: bold
    white-space: nowrap
    overflow: hidden
    text-overflow: ellipsis

    [data-theme='dark']
    .collect .collect-list .collect_box
    color: #ddd !important
    &:hover
    transform: translateY(-10px)
    &::after
    background: rgba(0,0,0,0.2)
    &::after
    background: rgba(0,0,0,0.5)
    .collect .collect-list
    @media screen and (max-width: 1100px)
    gap: 15px
    .collect_box
    --w: calc(20% - 12px)
    @media screen and (max-width: 900px)
    gap: 16px
    .collect_box
    --w: calc(25% - 12px)
    @media screen and (max-width: 768px)
    gap: 15px
    .collect_box
    --w: calc(100% / 3 - 10px)
    @media screen and (max-width: 500px)
    gap: 16px
    .collect_box
    --w: calc(50% - 8px)

    [blogRoot]themes\butterfly\scripts\helpers\page.js的合适位置粘贴如下代码

    1
    2
    3
    4
    5
    6
    7
    8
    // 藏宝阁星星
    hexo.extend.helper.register('toStar', function(num) {
    let tmp = ''
    for (let i = 0; i < Math.floor(num); i++) { tmp += '<i class="fa-solid fa-star"></i>' } // 整数部分加 实心星星
    if (num - Math.floor(num) != 0) tmp += '<i class="fa-solid fa-star-half-alt"></i>' // 小数部分转成 半星
    for (let i = 0; i < 5 - Math.ceil(num); i++) { tmp += '<i class="fa-regular fa-star"></i>' } // 不够5个补 空心星星
    return tmp
    })