javascript

在 Ubuntu 22.04|20.04|18.04 上安装和使用 Hugo

在本指南中,我将引导您完成在 Ubuntu 22.04|20.04|18.04 桌面版和服务器版上安装和使用 Hugo 的步骤。 Hugo 已被证实是用 Go 编写的最快的开源静态站点生成器。 Hugo 能够以每页 <1 毫秒的速度生成静态网站,平均网站构建时间不到一秒。它附带预制模板,可以快速执行 SEO、评论、分析和其他功能。

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

在 Ubuntu 22.04|20.04|18.04 上安装 Hugo

Hugo 可以通过下载 .deb 包或从 apt 存储库安装在 Ubuntu 22.04|20.04|18.04 上。

从 apt 存储库在 Ubuntu 22.04|20.04|18.04 上安装 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 linux/amd64 BuildDate: 2020-03-25T06:15:45Z

在 Ubuntu 22.04|20.04|18.04 上从 .deb 包安装 Hugo

要从 Debian 软件包在 Ubuntu 22.04|20.04|18.04 上安装 Hugo,首先,从 Github 版本页面 https://github.com/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 linux/amd64 BuildDate=2022-03-12T10:28:42Z VendorInfo=gohugoio

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

$ hugo --help

在 Ubuntu 22.04|20.04|18.04 Linux 上使用 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: 2018-07-12T10: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

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

Total in 9 ms

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

解释$ hugo server

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

Total in 10 ms
Watching for changes in /root/hugo.computingforgeeks.com/{content,data,layouts,static}
Watching for config changes in /root/hugo.computingforgeeks.com/config.toml
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/ (bind address 127.0.0.1)
Press Ctrl+C to stop

要在 Nginx 或 Apache 等网络服务器上进行自托管,请将 public 目录中的内容复制到您的网络服务器文档根目录。

AI相关的一切

留言

您的邮箱地址不会被公开。 必填项已用 * 标注