当前位置:网站首页>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目录来读取博客原文。
边栏推荐
- Conditional compilation
- 杰理之检测灵敏度级别确定【篇】
- The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
- neo4j load csv 配置和使用
- 微信小程序开发实战 云音乐
- 8 - 函数
- NLP技能树学习路线-(一)路线总览
- CADD课程学习(1)-- 药物设计基础知识
- VB的基本语法
- Notes on modification of Jerry's test box pairing software [chapter]
猜你喜欢

DEX文件解析 - method_ids解析
Application of JDBC in performance test

如何做好测试用例设计

Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]

How unity pulls one of multiple components

Primary school, session 3 - afternoon: Web_ xxe
![Network planning | [five transport layers and six application layers] knowledge points and examples](/img/4f/31acce51b584bed5ef56b2093c4db3.png)
Network planning | [five transport layers and six application layers] knowledge points and examples
![Jerry's touch key recognition process [chapter]](/img/cf/8dacbb7f80e427276df6201dddd377.png)
Jerry's touch key recognition process [chapter]

微信小程序开发实战 云音乐
随机推荐
exness:美GDP终值意外加速萎缩1.6%
Unity 如何拖拉多个组件中的一个
The prospectus of pelt medical was "invalid" for the second time in the Hong Kong stock exchange, and the listing plan was substantially delayed
静态类使用@Resource注解注入
Web host iptables firewall security script
企业中台规划和IT架构微服务转型
Great God detailed open source Buff gain Introduction 丨 Live
Spark - 一文搞懂 Partitioner
杰理之检测灵敏度级别确定【篇】
数据智能——DTCC2022!中国数据库技术大会即将开幕
杰理之检测灵敏度级别确定【篇】
杰理之触摸按键识别流程【篇】
网上炒股开户安全嘛!?
信息学奥赛一本通 1362:家庭问题(family)
HeartBeat基于CRM使用NFS对MySQL高可用
杰理之关于长按复位【篇】
originpro 2021 附安装教程
To eliminate bugs, developers must know several bug exploration and testing artifacts.
文件包含&条件竞争
1045 error occurred in MySQL login. Modification method [easy to understand]