hugo-theme-codex icon indicating copy to clipboard operation
hugo-theme-codex copied to clipboard

Removing links to previous and next post

Open ajdinre opened this issue 5 years ago • 3 comments

Hi,

I've used your theme and I think this would be a good feature. In post Params, we can insert another value like cleanPage = true. This would be useful here:

<div class="pagination">
  {{if .Params.cleanPage}}
  <div></div>
  {{else}}
    {{if .PrevInSection}}
      <a class="pagination__item" href="{{.PrevInSection.Permalink}}">
          <span class="pagination__label">Previous Post</span>
          <span class="pagination__title">{{.PrevInSection.Title}}</span>
      </a>
    {{end}}

    {{if .NextInSection}}
      <a class="pagination__item" href="{{.NextInSection.Permalink}}">
        <span class="pagination__label">Next Post</span>
        <span class="pagination__title" >{{.NextInSection.Title}}</a>
      </a>
    {{end}}
    {{end}}
</div>

please note, there has to be something in the first part of the if statement.

I'd add just one variable called cleanPost to page parameters and that parameter would remove the pagination. This would be useful on pages like /about, /cv, /resources etc.

Edit: i just wanted to ask if this was an okay feature to add, I could make a PR for it.

ajdinre avatar Aug 26 '20 10:08 ajdinre

@ajdintrejic I'd like to suggest a modification:

{{ if not .Params.cleanPage }}
  <div class="pagination">
    {{ if .PrevInSection }}
      <a class="pagination__item" href="{{ .PrevInSection.Permalink }}">
        <span class="pagination__label">Previous Post</span>
        <span class="pagination__title">{{ .PrevInSection.Title }}</span>
      </a>
    {{ end }}

    {{ if .NextInSection }}
      <a class="pagination__item" href="{{ .NextInSection.Permalink }}">
        <span class="pagination__label">Next Post</span>
        <span class="pagination__title" >{{ .NextInSection.Title }}</a>
      </a>
    {{ end }}
  </div>
{{ end }}

I haven't tested this locally, but I believe this should work. Let me know if it doesn't.

Another approach would be to conditionally display the pagination partial by updating single.html#L21 like so:

{{ partial "tags.html" .}}
{{ if not .Params.cleanPage }} {{ partial "post-pagination.html" .}} {{ end }}

I personally feel that using a parameter like pagination: true would be more self-explanatory, in which case: {{ if not .Params.cleanPage }} would be replaced by {{ if .Params.pagination }}

SanchithHegde avatar Aug 27 '20 19:08 SanchithHegde

This is a great idea. There's a lot of opinions about the usefulness of pagination in blog posts these days. So thank you for bringing it up @ajdintrejic . I agree with the semantics proposed by @SanchithHegde :

{{ if .Params.pagination }} {{ partial "post-pagination.html" .}} {{ end }}

Would you be open to making a contribution @ajdintrejic ?

jakewies avatar Oct 18 '20 15:10 jakewies

Thanks, I'll make changes and do a pr in couple of days.

ajdinre avatar Oct 18 '20 15:10 ajdinre