theme-shoka-x / hexo-theme-shokaX

a hexo theme based on shoka
https://docs-hexo.shokax.top
GNU Affero General Public License v3.0
288 stars 35 forks source link

Fails to generate static html #22

Closed duchenpaul closed 1 year ago

duchenpaul commented 1 year ago

问题发生位置

Hexo渲染报错

问题描述

Error occurs when using hexo algolia and hexo generate to generate static html pages, here is the error.

Node.js v19.3.0
INFO  Validating config
INFO  Start processing
INFO  minify the js: unknown.js [ 49.26% saved]
INFO  Files loaded in 6.01 s
ERROR 
TypeError: /src/themes/shokaX/layout/_mixin/sidebar.pug:23
    21|                             != related
    22|                 div(class="overview panel" data-title=__('sidebar.overview'))
  > 23|                     != partial('_partials/sidebar/overview.pug', {}, {cache: true})
    24|         ul(id="quick")
    25|             li(class="prev pjax")
    26|                 if page && page.prev

/src/themes/shokaX/layout/_partials/sidebar/overview.pug:33
    31| 
    32| div(class="social")
  > 33|     each link, name  in theme.social
    34|         - var sidebarURL = link.split('||')[0].trim()
    35|         - var sidebarIcon = '<i class="ic i-' + link.split('||')[1].trim() + '"></i>'
    36|         != _url(sidebarURL, sidebarIcon, {title: sidebarURL, class: 'item ' + name})

Cannot read properties of null (reading 'length')
    at eval (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:73:32)
    at eval (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:96:4)
    at template (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:105:7)
    at _View._compiledSync (/src/node_modules/hexo/lib/theme/view.js:132:24)
    at _View.renderSync (/src/node_modules/hexo/lib/theme/view.js:59:25)
    at /src/node_modules/hexo/lib/plugins/helper/partial.js:31:52
    at Cache.apply (/src/node_modules/hexo-util/lib/cache.js:27:46)
    at Object.fragmentCache (/src/node_modules/hexo/lib/plugins/helper/fragment_cache.js:11:34)
    at Object.partial (/src/node_modules/hexo/lib/plugins/helper/partial.js:31:17)
    at Object.pug_interp [as sidebarRender] (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:597:46)
    at eval (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:895:28)
    at template (eval at wrap (/src/node_modules/pug-runtime/wrap.js:6:10), <anonymous>:1114:7)
    at _View._compiled (/src/node_modules/hexo/lib/theme/view.js:136:50)
    at _View.render (/src/node_modules/hexo/lib/theme/view.js:39:17)
    at /src/node_modules/hexo/lib/hexo/index.js:64:21
    at tryCatcher (/src/node_modules/bluebird/js/release/util.js:16:23)
    at /src/node_modules/bluebird/js/release/method.js:15:34
    at RouteStream._read (/src/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)
ERROR 
...

复现步骤

This is the script I used to install dependencies and generate webpages:

cd /src
npm config set registry http://mirrors.cloud.tencent.com/npm/

npm install
npm un hexo-renderer-marked --save

echo Install npm package hexo-cli
npm list hexo-cli || npm install hexo-cli
echo Install npm package hexo-server
npm list hexo-server || npm install hexo-server
echo Install npm package hexo-asset-image
npm list hexo-asset-image || npm install hexo-asset-image
echo Install npm package hexo-wordcount
npm list hexo-wordcount || npm install hexo-wordcount
echo Install npm package hexo-generator-sitemap
npm list hexo-generator-sitemap || npm install hexo-generator-sitemap
echo Install npm package hexo-generator-baidu-sitemap
npm list hexo-generator-baidu-sitemap || npm install hexo-generator-baidu-sitemap
echo Install npm package hexo-deployer-git
npm list hexo-deployer-git || npm install hexo-deployer-git
echo Install npm package hexo-renderer-multi-next-markdown-it
npm list hexo-renderer-multi-next-markdown-it || npm install hexo-renderer-multi-next-markdown-it
echo Install npm package hexo-autoprefixer
npm list hexo-autoprefixer || npm install hexo-autoprefixer
echo Install npm package hexo-algoliasearch
npm list hexo-algoliasearch || npm install hexo-algoliasearch
echo Install npm package hexo-feed
npm list hexo-feed || npm install hexo-feed
echo Install npm package shokax-cli --location=global
npm list shokax-cli --location=global || npm install shokax-cli --location=global

# shokax
SXC install shokaX

hexo algolia
hexo generate

相关配置

Versions:

bash-5.1# node --version
v19.3.0
bash-5.1# hexo --version
INFO  Validating config
hexo: 6.3.0
hexo-cli: 4.3.0
os: linux 5.10.0-20-amd64 Alpine Linux
node: 19.3.0
v8: 10.8.168.21-node.8
uv: 1.44.2
zlib: 1.2.13
brotli: 1.0.9
ares: 1.18.1
modules: 111
nghttp2: 1.51.0
napi: 8
llhttp: 8.1.0
uvwasi: 0.0.13
openssl: 3.0.7+quic
cldr: 42.0
icu: 72.1
tz: 2022f
unicode: 15.0
ngtcp2: 0.8.1
nghttp3: 0.7.0
bash-5.1# 

_config.shokaX.yml.j2

# Alternate site name
alternate: Chenny's blog

open_graph:
  #twitter_id:
  #google_plus:
  #fb_admins:
  #fb_app_id:

# Assets
statics: / #//cdn.jsdelivr.net/gh/username/RepositoryName@latest/
css: css
js: js
images: images

# themes/shoka/source/images/***
favicon:
  apple_touch_icon: /apple-touch-icon.png
  #safari_pinned_tab: /logo.svg
  #android_manifest: /manifest.json
  #ms_browserconfig: /browserconfig.xml

# Dark Mode
# By default, the page judges whether to turn on the dark mode according to the device settings or user selection
# if `true`, the page will be displayed directly as Dark Mode, unless the user makes another choice
darkmode: true

# By default the page will automatically scroll to the last viewed position
# if `false`, automatic positioning will be turned off
auto_scroll: true

# Whether to show the loading cat
loader:
  start: true # When entering the page
  switch: false # When switching to another page

# click with Firework
fireworks:
  enable: true
  color:
    # - "rgba(255,182,185,.9)"
    # - "rgba(250,227,217,.9)"
    # - "rgba(187,222,214,.9)"
    # - "rgba(138,198,209,.9)"

font:
  enable: true
  # Font options:
  # `external: true` will load this font family from `host` above.
  # `family: Times New Roman`. Without any quotes.
  # `size: x.x`. Use `em` as unit. Default: 1 (16px)

  # Global font settings used for all elements inside <body>.
  global:
    external: true
    family: Mulish
    size:

  # Font settings for alternate title.
  logo:
    external: true
    family: Fredericka the Great
    size: 3.5

  # Font settings for site title.
  title:
    external: true
    family: Noto Serif JP
    size: 2.5

  # Font settings for headlines (<h1> to <h6>).
  headings:
    external: true
    family: Noto Serif SC
    size:

  # Font settings for posts.
  posts:
    external: true
    family:

  # Font settings for <code> and code blocks.
  codes:
    external: true
    family: Inconsolata

# project of https://www.iconfont.cn/
# //at.alicdn.com/t/font_1832207_c8i9n1ulxlt.css => 1832207_c8i9n1ulxlt
iconfont: "1832207_igi8uaupcus"

menu:
  home: / || home
  # about: /about/ || user
  posts:
    default: / || feather
    archives: /archives/ || list-alt
    categories: /categories/ || th
    tags: /tags/ || tags
  # friends: /friends/ || heart
  # links: /links/ || magic

# Social Links
# Usage: `Key: permalink || icon || color`
# Key is the link label showing to end users.
# Value before `||` delimiter is the target permalink,
# secend value is the name of Font icon.
social:
  #github: https://github.com/yourname || github || "#191717"
  #google: https://plus.google.com/yourname || google
  #twitter: https://twitter.com/yourname || twitter || "#00aff0"
  #zhihu: https://www.zhihu.com/people/yourname || zhihu || "#1e88e5"
  #music: https://music.163.com/#/user/home?id=yourid || cloud-music || "#e60026"
  #weibo: https://weibo.com/yourname || weibo || "#ea716e"
  #about: https://about.me/yourname || address-card || "#3b5998"
  #email: mailto:yourname@mail.com || envelope || "#55acd5"
  #facebook: https://www.facebook.com/yourname || facebook
  #stackoverflow: https://stackoverflow.com/yourname || stack-overflow
  #youtube: https://youtube.com/yourname || youtube
  #instagram: https://instagram.com/yourname || instagram
  #skype: skype:yourname?call|chat || skype
  #douban: https://www.douban.com/people/yourname/ || douban

sidebar:
  # Sidebar Position.
  position: right
  # Replace the default avatar image and set the url here.
  avatar: avatar.jpg

widgets:
  # if true, will show random posts
  random_posts: true
  # if true, will show recent comments
  recent_comments: true

footer:
  # Specify the date when the site was setup. If not defined, current year will be used.
  since: 2010
  icon:
    name: sakura rotate
    # Change the color of icon, using Hex Code.
    color: "#ffc0cb"
  # Dependencies: https://github.com/theme-next/hexo-symbols-count-time
  count: true
  powered: true

post:
  # Dependencies: https://github.com/theme-next/hexo-symbols-count-time
  count: true

# Reward (Donate)
reward:
  # If true, reward will be displayed in every article by default.
  enable: false
  account:
    wechatpay: /wechatpay.png
    alipay: /alipay.png
    paypal: /paypal.png

# TagCloud settings for tags page.
tagcloud:
  # All values below are same as default, change them by yourself.
  min: 16 # Minimun font size in px
  max: 22 # Maxium font size in px
  start: "#72cecf" # Start color (hex, rgba, hsla or color keywords)
  end: "#ffbac3" # End color (hex, rgba, hsla or color keywords)
  amount: 200 # Amount of tags, change it if you have more than 200 tags

# ---------------------------------------------------------------
# Third Party Plugins & Services Settings
# ---------------------------------------------------------------

# Creative Commons 4.0 International License.
# See: https://creativecommons.org/share-your-work/licensing-types-examples
# Available values of license: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org
creative_commons:
  license: by-nc-sa
  language: deed.zh

# Comments
# Valine
# For more information: https://github.com/amehime/MiniValine
valine:
  appId: #Your_appId
  appKey: #Your_appkey
  placeholder: ヽ(○´∀`)ノ♪ # Comment box placeholder
  avatar: mp # Gravatar style : mp, identicon, monsterid, wavatar, robohash, retro
  pageSize: 10 # Pagination size
  lang: en
  visitor: true # Article reading statistic
  NoRecordIP: false # Whether to record the commenter IP
  serverURLs: # When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)
  powerMode: true
  tagMeta:
    visitor: 新朋友
    master: 主人
    friend: 小伙伴
    investor: 金主粑粑
  tagColor:
    master: "var(--color-orange)"
    friend: "var(--color-aqua)"
    investor: "var(--color-pink)"
  tagMember:
    master:
      # - hash of master@email.com
      # - hash of master2@email.com
    friend:
      # - hash of friend@email.com
      # - hash of friend2@email.com
    investor:
      # - hash of investor1@email.com

# bgm
audio:
  - title: Fav
    list:
      - https://music.163.com/#/song?id=1931517046 # 再见二丁目
      # - http://music.163.com/song/media/outer/url?id=258684
      - https://music.163.com/#/song?id=258684
      - https://music.163.com/#/song?id=5138277
      - https://music.163.com/#/song?id=34200332
      - https://music.163.com/#/song?id=94663
  - title: Patriot
    list:
      - https://music.163.com/#/playlist?id=7842528162
  - title: World order
    list:
      - https://music.163.com/#/playlist?id=7999951136

# random image api
image_server:  # http://repo.homes:80/artifactory/generic/pictures

# Algolia Search
# For more information: https://www.algolia.com
search:
  hits:
    per_page: 10

# Dependencies: https://github.com/amehime/hexo-renderer-multi-markdown-it
pangu: false

# Quicklink Support
# For more information: https://github.com/GoogleChromeLabs/quicklink
quicklink:
  # Custom a time in milliseconds by which the browser must execute prefetching.
  timeout: 3000
  # Default (true) will attempt to use the fetch() API if supported (rather than link[rel=prefetch]).
  priority: true

  # For more flexibility you can add some patterns (RegExp, Function, or Array) to ignores.
  # See: https://github.com/GoogleChromeLabs/quicklink#custom-ignore-patterns
  ignores:

# ---------------------------------------------------------------
# analytics & SEO Settings
# ---------------------------------------------------------------
baidu_analytics: # <app_id>

# Disable Baidu transformation on mobile devices.
disable_baidu_transformation: true

# Automatically add external URL with Base64 encrypt & decrypt.
exturl: true

# Google Webmaster tools verification.
# See: https://www.google.com/webmasters
google_site_verification:

# Bing Webmaster tools verification.
# See: https://www.bing.com/webmaster
bing_site_verification:

# Yandex Webmaster tools verification.
# See: https://webmaster.yandex.ru
yandex_site_verification:

# Baidu Webmaster tools verification.
# See: https://ziyuan.baidu.com/site
baidu_site_verification:

# Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO.
baidu_push: false

#! ---------------------------------------------------------------
#! DO NOT EDIT THE FOLLOWING `vendors` SETTINGS
#! UNLESS YOU KNOW WHAT YOU ARE DOING
#! Script dependencies will be combined with jsDelivr (cdn.jsdelivr.net)
#! ---------------------------------------------------------------
vendors:
  css:
    katex: npm/katex@0.12.0/dist/katex.min.css
    comment: css/comment.css
    fancybox: combine/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css,npm/justifiedGallery@3.8.1/dist/css/justifiedGallery.min.css
  js:
    pace: npm/pace-js@1.0.2/pace.min.js
    pjax: npm/pjax@0.2.8/pjax.min.js
    fetch: npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js
    anime: npm/animejs@3.2.0/lib/anime.min.js
    algolia: npm/algoliasearch@4/dist/algoliasearch-lite.umd.js
    instantsearch: npm/instantsearch.js@4/dist/instantsearch.production.min.js
    lazyload: npm/lozad@1/dist/lozad.min.js
    quicklink: npm/quicklink@2/dist/quicklink.umd.js
    fancybox: combine/npm/jquery@3.5.1/dist/jquery.min.js,npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js,npm/justifiedGallery@3.8.1/dist/js/jquery.justifiedGallery.min.js
    valine: gh/amehime/MiniValine@4.2.2-beta10/dist/MiniValine.min.js
    copy_tex: npm/katex@0.12.0/dist/contrib/copy-tex.min.js
    chart: npm/frappe-charts@1.5.0/dist/frappe-charts.min.iife.min.js

_config.yml

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: ''
subtitle: ''
description: ''
keywords:
author: {{ hexo_theme_config['author'] }}
language: en
timezone: '{{ timezone }}'

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://example.com
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
  trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
  trailing_html: true # Set to false to remove trailing '.html' from permalinks

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link:
  enable: true # Open external links in new tab
  field: site # Apply to the whole site
  exclude: ''
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: false
  line_number: true
  auto_detect: false
  tab_replace: ''
  wrap: true
  # hljs: false
prismjs:
  enable: false
  preprocess: true
  line_number: true
  tab_replace: ''

# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: shokaX

# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
  type: ''

markdown:
  render: # 渲染器设置
    html: false # 过滤 HTML 标签
    xhtmlOut: true # 使用 '/' 来闭合单标签 (比如 <br />)。
    breaks: true # 转换段落里的 '\n' 到 <br>。
    linkify: true # 将类似 URL 的文本自动转换为链接。
    typographer: 
    quotes: '“”‘’'
  plugins: # markdown-it 插件设置
    - plugin:
        name: markdown-it-toc-and-anchor
        enable: true
        options: # 文章目录以及锚点应用的 class 名称, shoka 主题必须设置成这样
          tocClassName: 'toc'
          anchorClassName: 'anchor'
    - plugin:
        name: markdown-it-multimd-table
        enable: true
        options:
          multiline: true
          rowspan: true
          headerless: true
    - plugin:
        name: ./markdown-it-furigana
        enable: true
        options:
          fallbackParens: "()"
    - plugin:
        name: ./markdown-it-spoiler
        enable: true
        options:
          title: "你知道得太多了"

minify:
  html:
    enable: true
    exclude: # 排除 hexo-feed 用到的模板文件
      - '**/json.ejs'
      - '**/atom.ejs'
      - '**/rss.ejs'
  css:
    enable: true
    exclude:
      - '**/*.min.css'
  js:
    enable: true
    mangle:
      toplevel: true
    output:
    compress:
    exclude:
      - '**/*.min.js'

autoprefixer:
  exclude:
    - '*.min.css'

algolia:
  appId: "{{ hexo_theme_config['algolia_appId'] }}"
  apiKey: "{{ hexo_theme_config['algolia_apiKey'] }}"
  adminApiKey: "{{ hexo_theme_config['algolia_adminApiKey'] }}"
  chunkSize: 5000
  indexName: "hexo-shoka"
  fields:
    - title
    - path
    - categories
    - content:strip:truncate,0,2000
    - gallery
    - photos
    - tags

注意事项

zkz098 commented 1 year ago

受限于PUG本身的迭代问题,您需要至少在social中启用一项

zkz098 commented 1 year ago

此外,shokaX的配置与shoka有较大不同,建议您参考仓库下的_config.yml进行配置而非直接使用shoka的配置

duchenpaul commented 1 year ago

受限于PUG本身的迭代问题,您需要至少在social中启用一项

Confirmed that is the issue, you have to add at least one item in "social" section.