laozhu / hugo-nuo

🎨 A responsive light & clean hugo theme for blogger.
https://laozhu.me
MIT License
427 stars 150 forks source link

avatar在 config.toml 引用错误 #89

Closed riveryc closed 5 years ago

riveryc commented 5 years ago

老朱你好, 谢谢你的这个模板.

我在 config.toml 中设置了我自己的 avatar: /images/avatar.png 我也把文件 copy 到了static/images/avatar.png 中. 测试 http://localhost:1313/images/avatar.png 可以看到我的头像.

然而首页仍然是你的... 后来通过查看themes/hugo-nuo/layouts/partials/head.html & header.html 你似乎hardcoded 了你的 avatar: {{ $avatar := "/images/avatar.jpg" }} <img class="avatar" src="{{ "/images/avatar.jpg" | relURL }}" alt="Avatar">

我知道可以通过我自己做一个 head.html 来 override 你的文件去修复这个问题... 可是我不想错过你的更新也不想做不必要的修改. 所以想问问你能否修改一下你的源代码?

laozhu commented 5 years ago

@riveryc 现在头像等静态资源都可以在 config.toml 里面配置了。

riveryc commented 5 years ago

The build failed... Here is the error message, I'm still very new to this, searched around with keyword "hugo error failed to publish resource assets is a directory" in Google, didn't find any help. Can you please have a look?

Thanks! @laozhu

Building sites … INFO 2018/11/13 18:40:44 syncing static files to /
INFO 2018/11/13 18:40:44 found taxonomies: map[string]string{"tag":"tags", "category":"categories"}
ERROR 2018/11/13 18:40:44 failed to publish Resource: read /Users/ryang/private/gitlab/riveryc.gitlab.io/themes/hugo-nuo/assets: is a directory
INFO 2018/11/13 18:40:44 Alias "/tags/docker/page/1/index.html" translated to "tags/docker/page/1/index.html"
INFO 2018/11/13 18:40:44 Alias "/page/1/index.html" translated to "page/1/index.html"
INFO 2018/11/13 18:40:44 Alias "/tags/proxy/page/1/index.html" translated to "tags/proxy/page/1/index.html"
INFO 2018/11/13 18:40:44 Alias "/tags/powershell/page/1/index.html" translated to "tags/powershell/page/1/index.html"
INFO 2018/11/13 18:40:44 Alias "/post/page/1/index.html" translated to "post/page/1/index.html"
INFO 2018/11/13 18:40:44 Alias "/tags/windows-server-2016/page/1/index.html" translated to "tags/windows-server-2016/page/1/index.html"
Total in 36 ms
riveryc commented 5 years ago

I removed "resources" folder, and retried the build. still same error message...

laozhu commented 5 years ago

@riveryc 我也不清楚你这个是什么原因,报错是

failed to publish Resource: read /Users/ryang/private/gitlab/riveryc.gitlab.io/themes/hugo-nuo/assets: is a directory
  1. 你先看看 hugo 版本,是不是支持 hugo pipes

  2. static 文件夹不再需要了,所有的静态资源都放到了 assets 目录下面,通过 hugo pipes 的方式引入,你可以参考 head.html 模版 里的用户引入自己的静态资源,只要把静态资源丢到 assets 下面在模版引入就可以。

  3. 你要修改样式的话,需要到主题根目录下面执行下

$ npm install
# 或者
$ yarn

安装 package.json 中的依赖才能编译 CSS 文件。

riveryc commented 5 years ago
➜  riveryc.gitlab.io git:(master) ✗ hugo version
Hugo Static Site Generator v0.51/extended darwin/amd64 BuildDate: unknown

I installed it by using brew yesterday, so I think it should be the latest build.

Still no luck... same error...

laozhu commented 5 years ago

@riveryc I didn't provide default value for hugo pipes' GET method.

Now it's OK.

riveryc commented 5 years ago

Issue fixed!

I'll try the asset fix later.

Thanks! R

riveryc commented 5 years ago

Sorry trouble you again. 你说:

  1. 你要修改样式的话,需要到主题根目录下面执行下
$ npm install
# 或者
$ yarn

安装 package.json 中的依赖才能编译 CSS 文件。

样式文件是不是也要丢到 assets里? assets -> styles -> partials -> _header.scss ? 这样覆盖你原来的文件?

我修改后去你的根目录下 run 了npm install... 没起什么作用, 似乎还是从你的 assets 里 load 的 scss 文件. 没有起到覆盖的作用. 我是 node 小白, 也是 UI 小白. 完全不懂... 哥们只是个 DevOps, 还请请教... 你不忙的时候能否写个稍微详细点的? 辛苦了! 

riveryc commented 5 years ago

搞定了, 哥们, 你那里少了个 dependency: postcss-cli

我需要做:

npm install -g postcss-cli

然后 hugo server 就会帮忙去 compile 我改过的那个文件... 然后就好了...

多谢啦!

riveryc commented 5 years ago

另外一个小问题:

我其他 post 中如果要加一些页面, 截图之类的, 还是需要放在 static 里吧? 我试着放在 assets 里, 结构大概是这样的: assets/images/post/20181115/title.png 然后在 post 中引用/images/post/20181115/title.png 然后返回是404 找不到... 但是 avatar 在/images/avatar.png是可以找到的. 奇怪了...

然后我放在 static/img/post/20181115/title.png post 中引用/img/post/20181115/title.png 就没问题了... 这个正常吗? 是应该这样做么? 还是说你有更好的方法?

谢谢!

laozhu commented 5 years ago

@riveryc 和主题无关的内容图片不建议放到主题文件夹下面的,不管是 static 还是 assets下面,你可以把内容图片放到 content 下面,按文章归类,按日期归类都可以的,然后引用的时候(一般也是在内容page或者markdown里引用)用绝对路径就可以了

image