media

look

A picture or a video of a known size.

Drawn

a bar chart. 4 marks: Highlight 1, upper right; Arrow 1, upper centre; Text “Launch week”, upper left; Pin 1, lower centre
Downloads by week, 8 weeks, marked up

The sample

site/src/kinds.rs:198–250

fn words() -> Vec<Block> {
    let prose = Prose::new(vec![
        heading("Release notes"),
        para(vec![span("The diff is now "), bold("typed"), span(" end to end.")]),
        Part::List {
            ordered: false,
            items: vec![
                vec![span("rows keep their place")],
                vec![span("forms check as you type")],
            ],
        },
        Part::Quote {
            spans: vec![span("One shape, three renderers.")],
        },
        listing("rust", "Row::new(\"build\").value(Shown::Text(\"2m\".into()))"),
    ])
    .id("notes");
    let chart = Media::new("media/sample.svg", "a bar chart", 640_u32, 360_u32);
    let hero = Hero::new("Weekly report")
        .id("report")
        .subtitle("What moved, what waits, what broke.")
        .media(chart.clone())
        .actions(vec![Act {
            label: "open".into(),
            tap: Some(open("gallery.html#kind-hero")),
            ..Act::default()
        }]);
    let link = |label: &str| NavLink {
        label: label.into(),
        href: "gallery.html#kind-nav".into(),
        current: (label == "docs").then_some(true),
    };
    let nav = Nav::new(vec![link("docs"), link("guides"), link("changelog")])
        .id("acme-nav")
        .brand(link("Acme"));
    let shots = ["home", "list", "form", "dark"].map(sample_svg).to_vec();
    vec![
        b!(Text(Text::new().id("green").markdown(
            "**Builds are green.** The last one took `2m 14s`, see https://github.com/jirathip-dev/blocks"
        ))),
        b!(Prose(prose)),
        b!(Hero(hero)),
        b!(Nav(nav)),
        b!(Media(
            chart
                .id("downloads")
                .caption("Downloads by week, 8 weeks, marked up")
                .marks(markup())
        )),
        b!(Images(Images::new(shots).id("shots"))),
        b!(Diagram(release())),
    ]
}
{
  "blocks": [
    {
      "alt": "a bar chart",
      "caption": "Downloads by week, 8 weeks, marked up",
      "fallback": {
        "title": "media/sample.svg"
      },
      "height": 360,
      "id": "downloads",
      "marks": [
        {
          "at": [
            0.72,
            0.1
          ],
          "id": "best",
          "kind": "highlight",
          "to": [
            0.86,
            0.95
          ],
          "tone": "warn"
        },
        {
          "at": [
            0.45,
            0.2
          ],
          "id": "why",
          "kind": "arrow",
          "to": [
            0.7,
            0.3
          ]
        },
        {
          "at": [
            0.2,
            0.12
          ],
          "id": "note",
          "kind": "text",
          "text": "Launch week"
        },
        {
          "at": [
            0.36,
            0.72
          ],
          "id": "dip",
          "kind": "pin",
          "text": "1",
          "tone": "info"
        }
      ],
      "src": "media/sample.svg",
      "type": "media",
      "width": 640
    }
  ],
  "fallback": {
    "title": "screen"
  },
  "id": "media",
  "type": "screen"
}

Its fallback

What a renderer without media draws: a row from the fallback the block carries.
media/sample.svg

Style hooks

.b-mediathe block
[data-block=media]every block of the kind
[data-id=downloads]this one block
Every page here is a blocks Screen, written by site::page: no hand-written HTML. Source: https://github.com/jirathip-dev/blocks