templateshugoprinting-web-page

How to use custom output formats to create a printer-friendly template in hugo


I would like to be able to define an HTML template that is optimized for printing. It would seem that Hugo custom output formats is exactly what I need but I am struggling to understand how to make it work.

Here is an excerpt from the config.yaml file that defines the new format:


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

I've also created <theme>/layouts/_default/baseof.print.html and <theme>/layouts/_default/single.print.html.

I don't get any errors when I try to build, however I also don't see any of the print templates generated.

I also don't fully understand what the url structure would look like to target the resource. Here is what I've tried

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

Can someone help me understand what I am doing wrong in the configuration and what the URL would look like to access the custom out put?


Solution

  • I was able to work out the issue. Here is the change to the config.yaml that made it work ...

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

    Having made this change the following url will now give me access to the "printer-friendly" template:

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