当前位置:网站首页>Golang应用 ━━ 安装、配置与使用hugo博客系统
Golang应用 ━━ 安装、配置与使用hugo博客系统
2022-06-30 19:54:00 【暂时先用这个名字】
先吐槽一下,写的好几篇关于五行八卦的文章竟然被csdn提示违法国家法律。。。那只能考虑自建blog,不能被捆绑手脚了。
正巧也一直想搞一个本地的markdown系统,毕竟md放在本地总是第一要务。
目前流行的hugo试下来还蛮好,发文记录安装过程。
全程手工下载,不用git
一、准备执行文件hugo.exe
二进制
直接搞现成的~~
执行文件下载网址:https://github.com/gohugoio/hugo/releases源码生成
源码下载网址:https://github.com/gohugoio/hugo
解压缩全部,使用命令go build,这个就不用多废话了吧。。。哈哈。
注意,如果提示你build不成,请查一下你的go版本是不是最新的,写本文时用的go 1.18.3,如果是go 1.17.x版本则不能正常生成。
二、生成blogTest项目
将hugo.exe放于D:/test/hugo目录内,使用cmd命令
hugo new site blogTest
执行后生成D:/test/hugo/blogTest目录,这个目录是当前blogTest项目的根目录,然后把hugo.exe移入这个真正的根目录,待会儿的命令需要用到他。
三、安装模板testTpl
官方模板下载地址:https://themes.gohugo.io/
假定下载模板testTpl,下载后解压缩到D:/test/hugo/blogTest/themes/testTpl中。
四、创建文章first.md和about.md
在D:/test/hugo目录内,使用cmd命令
hugo new first.md
hugo new posts/about.md
此时生成目录和md文件:D:/test/hugo/blogTest/content/first.mdD:/test/hugo/blogTest/content/posts/about.md。
about.md文件内容如下:
---
title: "About"
date: 2022-06-26T16:15:50+08:00
draft: true
---
注意这条draft: true,意思是本文为草稿,文章后面要用到。
在最后---的下面写上一句## 好吧,测试一下,markdown语言就不多说了。
五、自建服务器
在D:/test/hugo目录内,使用cmd命令
hugo server --theme=testTpl --buildDrafts --watch
- theme:使用什么模板;
- buildDrafts:将草稿也显示出来;
- watch:任何文章修改都将实时同步刷新;

go server命令将自动启用内置web server,默认在本机浏览器使用http://127.0.0.1:1313打开,具体端口号请注意终端的结果提示。
六、生成静态文件
在D:/test/hugo目录内,使用cmd命令
- 常规模式
hugo
- 草稿也生成模式(
-B是--buildDrafts的缩写)
hugo -B
- 各种命令模式
hugo --theme=testTpl --buildDrafts

生成的静态文件都在D:/test/hugo/blogTest/public,包含文章、样式、多媒体文件等。
此时将public目录中的所有文件上传到托管服务器就能对外使用。
七、配置文件
有两处配置是重点,如果这两处不配置,则生成的静态文件无法正常显示或舒畅使用:
- 系统配置
在D:/test/hugo/blogTest/config.toml内容中修改baseURL和新增theme。baseURL为项目在web server上的根目录(可加域名也可不加,但需要符合绝对和相对目录的规则)。content为文章所在本机目录,可以将文章原件单独存放,hugo系统归另一个目录。theme为所使用的模板名称。uglyURLs将标题名作为文件名或作为目录名,默认为false,如果本地用图,则建议使用true
baseURL = 'http://127.0.0.1/hugo/blogTest/public/'
contentdir = "c:/blog/test"
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = "testTpl"
uglyURLs = true
- 文章配置
将D:/test/hugo/blogTest/content/posts/about.md文章中的draft: true改为draft: false,否则直接使用hugo命令的话,草稿是不会生成静态文件的,也不会出现在文章列表里,go server命令同理。
本例first.md和about.md文件中只有about.md非草稿,即draft: false,所以使用hugo命令直接生成静态文件的话,将出现只含一篇文章的首页。
八、开始写博客
如果使用Obsidian写博客,则为了附件能正常使用,建议设置如图,重点是插入基于当前笔记的相对路径。
详细的obsidian使用方法:《obsidian配合hugo的使用,让markdown本地编辑软件与在线化无缝衔接》
再次强烈建议:实际使用时尽量将博客原文存在其他目录,hugo的程序放在另一个目录。
在hugo的config.toml中设置contentdir目录来读取博客原文。
边栏推荐
- 1045 error occurred in MySQL login. Modification method [easy to understand]
- Notes on modification of Jerry's test box pairing software [chapter]
- 静态类使用@Resource注解注入
- 杰理之用测试盒配对软件修改注意点【篇】
- Detailed steps for Django to upload excel tables and write data to the database
- Filebeat自定义index和fields
- Why must a digital transformation strategy include continuous testing?
- 25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
- Exness: the final value of US GDP unexpectedly accelerated to shrink by 1.6%
- 数据智能——DTCC2022!中国数据库技术大会即将开幕
猜你喜欢

NLP skill tree learning route - (I) route overview

如何快速通过PMP考试?

Torchdrug -- drug attribute prediction
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]

The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed

Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake
Application of JDBC in performance test

【1175. 质数排列】

【450. 删除二叉搜索树中的节点】

8 - 函数
随机推荐
杰理之触摸按键识别流程【篇】
MySQL数据库误删回滚的解决
杰理之检测灵敏度级别确定【篇】
Great God detailed open source Buff gain Introduction 丨 Live
C语言:hashTable
Ten percent of the time, the tar command can't parse the English bracket "()" when decompressing the file
Introduction to neural network (Part 1)
以全栈全功能解决方案,应对多样工具复杂环境DevOps落地难题
CADD course learning (1) -- basic knowledge of drug design
Graduates
基于slate构建文档编辑器
PHP文件上传小结(乱码,移动失败,权限,显示图片)
Static classes use @resource annotation injection
Heartbeat uses NFS to make MySQL highly available based on CRM
小学期,第三场-下午:WEB_xxe
Primary school, session 3 - afternoon: Web_ xxe
【1175. 质数排列】
计网 | 【五 传输层、六 应用层】知识点及例题
GeoServer安装
新出生的机器狗,打滚1小时后自己掌握走路,吴恩达开山大弟子最新成果