通过 Hugo+Nginx 部署静态网页

nginx 配置文件如下所示:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 server {
        listen  80;
        server_name  localhost;
        location / {
            root   /mnt/e/myhugo/public/;
            index  index.html index.htm;
        }
        error_page  404  /404.html;
        location = /404.html {
            root  /home/wwwroot/html;
        }
    }
    server {
        listen 80;
        server_name blog.tool.mybns.cn;
        rewrite  ^(.*)$  https://${server_name}$1  permanent;    #接收到http访问请求时,重定向到https
        location / {
            root  /home/wwwroot/html;
            index  index.html index.htm;
        }
        error_page  404 /404.html;
        location = /404.html {
            root  /home/wwwroot/html;
        }
    }
    server {
      listen 443 ssl http2;
         ssl_certificate ./server.crt;
    #私钥文件名称(此处的私钥文件放在 /etc/nginx/ssl-nginx-qcloud 目录下)
    ssl_certificate_key ./server.key;
        ssl_protocols         TLSv1.2 TLSv1.3;
        server_name blog.tool.mybns.cn;
        location / {
            root  /mnt/e/myhugo/public;
            index  index.html index.htm;
        }
        error_page  404 /404.html;
        location = /404.html {
            root  /mnt/e/myhugo/public/;
        }
    }

hugo 再起航

hugo 参考官方搭建

安装 hugo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo pacman -S hugo
resolving dependencies...
looking for conflicting packages...

Packages (1) hugo-0.112.3-1

Total Download Size:   14.74 MiB
Total Installed Size:  62.59 MiB

:: Proceed with installation? [Y/n] Y
:: Retrieving packages...
 hugo-0.112.3-1-x86_64

安装 emacs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
🌈 yay -S emacs
Sync Explicit (1): emacs-28.2-2
warning: emacs-28.2-2 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Packages (1) emacs-28.2-2

Total Installed Size:  111.46 MiB
Net Upgrade Size:        0.00 MiB

:: Proceed with installation? [Y/n]

安装 spacemacs

1
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

# 本文作者: Linn @林・初夏 # 本文链接: https://linn-ylz.com/Computer-Science/Emacs/emacs-learning-2/ # 版权声明: 本站所有文章除特别声明外,均采用 (CC)BY-NC-SA 许可协议。转载请注明出处!

Emacs 的配置文件默认保存在 ~/.emacs.d/init.el 文件中。(如果其不存在可自行创建, 配置文件也可保存在 ~/.emacs 文件中,通常 ~/.emacs 的优先级更高)。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(defun my/hugo-newpost (slug title tags categories)
  (interactive "sSlug: \nsTitle: \nsTags: \nsCategories: ")
  (let* ((now (current-time))
		 (basename (concat (format-time-string "%Y-%m-%d-" now)
						   slug ".org"))
		 (postdir (expand-file-name "content/post" (locate-dominating-file default-directory "config.toml")))
		 (filename (expand-file-name basename postdir))
         (create-date (my/iso-8601-date-string)))
	(when (file-exists-p filename)
      (error "%s already exists!" filename))
	(find-file filename)
	(insert
	 (format "#+TITLE: %s\n#+DATE: %s\n#+LASTMOD: %s\n#+TAGS[]: %s\n#+categories[]: %s\n"
             title create-date create-date tags categories))
	(goto-char (point-max))
	(save-buffer)))
(defun my/iso-8601-date-string (&optional datetime)
  (concat
   (format-time-string "%Y-%m-%dT%T" datetime)
   ((lambda (x) (concat (substring x 0 3) ":" (substring x 3 5)))
    (format-time-string "%z" datetime))))

打开 emacs-nw 打开无终端版. 在 macos 下需要注意一点的是,meta 的键的位置需要指定,我在 iterm 上和 terminal 上,都选择了用 option 作为 meta 键。

修改 update 的时间格式为

1
YYYY-MM-DDTHH:mm:ssxxx

update 添加 xxx 即可达到一样的效果,多看文档。

可以的。

Licensed under CC BY-NC-SA 4.0
最后更新于 Jan 06, 2025 05:52 UTC
comments powered by Disqus
Built with Hugo
主题 StackJimmy 设计
Caret Up