Hugo博客搭建教程以及配置调优

正式开始 请全程在Windows上操作 我们首先需要安装Scoop,这是一个适用于Windows的包管理器,个人认为非常好用 Scoop默认会安装到C盘,如果你想要换盘请按需更改 $env:SCOOP='D:\Scoop' $env:SCOOP_GLOBAL='D:\ScoopApps' [Environment]::SetEnvironmentVariable('SCOOP', $env:SCOOP, 'User') [Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $env:SCOOP_GLOBAL, 'Machine') 安装Scoop: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression 如果你以管理员的身份会安装失败,请切换为普通用户。若想强制以管理员身份安装Scoop请使用 github原帖 出于安全考虑,默认情况下已禁用管理员控制台下的安装。如果您知道自己在做什么并希望以管理员身份安装Scoop,请下载安装程序并在提升的控制台中手动执行它,使用 -RunAsAdmin 参数。以下是示例: irm get.scoop.sh -outfile 'install.ps1' .\install.ps1 -RunAsAdmin [-OtherParameters ...] # 如果你想要一行解决: iex "& {$(irm get.scoop.sh)} -RunAsAdmin" 安装Hugo框架: scoop install hugo 然后选择一个你喜欢的文件夹创建你的站点。 myblog 即你的站点文件夹名称 hugo new site myblog cd myblog 安装PaperMod主题: git clone https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod 站点根目录会有一个 hugo.toml。我推荐使用YAML。将文件重命名为 hugo.yaml。粘贴并更改以下内容 baseURL: "https://站点url" title: "网站标题" LanguageCode: "zh-CN" theme: "PaperMod" # 启用首页个人简介展示 params: # 是否启用评论。你需要自己配置,或者直接引入Giscus等评论系统 comments: false # 是否显示代码复制按钮 ShowCodeCopyButtons: true # 是否显示面包屑导航 ShowBreadCrumbs: false # 是否显示阅读时间 ShowReadingTime: true # 是否显示分享按钮 ShowShareButtons: true # 分享按钮配置 # ShareButtons: ["linkedin", "twitter"] # 是否禁用主题切换按钮 disableThemeToggle: false assets: favicon: "/你的/网站图标.jpg" # 需要在static文件夹放置对应的图片 iconHeight: 35 # 首页信息配置 homeInfoParams: Title: "首页展示的标题" Content: > 首页展示的文本 # 设置网站头像和首页头像 profileMode: enabled: false # 设为 true 将完全替换 homeInfoParams # 网站头像设置 (显示在导航栏) label: text: "左上角显示的文本" icon: "/你的/左上角显示的图片.jpg" # 这将显示在导航栏标题旁边。需要在static文件夹放置对应的图片 iconHeight: 35 # 社交图标 (显示在简介下方) socialIcons: - name: bilibili url: "" - name: github url: "" - name: telegram url: "" # 可以添加更多社交图标 https://github.com/adityatelange/hugo-PaperMod/wiki/Icons # 顶部导航栏的快捷链接 menu: main: - identifier: categories name: 分类 url: /categories/ weight: 10 - identifier: tags name: 标签 url: /tags/ weight: 20 - identifier: archives name: 归档 url: /archives/ weight: 30 - identifier: search name: 搜索 url: /search/ weight: 40 # 可以添加更多导航链接。weight的值越高排序越靠后 # 如果要启用搜索功能,需要添加这个 outputs: home: - HTML - RSS - JSON # 必须,用于搜索功能 然后我们需要分别配置分类、标签、归档和搜索页 ...

March 11, 2025 · 4 min