Blog源文件GitHub

使用github上传自己的blog源文件

新环境

  • 要在新环境继续在原有仓库基础上撸文章,此时通过git clone将博客源码拉到本地,然后安装、初始化hexo就能搞定:
1
2
3
4
5
6
git clone ...
npm install hexo
npm install hexo-deployer-git -save

// hexo环境配置好后,继续像之前一样
hexo new post_name
  • hexo algolia命令需要设置HEXO_ALGOLIA_INDEXING_KEY`

    git bash 命令上执行:

    1
    2
    3
    export HEXO_ALGOLIA_INDEXING_KEY=""

    ./node_modules/.bin/hexo algolia
  • 配置pwa(我也不知道为啥会掉)

    [Blogroot]\themes\butterfly\layout\includes\third-party\目录下新建pwanotice.pug文件,打开[Blogroot]\themes\butterfly\layout\includes\third-party\pwanotice.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
    39
    40
    41
    42
    43
    #app-refresh.app-refresh(style='position: fixed;top: -2.2rem;left: 0;right: 0;z-index: 99999;padding: 0 1rem;font-size: 15px;height: 2.2rem;transition: all 0.3s ease;')
    .app-refresh-wrap(style=' display: flex;color: #fff;height: 100%;align-items: center;justify-content: center;')
    label ✨ 有新文章啦! 👉
    a(href='javascript:void(0)' onclick='location.reload()')
    span(style='color: #fff;text-decoration: underline;cursor: pointer;') 🍗点击食用🍔
    script.
    if ('serviceWorker' in navigator) {
    if (navigator.serviceWorker.controller) {
    navigator.serviceWorker.addEventListener('controllerchange', function() {
    showNotification()
    })
    }
    window.addEventListener('load', function() {
    navigator.serviceWorker.register('/sw.js')
    })
    }
    function showNotification() {
    if (GLOBAL_CONFIG.Snackbar) {
    var snackbarBg =
    document.documentElement.getAttribute('data-theme') === 'light' ?
    GLOBAL_CONFIG.Snackbar.bgLight :
    GLOBAL_CONFIG.Snackbar.bgDark
    var snackbarPos = GLOBAL_CONFIG.Snackbar.position
    Snackbar.show({
    text: '✨ 有新文章啦! 👉',
    backgroundColor: snackbarBg,
    duration: 500000,
    pos: snackbarPos,
    actionText: '🍗点击食用🍔',
    actionTextColor: '#fff',
    onActionClick: function(e) {
    location.reload()
    },
    })
    } else {
    var showBg =
    document.documentElement.getAttribute('data-theme') === 'light' ?
    '#3b70fc' :
    '#1f1f1f'
    var cssText = `top: 0; background: ${showBg};`
    document.getElementById('app-refresh').style.cssText = cssText
    }
    }

    修改[Blogroot]\themes\butterfly\layout\includes\additional-js.pug,在文件底部添加以下内容,注意缩进。butterfly_v3.6.0取消了缓存配置,转为完全默认,需要将{cache:theme.fragment_cache}改为{cache: true}:

    • 这里直接加就行
    1
    2
    if theme.pwa.enable
    !=partial('includes/third-party/pwanotice', {}, {cache: true})

    一直pwa推送,很烦人,不用了

之后就可以了。(仅供个人使用)