時間:2023-10-12 10:12:01 | 來源:網(wǎng)站運營
時間:2023-10-12 10:12:01 來源:網(wǎng)站運營
10分鐘用Hugo打造一個靜態(tài)網(wǎng)站:快速部署那么,都有哪些流行的靜態(tài)網(wǎng)站生成器呢?
安全(無動態(tài)內(nèi)容)
快速迅速
使用簡單
能夠進行版本控制
Gatsby (React/JS)
Hugo (Go)
Next.js (React/JS)
Jekyll (Ruby)
Gridsome (Vue/JS)
brew install hugo
Linux:sudo apt-get install hugo或者sudo pacman -Syu hugo
然后執(zhí)行下面的命令檢查是否安裝成功:hugo version
hugo new site my-project
下載一個主題??梢栽?https://themes.gohugo.io/ 找到更多你喜歡的主題。cd my-projectgit initgit submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
將主題添加到配置文件。echo 'theme = "ananke"' >> config.toml
添加一篇文章。hugo new posts/my-first-post.md
它看上去應該像這樣:---title: "My First Post"date: 2021-03-10T18:37:11+08:00draft: true---Hello World!
可以在這里給文章添加添加更多屬性配置(標簽,描述,類別,作者)。hugo server -D
在瀏覽器中打開 http://localhost:1313
就能看到你的網(wǎng)站了。├── archetypes├── assets (not created by default)├── config.toml├── content├── data├── layouts├── static└── themes
config.toml
、config.yaml
或 config.json
(可以在網(wǎng)站根目錄中找到)作為默認網(wǎng)站配置文件。除了單獨的配置文件之外,你還可以使用 config directory 來分隔不同的環(huán)境。devops
和 nodejs
部分,那么你需要有 content/devops/first-post.md
和 content/nodejs/second-post.md
目錄。.html
文件的形式存儲模板。有關(guān)更多信息,請參見 Styling
部分。themes
文件夾,可以看到樣式文件。千萬不要直接編輯這些文件!。應該將主題目錄結(jié)構(gòu)復制到
layouts
文件夾。themes/theme-name/layouts/partials
文件夾,可以在其中找到一些HTML模板(header.html
、footer.html
)?,F(xiàn)在我們將編輯 header.html
模板,將內(nèi)容從這個文件復制到 layouts/partials/header.html
中,并注意在主題 layouts
根目錄中創(chuàng)建與主題相同的目錄結(jié)構(gòu)。layouts/partials/header.htmlssthemes/theme-name/layouts/partials/header.html
創(chuàng)建一個自定義CSS文件: static/css/custom-style.css
,然后把自定義 CSS 文件添加到 config.toml
中:[params] custom_css = ["css/custom-style.css"]
打開 layouts/partials/header.html
:<head>
標簽內(nèi):{{ range .Site.Params.custom_css -}} <link rel="stylesheet" href="{{ . | absURL }}">{{- end }}
現(xiàn)在,就可以覆蓋主題中所應用的 CSS 類。hugo
命令:>>> hugo | EN -------------------+----- Pages | 14 Paginator pages | 0 Non-page files | 0 Static files | 1 Processed images | 0 Aliases | 6 Sitemaps | 1 Cleaned | 0 Total in 74 ms
執(zhí)行成功后,會生成一個public 目錄,這個目錄中的內(nèi)容就是我們靜態(tài)網(wǎng)站的所有內(nèi)容。關(guān)鍵詞:靜態(tài),打造
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。