Hugo+manpassant搭建博客
前言
搭建步骤
- 以管理员的身份打开cmd
# choco 包管理器
powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
# 设置环境变量
SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
# 安装hugo
choco install hugo -confirm
# 验证是否安装成功
hugo version
# 例如我们在D盘打开cmd,使用hugo创建一个文件夹hugo作为本地博客目录
hugo new site hugo
# gitbash进入到本地博客文件夹根目录,将hugo主题克隆到themes文件夹
cd <YOUR Bolg Root Dir>
git clone https://github.com/flysnow-org/maupassant-hugo themes/maupassant
# 克隆后,themes目录中就有了一个主题,复制config.toml到博客根目录
# cmd进入本地博客根目录,启动本地服务,浏览器访问http://localhost:1313/
hugo server
- 新建一篇文章
hugo new post/filename.md # D:\hugo\content\post目录下会生成一篇文章
# 新生成的文章中开头有一个属性,需改为false,否则本地启动服务后不会显示;或者使用hugo server -D启动
draft: true # 表示文章是否草稿,草稿内容不会被发布
# 以后每次生成文章,可使用如下方式配置属性
---
title: "Hugo+manpassant搭建博客"
author: "作者" # 文章作者
description : "描述信息" # 文章描述信息
date: 2021-12-04T10:57:09+08:00
lastmod: 2021-12-05 # 文章修改日期
draft: false
tags: # 标签
- Hugo
- Markdown
categories: # 分类
- 博客搭建
keywords: # 关键字
- Hugo
next: /chnq/github-pages-blog # 下一篇博客地址
prev: /chnq/automated-deployments # 上一篇博客地址
---
- hugo配置文件
# 在本地将文章编译,部署到github后,通过baseURL跳转
baseURL = "https://chnq.github.io"
languageCode = "zh-CN"
title = "chnq"
theme = "maupassant"
# 页面文章数
paginate = 10
# 摘要字数
summaryLength = 70
[author]
name = "chnq"
## 友情链接
[[params.links]]
title = "c03的博客"
name = "c03的博客"
url = "https://www.cnblogs.com/chniny/"
## 侧边栏广告
[[params.ads]]
title = "【2019双12】ALL IN CLoud 低至1折"
url = "https://www.aliyun.com/minisite/goods?userCode=jdg9oj97&share_source=copy_link"
img = "https://img.alicdn.com/tfs/TB1_rYHo7P2gK0jSZPxXXacQpXa-690-388.jpg"
## 开启版权声明,协议名字和链接都可以换
[params.cc]
name = "知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议"
link = "https://creativecommons.org/licenses/by-nc-nd/4.0/"
## 配置网站菜单
[menu]
[[menu.main]]
identifier = "tags"
name = "标签"
url = "/tags/"
weight = 2
[[menu.main]]
identifier = "categories"
name = "分类"
url = "/categories/"
weight = 3
[[menu.main]]
identifier = "archives"
name = "归档"
url = "/archives/"
weight = 4
- 自定义菜单
# 在config.toml中配置子菜单,但点击时会报错:404 page not found
# 这是我们需要在D:\hugo\content路径下新建[tags、categories、archives]这三个文件夹,在文件夹中分别新建index.md
# 在index.html中分别编写如下
---
title: "标签"
description: "标签页面"
type: "tags"
---
---
title: "分类"
description: "分类页面"
type: "categories"
---
---
title: "归档"
description: "归档页面"
type: "archives"
---
- 站内搜索
# 参考以上案例,在D:\hugo\content路径下新建search文件夹,并新建index.md,编写如下内容
---
title: "搜索"
description: "搜索页面"
type: "search"
---
部署
- 在github新建一个仓库,格式为
账户名.github.io
# 进入本地博客文件夹根目录,编译文章
hugo
# 进入public目录,初始化仓库
git init
# 初始化本地仓库后时master分支,需切换为与github上相同的main分支
git branch -M main
# 将所有内容添加到git
git add .
# 暂存文件时,报错:warning: LF will be replaced by CRLF in **
git config core.autocrlf false
# 提交到git本地
git commit -m "博客初始化"
# 关联到远程git
git remote add origin git@github.com:chnq/chnq.github.io.git
# 推送到远程git
git push -u origin master
- 访问
https://chnq.github.io
编写文章
- 插入图片
# 在D:\hugo\static路径下新建一个文件夹images,将图片放到该路径下
# 在文章中插入图片,启动服务后本地可查看;编译后远程也可查看
![](/images/test_images.jpg)
以下为测试代码块
- 代码块1
点击查看详情
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
- 代码块2
server:
port: 8080
spring:
application:
name: mybatisdemo
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.0.102:3306/mybatisdemo?characterEncoding=utf-8&serverTimezone=UTC
username: root
password: 123456
mvc:
view:
suffix: ".html"
mybatis:
configuration:
map-underscore-to-camel-case: true
mapperLocations: classpath:mapper/*.xml # 映射xml文件
logging:
level:
com:
chnq:
mybatisdomo: debug
- 代码块3
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.chnq.mybatisdemo.mapper")
public class MybatisDemoApplication {
public static void main(String[] args) {
SpringApplication.run(MybatisDemoApplication.class, args);
}
}
- 代码块4
// 先指定类型,再赋值
let a: number;
a = 123;
// 指定类型后直接赋值
let b: String = 'hello';
// ts文件中直接指定值,ts会自动判断类型
let c = false;
// 给函数的参数和返回值指定类型
function sum(a: number, b: number): number{ // 第三个number表示返回值的类型
return a + b;
}
- 代码块5
html, body, #app{
height: 100%;
margin: 0;
padding: 0;
}
- 代码块6
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
引用
一支穿云箭,千军万马来相见;
复选框 checkbox
bug
- [标签、分页、归档]这三个子菜单存在问题,在博客根目录
config.toml
中配置如下属性,参考
[taxonomies]
tag = "tags"
category = "categories"
archives = "archives"