跳过正文
  1. Docs/

使用hugo来搭建自己的博客

·1918 字·4 分钟· loading · loading · · ·
折腾日记 Hugo Blog
目录

前言
#

由于琐事越来越多,经常记不住事,由此搭建博客。

准备工作
#

  1. 安装(Git)

  2. 在微软商店安装PowerShell终端 Terminal

  3. 新建hugo文件夹将hugo放入hugo文件夹内

  4. 把hugo.exe添加到系统环境变量path中


正文
#

创建站点
#

假如我的网站名要设置为blog的话,打开terminal,转到对应盘符cd D:,输入hugo new site blog,会自动创建一个blog的文件夹,cd blog此时路径应该为D:\blog\,你已经完成了部署网站,下面该设置个themes主题了。将<site_name>设置为你想要的名称,该名称应该是英文。

hugo new site <site_name>

现在使用hugo server -D打开对应的http://localhost:1313应该为page not found。

主题
#

博主采用的是blowfish主题 你也可以在hugo官网或者GitHub上选择其他的主题。

以防万一

hugo new site blog创建网站

cd blog转至网站文件夹

git init

git submodule add -b main https://github.com/nunocoracao/blowfish.git themes/blowfish

通过上述命令你将安装好blowfish主题,你可能会出现代理问题无法下载github文件

代理
#

具体代理方法本文暂不提供,设置临时代理如下

cmd

set http_proxy=http://127.0.0.1:7899
set https_proxy=http://127.0.0.1:7899

powershell专用

$env:http_proxy="http://127.0.0.1:7899"
$env:https_proxy="http://127.0.0.1:7899"

进行配置主题
#

  1. 进入themes\blowfish把blowfish目录下的exampleSite内的文件全部复制到D:\blog\并把blog目录中的hugo.ymal删除。
.
├─ archetypes  
├─ assets
├─ config   
├─ content
├─ data
└─ layouts
  1. 输入命令hugo server -D运行站点,此时默认站点运行在`http://localhost:1313

自定义主题内容
#

网站图标(favicons)
#

  1. 找到一张图片也可以是自己的头像去favicon.io上传后下载压缩包

  2. 解压缩至blog\static目录下

    static/
    ├─ android-chrome-192x192.png
    ├─ android-chrome-512x512.png
    ├─ apple-touch-icon.png
    ├─ favicon-16x16.png
    ├─ favicon-32x32.png
    ├─ favicon.ico
    └─ site.webmanifest
    

头像
#

找到目录config\_default中的languages.zh-cn.toml

languageCode = "zh-cn"
languageName = "简体中文"
weight = 1
title = "la_ruiのblog"

[params]
  displayName = "简体中文"
  isoCode = "zh-cn"
  rtl = false
  dateFormat = "2006 年 1 月 2 日"
  logo = "img/logo.png"
  description = "la_ruiのblog"
  copyright = '© 2025 - { year } larui All Rights Reserved.'

[params.author]
  name = "la_rui"
  image = "img/larui.JPG"
  links = [
    { bilibili = "https://space.bilibili.com/37930808" },
    { steam = "https://steamcommunity.com/id/la_rui/" },    
    { github = "https://github.com/larui762" },
  ]

对应修改内容,为logo和image 设置图片,路径在assets\img,图片名称需对应,其格式可以是pngjpg其他格式未进行尝试。在[params.author]内的link可以设置社交账号,前面的bilibili会寻找assets\icons目录下的svg同名称格式文件bilibili.svg在这里可以找到各种svg格式文件svgrepo

网站配置
#

目录config\_default\hugo.toml

修改这一条defaultContentLanguage = “zh-cn”

其他配置可前往主题作者网站查看

详细配置

仪表盘(导航栏/页首/menu菜单)
#

# -- Main Menu --
# The main menu is displayed in the header at the top of the page.
# Acceptable parameters are name, pageRef, page, url, title, weight.
# 
# The simplest menu configuration is to provide:
#   name = The name to be displayed for this menu link
#   pageRef = The identifier of the page or section to link to
#
# By default the menu is ordered alphabetically. This can be
# overridden by providing a weight value. The menu will then be
# ordered by weight from lowest to highest.

[[main]]
  name = "文章"
  pageRef = "docs"
  weight = 10

[[main]]
  name = "我"
  pageRef = "me"
  weight = 18

#[[main]]
#  name = "示例"
#  weight = 20

#[[main]]
#  name = "功能示例"
#  parent = "示例"
#  pageRef = "samples"
#  weight = 16

#[[main]]
#  name = "模板示例"
#  parent = "示例"
#  pageRef = "examples"
#  weight = 30

#[[main]]
#  name = "部署指南"
#  parent = "示例"
#  pageRef = "guides"
#  weight = 40



[[main]]
  identifier = "github"
  pre = "github"
  url = "https://github.com/larui762"
  weight = 400


# -- Footer Menu --
# The footer menu is displayed at the bottom of the page, just before
# the copyright notice. Configure as per the main menu above.

 [[footer]]
   name = "标签"
   pageRef = "tags"
   weight = 10

name为名称,pageRef为路径larui\content下文件夹,weight为先后顺序,10<18所以文章前面,identifierpre名称需是assets\icons下同名称svg文件。footer则在页面左下角显示。

大概配置就这样吧
#

文章
#

hugo new docs/first.md

打开后可以看到

title: "使用hugo来搭建自己的博客"#修改
date: 2025-06-01T12:39:53+08:00#日期
draft: true#true为开启草稿
description: ""#描述 也不知道干嘛的
tags: ["折腾日记","hugo","blog"]#加tag

语法
#

# H1
## H2 该主题##可以在右侧显示导航栏
### H3
#### H4
##### H5
###### H6

参考文章
#

如何使用 Github Page 搭建自己的博客 · 瞳のBlog

bolowfish.page

如何在 Hugo 部落格首頁加上 TypeIt 打字效果 · Azurerain4u