luaquartoreveal.js

How to create a lua filter that targets title slides in Quarto revealjs presentations


I'd like to build off of the answer in this question.

I want to modify the background image of slides that meet a certain criteria. In this case I want to apply new attributes to the title slide and all level 1 header slides. This function successfully targets all level 1 headers, but I'm not sure how to target the title slides as well.

I know I can do this in the YAML header for the individual Quarto Presentation file, but I'm creating a template for my organization and would like to keep this background modification as simple and easy to maintain as possible, by keeping it in one place.

function Header(el)
  if el.level == 1 then
    el.attributes["data-background-image"]    = "bg.png"
    el.attributes["data-background-position"] = "left"
    el.attributes["data-background-opacity"]  = "0.25"
    el.attributes["data-background-size"]     = "33%"
    return el
  end
end

I've tried this, based on my super limited lua knowledge, but it doesn't work.

function Header(el)
  if el.level == 1 or el.classes:includes("title-slide") then
    el.attributes["data-background-image"]    = "bg.png"
    el.attributes["data-background-position"] = "left"
    el.attributes["data-background-opacity"]  = "0.25"
    el.attributes["data-background-size"]     = "33%"
    return el
  end
end

And finally, the minimal example that I'll work with comes from the answer to the linked question.


Solution

  • I think it would be easier to handle the background image for the title slide in a different manner, since we specify the title slide background image properties in the document yaml block.

    With this in mind, you can try the following,

    local bg_image = "beach.jpeg"
    local bg_pos = "left"
    local bg_opacity = "0.25"
    local bg_size = "33%"
    
    
    function Header(el)
      if el.level == 1 then
        el.attributes["data-background-image"] = bg_image
        el.attributes["data-background-position"] = bg_pos
        el.attributes["data-background-opacity"] = bg_opacity
        el.attributes["data-background-size"] = bg_size
        return el
      end
    end
    
    function Meta(m)
      m["title-slide-attributes"] = {
        ["data-background-image"] = bg_image,
        ["data-background-position"] = bg_pos,
        ["data-background-opacity"] = bg_opacity,
        ["data-background-size"] = bg_size
      }
      return m
    end