You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Hugo与blogdown无法创建新文章的技术求助

关于blogdown创建文章及站点构建的问题解决建议

一、核心问题表现

1. 新建文章失败报错

无论更换何种主题,使用blogdown新建文章时均触发如下错误:

Loading required package: shiny

Listening on http://127.0.0.1:4451
Warning in system2(...):
  running command '"C:/Users/<PATH_NAME>/Hugo/0.112.3/hugo.exe" new "post/2023-05-25-test/index.md" --themesDir themes -t hugo-lithium' had status 1
Warning: Error in new_content: Failed to create the file 'post/2023-05-25-test/index.Rmd'.
  9: shiny::runApp
  8: shiny::runGadget
  7: eval
  6: eval
  5: sys.source
  2: source_addin
  1: blogdown:::new_post_addin

2. 默认Lithium主题安装失败

尝试创建使用hugo-lithium主题的新站点时,出现文件读写权限类错误:

Creating your new site
| Installing the theme yihui/hugo-lithium from github.com
trying URL 'https://github.com/yihui/hugo-lithium/archive/HEAD.tar.gz'
Content type 'application/x-gzip' length unknown
downloaded 109 KB

Error in gsub_file(f, ...) : 
  Unable to read or write to 687c340e18f2/hugo-lithium-ac5574669ddd07feb1cb87fab1f5933a45e3f578/exampleSite/content/post/2015-01-01-lorem-ipsum/index.md

3. 站点构建异常

  • 执行blogdown::build_site(build_rmd = TRUE)时,除最新文章外,所有已存在的旧文章都会重新编译;
  • 执行blogdown::build_site(build_rmd='timestamp')时进程卡住,只能强制终止。

背景补充

有两个在blogdown v1.0版本更新前创建的旧博客,近期更新内容时触发问题。最初因partials文件缺失导致blogdown::serve_site()失败,手动从Lithium主题仓库复制partials后解决,但未明确问题根源。

二、会话信息

xfun::session_info('blogdown')
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621), RStudio 2023.3.1.446


Locale:
  LC_COLLATE=English_India.utf8  LC_CTYPE=English_India.utf8    LC_MONETARY=English_India.utf8
  LC_NUMERIC=C                   LC_TIME=English_India.utf8    

time zone: Europe/London
tzcode source: internal

Package version:
  base64enc_0.1.3   blogdown_1.17.2   bookdown_0.34     bslib_0.4.2       cachem_1.0.8      cli_3.6.1        
  digest_0.6.31     ellipsis_0.3.2    evaluate_0.21     fastmap_1.1.1     fontawesome_0.5.1 fs_1.6.2         
  glue_1.6.2        graphics_4.3.0    grDevices_4.3.0   highr_0.10        htmltools_0.5.5   httpuv_1.6.11    
  jquerylib_0.1.4   jsonlite_1.8.4    knitr_1.42        later_1.3.1       lifecycle_1.0.3   magrittr_2.0.3   
  memoise_2.0.1     methods_4.3.0     mime_0.12         promises_1.2.0.1  R6_2.5.1          rappdirs_0.3.3   
  Rcpp_1.0.10       rlang_1.1.1       rmarkdown_2.21    sass_0.4.6        servr_0.27        stats_4.3.0      
  stringi_1.7.12    stringr_1.5.0     tinytex_0.45      tools_4.3.0       utils_4.3.0       vctrs_0.6.2      
  xfun_0.39         yaml_2.3.7       

Hugo version: 0.112.3

三、解决建议

1. 排查权限问题

从报错信息看,文件读写失败是核心诱因,优先做以下检查:

  • 以管理员权限启动RStudio,规避Windows系统的权限限制;
  • 检查博客站点所在文件夹的权限,确保当前用户拥有完整读写权限(右键文件夹→属性→安全→编辑权限);
  • 临时关闭杀毒软件或防火墙,避免其拦截文件操作。

2. 调整Hugo版本适配

当前使用的Hugo 0.112.3版本较新,与旧博客的兼容性可能存在问题:

  • 尝试降级Hugo到0.100.x版本(blogdown v1.0推荐的稳定版本),测试是否解决新建文章和主题安装问题;
  • 运行blogdown::update_hugo(version = "0.100.2")可指定版本安装。

3. 更换新建文章方式

若RStudio插件新建失败,改用命令行方式创建:

blogdown::new_post(title = "测试文章", ext = ".Rmd")

指定ext参数确保生成Rmd文件,同时检查config.toml中contentDir等路径配置是否正确。

4. 修复旧博客兼容性

针对旧博客:

  • 运行blogdown::check_site()自动检测站点配置问题,根据提示逐一修复;
  • 重新初始化主题:删除旧的themes文件夹,运行blogdown::install_theme("yihui/hugo-lithium")重新安装,避免手动复制文件导致的路径或权限异常;
  • 清理缓存:删除站点根目录下的public和resources文件夹,再重新运行blogdown::serve_site()。

5. 优化构建参数

针对构建异常:

  • 检查所有Rmd文件的YAML元数据,确保lastmod或date字段设置正确,timestamp模式依赖这些时间戳判断是否重新编译;
  • 清理knitr缓存:删除每个Rmd文件对应的_cache文件夹,再运行build_site(build_rmd='timestamp');
  • 若仍卡住,尝试分批编译文章,排查是否有特定文章导致进程挂起。

内容的提问来源于stack exchange,提问作者starship9

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 21:45:48