Lhcfl / hexo-theme-anatolo

Anatolo,始于轻简,甄于完美
MIT License
94 stars 9 forks source link

github action部署失败 #5

Closed MyBlueHorizon closed 1 year ago

MyBlueHorizon commented 1 year ago

安装主题后本地部署成功,但Github Action生成报错

ERROR 
TypeError: /home/runner/work/blog/blog/themes/Anatolo/layout/partial/nav.pug:3
    1| .page-top.animated.fadeInDown
    2|   .nav
  > 3|     each cur, lst in theme.menu
    4|       li 
    5|         if is_current(cur)
    6|           a.current(href= cur)= __(lst)

Cannot read properties of undefined (reading 'length')
    at eval (eval at wrap (/home/runner/work/blog/blog/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:304:32)
    at eval (eval at wrap (/home/runner/work/blog/blog/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:351:4)
    at template (eval at wrap (/home/runner/work/blog/blog/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:1414:7)
    at _View._compiled (/home/runner/work/blog/blog/node_modules/hexo/lib/theme/view.js:136:50)
    at _View.render (/home/runner/work/blog/blog/node_modules/hexo/lib/theme/view.js:39:17)
    at /home/runner/work/blog/blog/node_modules/hexo/lib/hexo/index.js:64:21
    at tryCatcher (/home/runner/work/blog/blog/node_modules/bluebird/js/release/util.js:16:23)
    at /home/runner/work/blog/blog/node_modules/bluebird/js/release/method.js:15:34
    at RouteStream._read (/home/runner/work/blog/blog/node_modules/hexo/lib/hexo/router.js:47:5)
    at Readable.read (node:internal/streams/readable:496:12)
    at resume_ (node:internal/streams/readable:999:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Workflow如下

name: Pages

on:
  push:
    branches:
      - main  # default branch

jobs:
  pages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          # If your repository depends on submodule, please see: https://github.com/actions/checkout
          submodules: recursive
      - name: Use Node.js 18.x
        uses: actions/setup-node@v3
        with:
          node-version: '18'
      - name: Cache NPM dependencies
        uses: actions/cache@v3
        with:
          path: node_modules
          key: ${{ runner.OS }}-npm-cache
          restore-keys: |
            ${{ runner.OS }}-npm-cache
      - name: Install Dependencies
        run: npm install
      - name: Build
        run: npm run build
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
Lhcfl commented 1 year ago

github actions方面我技术力尚且不足()如果你能改善好,欢迎pr

另外你是不是可以检查一下你的config.yml文件

MyBlueHorizon commented 1 year ago

尝试把config.yml除主题外重置为默认,但问题依旧。 尝试把github action的环境改为windows,但问题依旧。 尝试把nodejs的版本选择到小版本,但问题依旧。 尝试往package.json手动添加pug依赖,但问题依旧。

each cur, lst in theme.menu

感觉这行报错的也看不出什么问题... 目前依然觉得是相关依赖的问题,但没有头绪。 打算稍晚时间再研究一下问题所在

Lhcfl commented 1 year ago

尝试把config.yml除主题外重置为默认,但问题依旧。

你恢复的是主题内的config.yml吗?看看这一段?

# Nav menu
menu:
  Home: /
  Archives: /archives
  Tags: /tags
  About: /about
  Links: /links
MyBlueHorizon commented 1 year ago

发现问题了 一个配置文件被主题目录下的git配置忽略而没有被本地git成功推送到GitHub 不知道您愿不愿意把config.yml从git的忽略中移除,方便采用GitHub action部署的用户。 最后感谢您维护这么棒的主题。

Lhcfl commented 1 year ago

发现问题了 一个配置文件被主题目录下的git配置忽略而没有被本地git成功推送到GitHub 不知道您愿不愿意把config.yml从git的忽略中移除,方便采用GitHub action部署的用户

原来如此。 忽略它是防止用户更新Anatolo的时候config.yml被意外更新;那我觉得对于使用github action部署的用户,额外说明一下修改gitignore就行了,这样也方便拉取更新。

MyBlueHorizon commented 1 year ago

Hexo5.0+支持独立主题配置文件 _config.[theme].yml 感觉可以通过这一方式解决更新问题。