今天,花时间整理了一下个人网站,主要做了下面这些工作:

  1. 选择了一个主题 hugo-prose。选择这个主题的原因是它足够简单,体积小,而且拥有不少需要的功能。如导航条、网站地图、目录、卡片、版权、引文等。
  2. 整理了之前的老文章。删掉了一些完全没有营养的帖子。大多数予以保留,并添加了 slug 标签,调整目录结构。写了一个脚本完成这项工作。
# find all files
files = list.files(path = "content/post/", pattern = stringr::regex("*.(md|rmd)", ignore.case = TRUE), full.names = TRUE)
lapply(files, function(file){
  # retrieve slug from filename
  filename = basename(file)
  ext = xfun::file_ext(file)
  basename = gsub(paste0(".", ext), "", filename)
  slug = gsub("[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}-", "", basename)

  # add tags to those posts
  header = blogdown:::split_yaml_body(xfun::read_utf8(file))[['yaml_list']]
  header$file = file
  if (is.null(header[['slug']])) header$slug = slug
  if (is.null(header[["author"]])) header$author = "gaoch"
  if (header$date < "2008-11-25"){
    header$categories = c("旧文","百度空间")
  } else if (header$date < "2018-10-17"){
    header$categories = c("旧文","WordPress博客")
  } 
  
  do.call(blogdown:::modify_yaml, header)
  
  # move post to new place
  path = paste0("content/post/", basename)
  dir.create(path)
  success = file.copy(from = file,
            to = paste(path, paste0("index.zh.", ext), sep = "/"))
  if(success){
    file.remove(file)
  }
})

作者简介

Chun-Hui Gao is a Research Associate at Huazhong Agricultural University.

重复使用

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The source code is licensed under MIT. The full source is available at https://github.com/yihui/hugo-prose.

欢迎修订

如果您发现本文里含有任何错误(包括错别字和标点符号),欢迎在本站的 GitHub 项目里提交修订意见。

引用本文

如果您使用了本文的内容,请按照以下方式引用:

gaoch (2023). 整理老文章. BIO-SPRING. /post/2023/08/08/tidy-old-blog-post/

BibTeX citation

@misc{
  title = "整理老文章",
  author = "gaoch",
  year = "2023",
  journal = "BIO-SPRING",
  note = "/post/2023/08/08/tidy-old-blog-post/"
}