Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blogdown Website post - Hide date and/or title of post

Tags:

r

blogdown

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/

like image 268
Jas Avatar asked Jul 13 '18 10:07

Jas


1 Answers

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.


like image 74
TC Zhang Avatar answered Oct 22 '22 10:10

TC Zhang