更新升级 专属应用 系统故障 硬件故障 电脑汽车 鸿蒙刷机 鸿蒙开发Linux教程 鸿蒙开发Linux命令
当前位置:HMXT之家 > 鸿蒙开发Linux教程 > 在Ubuntu 22.04系统上安装和使用Hugo的方法

在Ubuntu 22.04系统上安装和使用Hugo的方法

更新时间:2023-01-09 09:27:39浏览次数:117+次

本文介绍如何在Ubuntu 22.04操作系统上安装和使用Hugo的方法。当前它可以通过下载.deb包或从apt存储库安装在Ubuntu 22.04、20.04、18.04上。

简介

Hugo被证实是用Go编写的最快的开源静态站点生成器。Hugo能够以每页<1毫秒的速度生成静态站点,平均站点构建时间不到一秒钟。它附带了预先制作的模板,可以快速完成SEO、评论、分析和其他功能。

\

Hugo支持无限的内容类型、分类、菜单、动态API驱动的内容等等,所有这些都不需要插件。此外,您可以以多种格式输出内容,包括JSON或AMP。

在Ubuntu 22.04上安装Hugo

1、在Ubuntu 22.04上从apt存储库安装Hugo

更新系统apt索引并安装Hugo:

sudo apt update

sudo apt -y install hugo

您可以在安装后使用which命令确认hugo二进制文件的位置:

$ which hugo

/usr/bin/hugo

确认安装的版本:

$ hugo version

Hugo Static Site Generator v0.68.3/extended

2、在Ubuntu 22.04上从.deb包安装Hugo

要从Debian包在Ubuntu 22.04上安装Hugo,首先从Github发布页面下载最新版本,地址在https://github.com/gohugoio/hugo/releases。

安装wget和curl:

sudo apt update

sudo apt install curl wget

删除旧版本的hugo:

sudo apt remove hugo

exit

选择与您的CPU体系结构匹配的版本:

curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest \

 | grep  browser_download_url \

 | grep Linux-64bit.deb \

 | grep -v extended \

 | cut -d '"' -f 4 \

 | wget -i -

然后使用以下方法安装软件包:

$ sudo dpkg -i hugo*_Linux-64bit.deb

(Reading database ... 107522 files and directories currently installed.)

Preparing to unpack hugo_0.94.2_Linux-64bit.deb ...

Unpacking hugo (0.94.2) over (0.68.3-1) ...

Setting up hugo (0.94.2) ...

Processing triggers for man-db (2.9.1-1) ...

确认安装的版本:

$ hugo version

hugo v0.94.2-48FB9E4D

如果安装成功,您应该能够使用hugo命令:

$ hugo --help

在Ubuntu 22.04上使用Hugo

既然安装了Hugo,您就可以开始创建网站内容了。在此之前,您需要为站点创建新内容。在本例中,以hugo.computingforgeeks.com为例说明:

$ hugo new site hugo.computingforgeeks.com

Congratulations! Your new Hugo site is created in /home/jmutai/hugo.computingforgeeks.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 " command.

2.Perhaps you want to add some content. You can add single files with "hugo new /.".

3.Start the built-in live server via "hugo server".

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

要创建一个测试页面,请cd到站点目录并使用:

$ hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>

例子:

$ cd hugo.computingforgeeks.com

$ ls 

archetypes config.toml content data layouts static themes

网站内容放置在content目录中:

$ hugo new posts/test-page.md

/home/jmutai/hugo.computingforgeeks.com/content/posts/test-page.md created

为测试添加虚拟内容:

$ vim content/posts/test-page.md

添加:

---

title: "Test Page"

date: 2023-01-08T10:17:29Z

draft: true

---

# Hello World

This is my first hugo site, wooo!!

 

```

hugo_install="success"

if [[ $hugo_install == "success" ]]; then

  echo "Happy me"

```

bye!

生成站点:

$ hugo

输出如下图所示:

\

这将创建public文件夹并向其中添加内容。要使用hugo内置服务器服务网站,请使用:

$ hugo server

输出如下图所示:

\

对于在Nginx或Apache等web服务器上的自托管,请将public目录中的内容复制到web服务器文档根目录。