打算换blog

使用hexo感觉有点麻烦,还要设置文章的图片,hexo搭建起来也比较费劲,尤其是ondejs 的安装也比较大,于是我换成了hugo,这是一个用go写的,部署起来很快,但是并不简单,这里面有很多坑!🤕

图片文件

之前我的所有md文件的图片都是保存到$filename这个目录,也就是md文件名生成一个同名目录,然后放入图片,typora和marktext都有这个功能;但是hugo生成的静态文件,也是把md文件名生成一个同名目录,就导致了之前的图片全部不能找到,md文件的引用到图片的地方,全部都得重写,不过还好。我使用obsidian写博客,虽然obsidian没有自带的功能,让图片文件放入md变量的目录,但是有插件(Custom Attachment Location),现在我的图片路径是./asstes/$filename,之前 obsidian那个插件的设置也要去查看文档,有点麻烦。

# 附件位置
./assets/${noteFileName}

# 附件命名
${originalAttachmentFileName}

# markdown url
./assets/${noteFileName}/${originalAttachmentFileName}.${originalAttachmentFileExtension}

hugo的图片文件,只能一个一个去改。改了之后还有坑,它不支持图片的相对路径,在网上找了解决方案,就是在yaml配置文件里面加一个参数就好了。

然后就是hugo本身的问题

我是选了一个名字叫PaperMod的主题,主要就是hugo.toml这个文件的配置,生成博客之后,这个文件是空的,但是这个文件里面其实有很多需要自己配置的,否则博客有很多问题,这里我参考了主题给的demo yaml,另外在网上找了几个参数解决如下几个问题:

  • markdown的图片不支持相对路径
  • 博客的md不能软链接
baseURL: "https://tang895.github.io"
title: TangYijun's Blog
# paginate: 5
theme: papermod

enableRobotsTXT: true
buildDrafts: false
buildFuture: false
buildExpired: false
# canonifyURLs: false
cleanDestinationDir: true  # 清理构建目录

uglyURLs: true  # markdown图片可以相对路径
minify:
  disableXML: true
  minifyOutput: true
# security:
#   # followSymlinks: true  # 软链接
#   exec:
#     allow:
#       - '.*'
#   filesystem:
#     allow:
#       - '/**'

pagination:
  pagerSize: 5

module:
  mounts:
    source: "/Users/ian-macbook/ian-macbook-home/blog_raw/_posts/"
    target: "content/posts"

params:
  env: production # to enable google analytics, opengraph, twitter-cards and schema.
  title: TangYijun's Blog
  description: "ExampleSite description"
  keywords: [Blog, Portfolio, PaperMod]
  author: Me
  # author: ["Me", "You"] # multiple authors
  images: ["<link or path of image for opengraph, twitter-cards>"]
  DateFormat: "January 2, 2006"
  defaultTheme: auto # dark, light
  disableThemeToggle: false

  ShowReadingTime: true
  ShowShareButtons: true
  ShowPostNavLinks: true
  ShowBreadCrumbs: true
  ShowCodeCopyButtons: false
  ShowWordCount: true
  ShowRssButtonInSectionTermList: true
  UseHugoToc: true
  disableSpecial1stPost: false
  disableScrollToTop: false
  comments: false
  hidemeta: false
  hideSummary: false
  showtoc: false
  tocopen: false

  assets:
    # disableHLJS: true # to disable highlight.js
    # disableFingerprinting: true
    favicon: "<link / abs url>"
    favicon16x16: "<link / abs url>"
    favicon32x32: "<link / abs url>"
    apple_touch_icon: "<link / abs url>"
    safari_pinned_tab: "<link / abs url>"

  label:
    text: "Home"
    icon: /apple-touch-icon.png
    iconHeight: 35

  # profile-mode
  profileMode:
    enabled: false # needs to be explicitly set
    title: ExampleSite
    subtitle: "This is subtitle"
    imageUrl: "<img location>"
    imageWidth: 120
    imageHeight: 120
    imageTitle: my image
    buttons:
      - name: Posts
        url: posts
      - name: Tags
        url: tags

  # home-info mode
  homeInfoParams:
    Title: "Hi there \U0001F44B"
    Content: Welcome to my blog

  socialIcons:
    - name: x
      url: "https://x.com/"
    - name: stackoverflow
      url: "https://stackoverflow.com"
    - name: github
      url: "https://github.com/tang895"

  # analytics:
  #   google:
  #     SiteVerificationTag: "XYZabc"
  #   bing:
  #     SiteVerificationTag: "XYZabc"
  #   yandex:
  #     SiteVerificationTag: "XYZabc"

  cover:
    hidden: true # hide everywhere but not in structured data
    hiddenInList: true # hide on list pages and home
    hiddenInSingle: true # hide on single page

  editPost:
    URL: "https://github.com/<path_to_repo>/content"
    Text: "Suggest Changes" # edit text
    appendFilePath: true # to append file path to Edit link

  # for search
  # https://fusejs.io/api/options.html
  fuseOpts:
    isCaseSensitive: false
    shouldSort: true
    location: 0
    distance: 1000
    threshold: 0.4
    minMatchCharLength: 0
    limit: 10 # refer: https://www.fusejs.io/api/methods.html#search
    keys: ["title", "permalink", "summary", "content"]
menu:
  main:
    - identifier: categories
      name: categories
      url: /categories/
      weight: 10
    - identifier: tags
      name: tags
      url: /tags/
      weight: 20
    - identifier: example
      name: example.org
      url: https://example.org
      weight: 30
# Read: https://github.com/adityatelange/hugo-PaperMod/wiki/FAQs#using-hugos-syntax-highlighter-chroma
pygmentsUseClasses: true
markup:
  highlight:
    noClasses: false
    # anchorLineNos: true
    # codeFences: true
    # guessSyntax: true
    # lineNos: true
    # style: monokai