【问题标题】:How to use custom output formats to create a printer-friendly template in hugo如何使用自定义输出格式在 hugo 中创建打印友好的模板
【发布时间】:2020-12-12 18:14:01
【问题描述】:

我希望能够定义一个针对打印进行了优化的 HTML 模板。看起来 Hugo 自定义输出格式正是我所需要的,但我很难理解如何使它工作。

以下是定义新格式的 config.yaml 文件的摘录:


outputFormats:
  printFormat:
    name: print
    mediaType: text/html
    isHTML: true
    path: print

outputs:
  page:
    - HTML
    - print
  home:
    - HTML
    - RSS
  section:
    - HTML
    - RSS
  taxonomy:
    - HTML
    - RSS
  term:
    - HTML
    - RSS

我还创建了<theme>/layouts/_default/baseof.print.html<theme>/layouts/_default/single.print.html

我在尝试构建时没有收到任何错误,但是我也没有看到任何生成的打印模板。

我也不完全理解以资源为目标的 url 结构是什么样的。这是我尝试过的

https://<domain-name>/posts/<post-name>.print
https://<domain-name>/posts/<post-name>.print.html
https://<domain-name>/posts/print/<post-name>
https://<domain-name>/posts/<post-name>/print/index.html

有人可以帮助我了解我在配置中做错了什么以及访问自定义输出的 URL 是什么样的吗?

【问题讨论】:

    标签: templates hugo printing-web-page


    【解决方案1】:

    我能够解决这个问题。这是对config.yaml 的更改,使其工作...

    outputFormats:
      printFormat:
        name: print
        mediaType: text/html
        baseName: print
        isPlainText: false
        rel: alternate
        isHTML: false
        noUgly: true
        permalinkable: false
    

    进行此更改后,以下网址现在可以让我访问“打印机友好”模板:

    https://<domain-name>/posts/<post-name>/print.html
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 2011-11-26
      • 1970-01-01
      • 2020-06-05
      • 2015-06-28
      • 1970-01-01
      相关资源
      最近更新 更多