5

I would like to remove the date from a post without having to manually delete from the html from the public folder after running blogdown::build_site().

I have a post called Gallery which has the following yaml header in the Rmarkdown file at the top:

---
title: Gallery
date: null
output:
  blogdown::html_page:
    date: null
---

This is how it is rendered in the public/gallery/index.html file:

<div class="item">
    <h4><a href="/gallery/">Gallery</a></h4>
    <h5>January 1, 0001</h5>
</div>

Anyway to remove/hide it without doing it manually?

I'm using the minimal theme https://github.com/calintat/minimal/

Jas
  • 794
  • 12
  • 22

1 Answers1

8

What you are asking for is not natively packed with the theme. But a simple line of tweak will do.

  1. Create folder layouts/partials/ in your repo(if it does not exist).
  2. Copy themes/minimal/layouts/partials/list-item.html to layouts/partials/list-item.html
  3. Change this line:

    <h5>{{ $.Scratch.Get "subtitle" }}</h5>
    

    to

    {{ if not .Params.hidedate }}<h5>{{ $.Scratch.Get "subtitle" }}</h5>{{ end }}
    
  4. In the yaml header of your post, add hidedate: true, like this:

    ---
    title: "Creating a New Theme"
    tags: ["go", "golang", "hugo", "themes"]
    hidedate: true
    draft: false
    --- 
    

This will turn off the date; other normal posts remain unaffected.


Pablo Bernabeu
  • 402
  • 4
  • 23
TC Zhang
  • 2,757
  • 1
  • 13
  • 19
  • Thanks although copying the file to the new folder and updating it didn't work. I was able to get it work by directly adjusting the file in the theme folder itself. I just went ahead and deleted the lines because for this site I never need the date. – Jas Jul 15 '18 at 04:06
  • Actually, looks like I did need the date or subtitle for some of the posts. So went back to your option and only difference is I edited the file directly. Looks good! – Jas Jul 15 '18 at 04:18
  • 1
    Yes it should work. if you don't need to switch/update theme in the future, your solution is simpler – TC Zhang Jul 15 '18 at 04:32