基本用法

学习 HugoBlox 的基本用法和常用命令

最后更新: 2024-01-15
页面目录

本文档介绍 HugoBlox 的基本用法,包括创建内容、运行站点和常用命令。

常用命令

开发服务器

# 启动开发服务器(包含草稿内容)
hugo server -D

# 指定端口
hugo server -D --port 8080

# 绑定所有网络接口(便于局域网访问)
hugo server -D --bind 0.0.0.0

构建站点

# 构建静态文件到 public/ 目录
hugo

# 清理旧文件并构建
hugo --gc

# 最小化输出
hugo --gc --minify

内容管理

# 创建新文章
hugo new content post/my-first-post.md

# 创建新页面
hugo new content about.md

内容创建

Front Matter

每个内容文件都以 Front Matter 开头:

---
title: "文章标题"
description: "文章描述"
date: 2024-01-15
lastmod: 2024-01-20
draft: false
tags: ["hugo", "tutorial"]
categories: ["技术"]
---

Markdown 内容

Front Matter 之后是 Markdown 格式的内容:

## 第一节

这是段落内容。

### 子节

- 列表项 1
- 列表项 2

\`\`\`python
print("Hello, Hugo!")
\`\`\`

内容组织

Section(章节)

使用目录组织内容:

content/
├── docs/              # docs 章节
│   ├── _index.md      # 章节首页
│   ├── getting-started/
│   │   ├── _index.md
│   │   └── installation.md
│   └── advanced/
│       └── _index.md
└── blog/              # blog 章节
    └── _index.md

分类和标签

---
tags: ["python", "web"]
categories: ["教程", "编程"]
---

资源管理

图片

将图片放在与文章同名的目录中:

content/
└── post/
    └── my-post/
        ├── index.md
        └── image.png

在文章中引用:

![图片描述](image.png)

静态文件

放在 static/ 目录中:

static/
├── files/
│   └── document.pdf
└── images/
    └── logo.png

引用:

[下载文档](/files/document.pdf)

数学公式

HugoBlox 支持 LaTeX 数学公式:

行内公式

行内公式 $E = mc^2$ 示例。

渲染效果:行内公式 $E = mc^2$ 示例。

块级公式

$$
f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx
$$

渲染效果:

$$ f(x) = \int_{-\infty}^{\infty} e^{-x^2} dx $$

代码块

支持语法高亮:

def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

支持的语言包括:

语言 标识符
Python python
JavaScript javascriptjs
Go go
Rust rust
YAML yaml
JSON json
Shell bashshell

下一步

继续学习 核心概念 了解 HugoBlox 的架构设计。