gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
73.62k stars 7.39k forks source link

The variables in config file do not convert. #10069

Closed diguage closed 2 months ago

diguage commented 2 years ago

Desc

I want to use asciidoctor-diagram in the Hugo. I test the feature.

run hugo server, then throw an error:

$ hugo server
Start building sites …
hugo v0.101.0+extended darwin/amd64 BuildDate=unknown
ERROR 2022/07/05 10:23:55 post/dive-into-encoding-and-character-set.adoc: asciidoctor: FAILED: <stdin>: Failed to load AsciiDoc document - No such file or directory @ rb_sysopen - /diagrams/block.diag
ERROR 2022/07/05 10:23:55 post/dive-into-encoding-and-character-set.adoc: Use --trace to show backtrace
ERROR 2022/07/05 10:23:55 asciidoctor rendering post/dive-into-encoding-and-character-set.adoc: failed to execute binary "asciidoctor" with args [-r asciidoctor-comment-links -r asciidoctor-diagram -a image_attr=align=center,width=100% -a include_dir2=:contentDir/static -a icons=font -a source-highlighter=rouge -a rouge-style=monokai -a source_attr=indent=0,subs="attributes,verbatim,quotes" -a include_dir=:project/static -a blockdiag-fontpath=/tmp/SourceHanSerifSC-Regular.otf --no-header-footer -]: asciidoctor: FAILED: <stdin>: Failed to load AsciiDoc document - No such file or directory @ rb_sysopen - /diagrams/block.diag
  Use --trace to show backtrace

Failed to load AsciiDoc document - No such file or directory @ rb_sysopen - /diagrams/block.diag.

So, I want to set the project base dir as a asciidocotor variable which be used to find the /diagrams/block.diag.

I googled the document, and found the doucument: Configure Hugo | Hugo, there is some variables, such as project, contentDir and so on.

But when I used the variables as the document, the variables did not convert to the value:

INFO 2022/07/05 10:30:49 Rendering post/dive-into-encoding-and-character-set.adoc  using asciidoctor args [-r asciidoctor-comment-links -r asciidoctor-diagram -a include_dir2=:contentDir/static -a rouge-style=monokai -a source_attr=indent=0,subs="attributes,verbatim,quotes" -a include_dir=:project/static -a blockdiag-fontpath=/tmp/SourceHanSerifSC-Regular.otf -a icons=font -a source-highlighter=rouge -a image_attr=align=center,width=100% --no-header-footer -]

The param is -a include_dir=:project/static, not -a include_dir=/path/to/hugo/static.

Hugo version

$ hugo version
hugo v0.101.0+extended darwin/amd64 BuildDate=unknown

config.toml

# https://gohugo.io/content-management/formats/
[markup]
  [markup.asciidocExt]
    backend = 'html5'
    extensions = ["asciidoctor-comment-links", "asciidoctor-diagram"]
    safeMode = 'unsafe'
    sectionNumbers = false
    trace = false
    verbose = false
    [markup.asciidocExt.attributes]
      icons = "font"
      source-highlighter = "rouge"
      rouge-style = "monokai"
      source_attr = "indent=0,subs=\"attributes,verbatim,quotes\""
      image_attr = "align=center,width=100%"
      include_dir = ":project/static"
      include_dir2 = ':contentDir/static'

Hugo project

---
title: "细说编码与字符集"
date: 2022-05-05T09:09:12+08:00
draft: true
keywords: ["Unicode","UTF-8","UTF-16","UTF-32","UTF-16BE","UTF-16LE"]
tags: [""]
categories: [""]
thumbnail: "images/encoding/unicode-logo.svg"

weight: 1
---

TODO

.内部声明
[blockdiag,format=svg]
....
blockdiag {
  Kroki -> generates -> "Block diagrams";
  Kroki -> is -> "very easy!";

  Kroki [color = "greenyellow"];
  "Block diagrams" [color = "pink"];
  "very easy!" [color = "orange", label = "非常简单!"];
}
....

.引入声明
blockdiag::/diagrams/block.diag[format=svg]

.引入声明SVG
seqdiag::{include_dir}/diagrams/seq.diag[format=svg]

block.diag

blockdiag {
  Kroki -> generates -> "Block diagrams";
  Kroki -> is -> "very easy!";

  Kroki [color = "greenyellow"];
  "Block diagrams" [color = "pink"];
  "very easy!" [color = "orange", label = "非常简单!"];
}

seq.diag

seqdiag {
  browser  -> webserver [label = "GET /seqdiag/svg/base64"];
  webserver  -> processor [label = "将文字转换成图片"];
  webserver <-- processor;
  browser <-- webserver;
}

tree

$ tree
.
├── LICENSE
├── README.adoc
├── config
│   ├── _default
│   │   └── config.toml
│   └── production
│       └── config.toml
├── content
│   └── post
│       └── dive-into-encoding-and-character-set.adoc
├── static
│   ├── diagrams
│   │   ├── block.diag
│   │   └── seq.diag
│   └── images
└── themes
diguage commented 2 years ago

And there is a problem: the diagram which is in the document, is not included was converted to the project base dir, not the build dir(public).

diguage commented 2 years ago

I found the solution:

  1. add workingFolderCurrent = true to the config file:
# https://gohugo.io/content-management/formats/
[markup]
  [markup.asciidocExt]
    backend = 'html5'
    extensions = ["asciidoctor-comment-links", "asciidoctor-diagram"]
    safeMode = 'unsafe'
    sectionNumbers = false
    trace = false
    verbose = false
    workingFolderCurrent = true
    [markup.asciidocExt.attributes]
      icons = "font"
      source-highlighter = "rouge"
      rouge-style = "monokai"
      source_attr = "indent=0,subs=\"attributes,verbatim,quotes\""
      image_attr = "align=center,width=100%"
      blockdiag-fontpath = "/tmp/SourceHanSerifSC-Regular.otf"
  1. add --destination=public/ to the hugo command.
$ hugo server --destination=public/ -v
diguage commented 2 years ago

I found the solution:

  1. add workingFolderCurrent = true to the config file:
# https://gohugo.io/content-management/formats/
[markup]
  [markup.asciidocExt]
    backend = 'html5'
    extensions = ["asciidoctor-comment-links", "asciidoctor-diagram"]
    safeMode = 'unsafe'
    sectionNumbers = false
    trace = false
    verbose = false
    workingFolderCurrent = true
    [markup.asciidocExt.attributes]
      icons = "font"
      source-highlighter = "rouge"
      rouge-style = "monokai"
      source_attr = "indent=0,subs=\"attributes,verbatim,quotes\""
      image_attr = "align=center,width=100%"
      blockdiag-fontpath = "/tmp/SourceHanSerifSC-Regular.otf"
  1. add --destination=public/ to the hugo command.
$ hugo server --destination=public/ -v

This resolves the problem:

And there is a problem: the diagram which is in the document, is not included was converted to the project base dir, not the build dir(public).

jmooring commented 2 months ago

This was erroneously re-opened.

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.