Amp page linking to other amp pages

Hi there, recently started using Hugo and i’m enjoying it - having a little trouble with my template though.

I have an amp version of my home page - and all the links on my homepage to blog articles, are pointing at the html version instead of their respective amp versions.

Is there a way I can get the permalinks to point to the amp version if the current page is the amp output format?

The below code is what i’m using to generate the homepage’s posts, is there a nice way to get the .RelPermalink to point to the amp version, if the homepage is currently an amp version of the website?

{{- range $paginator.Pages }}

    <article>
      <header>
        <h1><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
      </header>
      {{- if .Summary }}
      <section>
        {{ .Summary }}
      </section>
      {{- end }}
      {{- if .Truncated }}
      <footer>
        <a href="{{ .RelPermalink }}">Read More…</a>
      </footer>
      {{- end }}
    </article>
{{- end }}

Thanks in advance,
Joshua

Permalink and .RelPermalink will alsways point to the main output format (the first)

See

Thanks for the response, so I guess I’ll have to in the amp version of the template use:

{{ with  .OutputFormats.Get "amp" -}}
    <a href="{{ .Permalink }}"></a>
{{- end }}

Which is great for any of my main files, but as for my markdown content files - is there a way to get those to conditionally link to their respective amp versions?

Is there a variable that can give the current output format being used? Then i might be able to prefix the url’s in the markdown with /amp/

1 Like

Re. content files:

  • Either do {{< relref "mypost.md" "amp" >}}
  • Create 1 shortcode per output format, i.e. linker.html and linker.amp.html or whatever.

Note that the .Content itself is currently fixed (one for all output types), but we do some special hackery with the shortcodes. This may be improved on in the future.

There is no exported value that tells you what is the “current output format”. I may expose that, but I suspect it will confuse more than it will help.