abnerwei / hexo-url-submission

Quickly submit new post URLs to Google, Bing, and Baidu search engines to improve the quality and speed of website inclusion
MIT License
37 stars 6 forks source link

fix: use hexo-fs to read google key file instead of require #18

Closed yqs112358 closed 1 week ago

yqs112358 commented 1 week ago

目前如果通过环境变量传递GOOGLE_KEY,并且将配置文件中url_submission -> google->key配置项置空时,这里 https://github.com/abnerwei/hexo-url-submission/blob/49c4ca12038d86ccf481b8124559824960be403a/src/google_deployer.ts#L28require会抛出异常,导致永远输出Google key file not exist, cancel submission.,后面的JSON.parse(process.env.GOOGLE_KEY || '{}')不会被执行。 如图:

image

使用hexo-fs代替require读取google key,解决了此问题。 修复后:

image
828767 commented 2 hours ago
INFO  Validating config
ERROR Plugin load failed: hexo-url-submission
Error: EISDIR: illegal operation on a directory, read
INFO

yqs112358 大佬你改的这版本加载失败:

$ hexo version
INFO  Validating config
ERROR Plugin load failed: hexo-url-submission
Error: EISDIR: illegal operation on a directory, read
INFO  
  =====================[ Hexo Theme - Solitude ]=====================
       #####  ####  #     #####  ###### #     # ######   ######
      #      #    # #       #      #    #     # #      # #
       ##### #    # #       #      #    #     # #      # ######
           # #    # #       #      #    #     # #      # #
      ######  ####  ##### #####    #      ###   ######   ######
                            2.0.12
  ===================================================================
  GitHub: https://github.com/everfu/hexo-theme-solitude

hexo: 7.3.0
hexo-cli: 4.3.2
os: win32 10.0.22631 undefined
node: 20.12.0
acorn: 8.11.3
ada: 2.7.6
ares: 1.27.0
base64: 0.5.2
brotli: 1.1.0
cjs_module_lexer: 1.2.2
cldr: 44.1
icu: 74.2
llhttp: 8.1.1
modules: 115
napi: 9
nghttp2: 1.60.0
nghttp3: 0.7.0
ngtcp2: 0.8.1
openssl: 3.0.13+quic
simdutf: 4.0.8
tz: 2024a
undici: 5.28.3
unicode: 15.1
uv: 1.46.0
uvwasi: 0.0.20
v8: 11.3.244.8-node.19
zlib: 1.3.0.1-motley-40e35a7
yqs112358 commented 2 hours ago

奇怪了,我代码里特定判定过fs.statSync(keyPath).isFile()来着🤔 哥们是用key文件还是环境变量传递授权json的?能不能贴下相关配置看看 @828767

828767 commented 41 minutes ago

奇怪了,我代码里特定判定过fs.statSync(keyPath).isFile()来着🤔 哥们是用key文件还是环境变量传递授权json的?能不能贴下相关配置看看 @828767

用的原先的JSON文件,文档里没见要改的说明,请问用环境变量该怎么配?_config.yml里google:值留空?

url_submission:
  enable: true
  count: 10 # Submit limit
  urls_path: 'submit_url.txt' # URL list file path
  sitemap: 'sitemap.xml' # Sitemap path(e.g. the url is like this https://abnerwei.com/baidusitemap.xml, you can fill in `baidusitemap.xml`)
  type: 'latest' # latest or all( latest: modified pages; all: posts & pages)
  channels: # included channels are `baidu`, `google`, `bing`, `shenma`
    google: # https://cloud.tencent.com/developer/article/2387384
      key: "google.json" # Google key path 与站点 _config.yml同级(e.g. `google_key.json` or `data/google_key.json`):GOOGLE_KEY
      count: 10 # Optional
yqs112358 commented 5 minutes ago

@828767 对,用环境变量的话 channels->google->key 这个配置写空字符串就行 然后环境变量里面直接放授权json文本