Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • GitCode
  • 帮助文档帮助文档
  • Wiki
    • Docs
    • User
    • Project
    • Pages
  • hugo

帮助文档
帮助文档
  • 项目概览

GitCode / 帮助文档

通知 1799
Star 580
Fork 457
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 44
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 1
  • DevOps
    • 流水线
    • 流水线任务
    • 计划
  • Wiki 89
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 代码片段
  • 项目成员
  • Pages
帮助文档
帮助文档
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 44
    • Issue 44
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 1
    • 合并请求 1
  • Pages
  • DevOps
    • DevOps
    • 流水线
    • 流水线任务
    • 计划
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 89
    • Wiki
  • 代码片段
    • 代码片段
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 流水线任务
  • 提交
  • Issue看板

hugo

最后修改来自于茶陵後 8月 25, 2021
页面历史

使用 Hugo 模板

Hugo 简介

hugo for pages

Hugo 是 Go 编写的静态网站生成器,速度快,易用,可配置。Hugo 有一个内容和模板目录,把他们渲染到完全的 HTML 网站。Hugo 依赖于 Markdown 文件,元数据字体 。用户可以从任意的目录中运行 Hugo,支持共享主机和其他系统。Hugo 只需要几分之一秒就可以渲染一个经典的中型网站,最好网站的每个部分渲染只需 1 毫秒。

Hugo 非常适合博客,文档等网站的生成。

Hugo 官方文档地址

Hugo 示例项目介绍

程序员电子书目录

  • Pages 网址:基于 Hugo 的电子图书目录
  • Pages 项目地址: 项目地址

首先,我们需要在终端中通过hugo new site yoursite.com来创建hugo 项目,如下:

# 创建 hugo 项目
$ hugo new site yousite.com
Congratulations! Your new Hugo site is created in ~/hugo/yousite.com.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/ or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.

其次,我们可以根据提示进行下面的步骤,包括配置 Theme,创建内容等。最终我们创建的一个 Hugo 项目会如下结构所示

# hugo 项目的目录结构
yousite.com
|- archetypes
|- config.toml
|- content
|- data
|- layouts
|- resources
|- static

其中:

  • config.toml为 hugo 的配置文件
  • content为内容存放目录

通常出情况下,这 2 个将会是我们重点关注的地方,接下来我们以上面提到的实例项目内容为大家进行介绍:

config.toml

baseURL = "http://codechina.gitcode.host/programmer/mdbook"
#baseURL = ""
languageCode = "zh"
title = "程序员电子书"
#theme = "showcase"

# showcase settings
license = "MIT"
licenselink = "https://github.com/apvarun/showcase-hugo-theme/blob/master/LICENSE"
description = "《程序员》· 国内开发者的权威刊物,程序员电子书分享"
tags = [ ]
features = ["responsive", "portfolio", "gallery"]
min_version = "0.41.0"

[Params]
hideAutoMenu = false
Author = "CODE CHINA"
Homepage = "https://codechina.csdn.net/programmer/mdbook"
Message = "程序员电子书书单"

[Social]
wechat = "CSDN CODE"%
  • baseURL 为 Pages 项目在 Pages 服务器上的存放目录,地址格式为 <namespace>.gitcode.host/<subgroup-name>/<your-repo>
    • 这里由于项目是 子组织 的项目,因此在项目前方需要添加上 子组织 的路径
  • title 是 Pages 项目的 Title
  • theme 是 Pages 项目使用的 theme,更多的 theme 可以参考 https://themes.gohugo.io/

Content 格式

通常,content 的内容格式存放在 archetypes/default.md中,这个项目的 default.md 内容如下:

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
subtitle:
link:
image:
---

在添加内容的时候按照上方的 MD 格式添加即可。

项目预览

你可以随时在终端中通过运行 hugo serve -D 来预览项目:

yousite.com git:(master) $ hugo serve -D
Start building sites …
WARN 2020/10/13 11:17:33 found no layout file for "HTML" for kind "section": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/10/13 11:17:33 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/10/13 11:17:33 found no layout file for "HTML" for kind "section": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2020/10/13 11:17:33 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

                   | EN
-------------------+-----
  Pages            | 27
  Paginator pages  |  0
  Non-page files   |  0
  Static files     | 23
  Processed images |  0
  Aliases          |  0
  Sitemaps         |  1
  Cleaned          |  0

Built in 162 ms
Watching for changes in /Users/xxm/Documents/gitlab/hugo/openday.com/{archetypes,content,data,layouts,static}
Watching for config changes in /Users/xxm/Documents/gitlab/hugo/openday.com/config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/openday/ (bind address 127.0.0.1)
Press Ctrl+C to stop
克隆仓库

快速访问

  • 首页
  • 组织
    • 子组织
    • 申请入驻
  • 项目
    • 徽章
    • 批量编辑
    • 新建项目
    • 描述模板
    • 文件查找
    • 合并请求
      • 允许协作
      • 创建合并请求
      • Cherry-pick
      • 快进合并
      • 解决冲突
      • 还原
      • 评审及管理
      • Squash合并
      • 合并请求版本
      • 草稿
    • 项目成员
    • 导入
      • Github
      • URL
    • Releases
    • 代码仓库
      • 分支
      • Git属性
      • Blame
      • 文件历史记录
      • 仓库镜像
      • 保护分支
      • 保护Tag
      • Git LFS
      • 减少仓库大小
      • GPG签名提交
      • 文件编辑
      • WebIDE
    • 项目设置
    • 与群组共享项目
    • wiki
    • 代码片
    • Pages
      • Hugo
      • Mdbook
      • html
  • Issues
    • 机密Issue
    • 关联Issue
    • 截止日期
    • 看板
    • 操作Issue
    • 标签
    • 管理Issue
    • 里程碑
    • Issue排序
  • API
    • Runners Api
  • CI / CD
    • Pipelines
      • 流水线计划
      • 设置
    • 变量
    • Runners
    • .codechina-ci.yml
      • .codechina-ci.yml 参考
      • 语法验证
  • 用户
    • 举报用户
    • 用户账号
      • 登录日志
      • 用户权限
      • 个人访问令牌
      • 个人偏好
    • Notebook
    • 探讨
    • SSH密钥
    • 快捷键
    • Markdown
    • 电子邮件通知
    • 快速操作
      • 自动填充
    • 预留命名空间
    • 搜索
    • 时间跟踪
    • 待办事项
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7