Git Product home page Git Product logo

bloggen's Introduction

bloggen

依赖

hugo版本

root@wwhvw:~/go/src/bloggen# hugo version
hugo v0.92.2+extended linux/amd64 BuildDate=2023-01-31T11:11:57Z VendorInfo=ubuntu:0.92.2-1ubuntu0.1

新建项目后操作

安装网站文件夹

  1. 进入项目cd ./bloggen
  2. hugo new site . --force 创建网站,将生成以下文件
  • archetypes:存放用hugo命令新建的md文件应用的front matter模版
  • content:存放内容页面,如Blog
  • layouts:存放定义网站的样式,写在layouts文件下的样式会覆盖安装的主题中的 layouts文件同名的样式
  • static:存放所有静态文件,如图片
  • data:存放创建站点时Hugo使用的其他数据
  • public:存放Hugo生成的静态网页
  • themes:存放主题文件
  • config.toml:网站配置文件

安装KeepIt主题

  1. 进入themes/目录
  2. git submodule add https://github.com/Fastbyte01/KeepIt.git 下载代码. 使用git submodule保持KeepIt代码仓库的独立性。
  3. 拷贝KeepIt/exampleSite/*bloggen/目录下
  4. 修改config.toml
baseURL = "https://wangweihong.github.io"
languageCode = "zh-cn"
defaultContentLanguage = "en"
title = "摸鱼佬"
theme = "KeepIt"
...
  1. 本地运行测试hugo server --bind 0.0.0.0

添加文档

  1. hugo new helloworld.md
  2. 将生成content/helloworld.md中草稿标识draft: true移除或者设置为false
  3. 本地运行测试hugo server --bind 0.0.0.0

生成静态HTML文件

  1. .gitignore文件中设置添加public/来忽略掉该文件的变更。
  2. 在代码根目录执行hugo,在public/生成静态HTML文件
  3. git init创建博客仓库,git add并且git commit -m "my first blog"
  4. 在github新建wangweihong.github.io项目。 注意,必须要和github账号同名。
  5. git remote set-url origin [email protected]:wangweihong/wangweihong.github.io.git指向仓库
  6. git push -u origin master
  7. 网页访问wangweihong.github.io

博客更新

配置Github Actions工作流。 后续只需要更新blogen仓库代码,推送到github时触发github action自动生成博客静态HTML文件并推送到博客仓库。

问题

本地运行hugo server失败

root@wwhvw:~/go/src/bloggen# hugo server --bind 0.0.0.0
Start building sites …
hugo v0.92.2+extended linux/amd64 BuildDate=2023-01-31T11:11:57Z VendorInfo=ubuntu:0.92.2-1ubuntu0.1
Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:3:3: executing "content" at <partial "home_post.html" .>: error calling partial: "/root/go/src/bloggen/themes/KeepIt/layouts/partials/home_post.html:8:27": execute of template failed: template: partials/home_post.html:8:27: executing "partials/home_post.html" at <.Site.Params.DefaultPage>: can't evaluate field Site in type string

这个是KeepIt主题的问题 见Fastbyte01/KeepIt#73. 修复方法还未合并到主线

修复方法

--- a/layouts/partials/home_post.html
+++ b/layouts/partials/home_post.html
@@ -1,11 +1,11 @@
 {{ $cdn_url := .Scratch.Get "cdn_url" }}
-
+{{ $default_page := .Site.Params.DefaultPage }}
 <div class="post-warp">
     <div class="intro">
         {{ with .Site.Params.avatar}}
         {{ $avatar := .}}
         <div class="avatar">
-          <a href="{{ .Site.Params.DefaultPage }}"> <img src="{{ (printf "%s%s" $cdn_url $avatar)}}"> </a>
+          <a href="{{ $default_page }}"> <img src="{{ (printf "%s%s" $cdn_url $avatar)}}"> </a>
         </div>
         {{ end }}
         {{ if or .Params.gravatar.Email (and .Site.Params.gravatar.Email (ne .Params.gravatar.Email false)) }}


--- a/layouts/partials/home_post.html
+++ b/layouts/partials/home_post.html
@@ -1,11 +1,11 @@
 {{ $cdn_url := .Scratch.Get "cdn_url" }}
-
+{{ $default_page := .Site.Params.DefaultPage }}
 <div class="post-warp">
     <div class="intro">
         {{ with .Site.Params.avatar}}
         {{ $avatar := .}}
         <div class="avatar">
-          <a href="{{ .Site.Params.DefaultPage }}"> <img src="{{ (printf "%s%s" $cdn_url $avatar)}}"> </a>
+          <a href="{{ $default_page }}"> <img src="{{ (printf "%s%s" $cdn_url $avatar)}}"> </a>
         </div>
         {{ end }}
         {{ if or .Params.gravatar.Email (and .Site.Params.gravatar.Email (ne .Params.gravatar.Email false)) }}

参考

bloggen's People

Contributors

wangweihong avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.