agendas icon indicating copy to clipboard operation
agendas copied to clipboard

Experiment: Add total duration to the agenda

Open nicolo-ribaudo opened this issue 1 year ago • 16 comments

image

Lets see if this works -- I'm not sure about how GitHub caches images.

Server code (using temporal and iterator helpers 😄): https://dash.deno.com/playground/tc39-agenda-time

const pattern = new URLPattern({ pathname: "/:year/:month{/}?" });

Deno.serve(async (req: Request) => {
    try {
        const { year, month } = pattern.exec(req.url).pathname.groups;

        const res = await fetch(`https://raw.githubusercontent.com/tc39/agendas/refs/heads/main/${year}/${month}.md`);
        const body = await res.text();

        let outputText;

        if (res.status === 404) {
            outputText = "Err 404"
        } else if (!res.ok) {
            return new Response("Error while fetching the agenda:\n\n" + body, {
                status: res.status,
                headers: { "content-type": "text/plain" }
            });
        } else {
            const minutes = body.matchAll(/\b(\d+)m(?=\s*[,|)])(?!\) Timeboxed Discussions)/g)
                .map(m => parseInt(m[1], 10))
                .reduce((sum, m) => sum + m, 0);

            const duration = Temporal.Duration.from({ minutes }).round({ largestUnit: "hours" });

            outputText = `${duration.hours}h ${duration.minutes}m`;
        }

        return new Response(`
            <svg version="1.1" width="80" height="20" xmlns="http://www.w3.org/2000/svg">
                <style>
                    @media (prefers-color-scheme: dark) {
                        text {
                            fill: white;
                        }
                    }
                </style>
                <text x="0" y="18" font-family="sans-serif">${outputText}</text>
            </svg>
        `, {
            headers: { "content-type": "image/svg+xml", "cache-control": "no-cache, max-age=0" }
        })
    } catch {
        return new Response("Error", { status: 500 });
    }
});

If this works, then I can add it to the template.

nicolo-ribaudo avatar Oct 02 '24 11:10 nicolo-ribaudo

Should we extract only the durations in the tables, or (which is what this PR is doing) also those in the bullet points?

nicolo-ribaudo avatar Oct 02 '24 11:10 nicolo-ribaudo

Github caches images very aggressively, and I'd think we want to avoid adding more external dependencies.

ljharb avatar Oct 02 '24 14:10 ljharb

Wdyt about an action that updates the time whenever there is a new commit on main?

nicolo-ribaudo avatar Oct 02 '24 14:10 nicolo-ribaudo

That seems like it'd create a ton of noise commits :-/

ljharb avatar Oct 02 '24 14:10 ljharb

Are we worried about the number of commits in this repo? I certainly would prioritize having the total time readily available over minimizing the number commits, personally.

bakkot avatar Oct 02 '24 14:10 bakkot

In general yes, git commit history is worth keeping clean on every repo.

I'm sure we can come up with a workaround - a github pages page that calculates it, for example, or a CI check that blocks additions that exceed the total time - that doesn't require spamming commits to the default branch.

ljharb avatar Oct 02 '24 14:10 ljharb

It seems like the cache-control header is working properly to prevent GitHub from caching the image — the preview of this PR already updated the total time due to https://github.com/tc39/agendas/pull/1707

nicolo-ribaudo avatar Oct 02 '24 17:10 nicolo-ribaudo

I just updated the Deno script because the regexp was accidentally including 30m from "Short (≤30m) Timeboxed Discussions", and the PR preview was updated immediately. Caching is definitely not a problem :)

nicolo-ribaudo avatar Oct 02 '24 17:10 nicolo-ribaudo

It doesn't work as well for dark mode image

ryzokuken avatar Oct 02 '24 20:10 ryzokuken

@ryzokuken Fixed

nicolo-ribaudo avatar Oct 04 '24 14:10 nicolo-ribaudo

For alt text, something like "dynamically computed total of timeboxes on the agenda"?

bakkot avatar Oct 04 '24 17:10 bakkot

Alt text updated. Also I figured out how to change the URL to something nicer.

nicolo-ribaudo avatar Oct 08 '24 01:10 nicolo-ribaudo

Note that this will possibly show the wrong duration when looking at older versions of the agenda.

michaelficarra avatar Oct 08 '24 04:10 michaelficarra

how so? the year and month are part of the URL

ljharb avatar Oct 08 '24 06:10 ljharb

@ljharb Not other agenda documents. An older commit.

michaelficarra avatar Oct 08 '24 06:10 michaelficarra

Yeah this will always fetch the duration from main. That part of the agenda is mostly meant for us so it's probably fine, but I can add an explicit mention of this.

Maybe one day with Shadow realm we'll be able to directly run JS in markdown :P

nicolo-ribaudo avatar Oct 08 '24 09:10 nicolo-ribaudo

PR updated to also add the duration to the agenda of the upcoming meeting.

nicolo-ribaudo avatar Nov 21 '24 11:11 nicolo-ribaudo

Can we merge this now?

ryzokuken avatar Jan 10 '25 00:01 ryzokuken