热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

以下内容_Hugo快速入门

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Hugo快速入门相关的知识,希望对你有一定的参考价值。Hugo是由Go语言实现的静态网站生成器。简单、易用、高效、易扩展

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Hugo快速入门相关的知识,希望对你有一定的参考价值。


Hugo是由Go语言实现的静态网站生成器。简单、易用、高效、易扩展、快速部署。


Intall1

go install github.com/gohugoio/hugo@latest

Quick Start2



https://gohugo.io/getting-started/quick-start/


运行以下命令创建一个使用Ananke主题的网站:

hugo new site quickstart
cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
echo "theme = 'ananke'" >> config.toml
hugo server

Add Content

给网站增加新的网页:

hugo new posts/my-first-post.md

Hugo在content/posts目录创建了my-first-post.md文件,文件内容如下:

---
title: "My First Post"
date: 2022-11-20T09:03:20-08:00
draft: true
---

修改并保存文件后启动Hugo服务器可以预览网站,可以使用以下的任一命令以包含draft内容:

hugo server --buildDrafts
hugo server -D

Configure the site

可以通过根目录的config.toml文件配置网站相关信息:

baseURL = 'http://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = 'ananke'

Publish the site

生成站点的静态文件,文件将生成到根目录下的public目录

hugo

Host on GitHub3



https://gohugo.io/hosting-and-deployment/hosting-on-github/



  1. 创建名为.github.io.github.io的GitHub仓库
  2. 在仓库中新增文件.github/workflows/gh-pages.yml并填写以下内容:

name: github pages
on:
push:
branches:
- main # Set a branch that will trigger a deployment
pull_request:
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
# extended: true
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/main'
with:
github_token: $ secrets.GITHUB_TOKEN
publish_dir: ./public

config.toml中的baseURL修改为https://.github.io

Ref:





  1. https://chuxing.club ↩︎

  2. https://github.com/gohugoio/hugo ↩︎

  3. https://www.xianmin.org/post/2022/07-familiar-one-keybinding-style/ ↩︎



推荐阅读
author-avatar
333
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有