Skip to content

Commit 16248b8

Browse files
feat: show latest log
1 parent 5a5e2c7 commit 16248b8

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

main.typ

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import "typ/packages/till-next.typ": mark-till-next, till-next
22
#import "typ/util.typ": babel, bbl, issue, note, now-fixed, prompt, pull, unichar, workaround
33
#import "typ/prioritization.typ": level, level-table
4-
#import "typ/show-example.typ": render-examples
4+
#import "typ/show-example.typ": layout-git-log, render-examples
55
#show: render-examples
66

77
#babel(en: [Chinese Layout Gap Analysis for Typst.], zh: [分析 Typst 与中文排版的差距。])
@@ -1648,6 +1648,8 @@ $ integral f dif x $
16481648
[
16491649
- #bbl(en: [Document version], zh: [文档版本]) \
16501650
#link(git.commit_url)[commit #git.name] (#link(git.log_url)[log])
1651+
1652+
#layout-git-log(summary: bbl(en: [Latest log], zh: [最新日志]), git.latest_log)
16511653
]
16521654
}
16531655

scripts/build.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,51 @@ import { fileURLToPath } from "node:url";
44
import { extraArgs } from "./config.ts";
55
import { precompile } from "./precompile.ts";
66
import { typst } from "./typst.ts";
7-
import { duration_fmt } from "./util.ts";
7+
import { duration_fmt, execFile } from "./util.ts";
8+
9+
interface GitInfo {
10+
name: string;
11+
commit_url: string;
12+
log_url: string;
13+
/** latest git log */
14+
latest_log: string;
15+
}
16+
17+
async function git_info(): Promise<GitInfo | null> {
18+
const git_log = execFile("git", [
19+
"log",
20+
"--max-count=1",
21+
"--pretty=fuller",
22+
"--date=iso",
23+
]).then(({ stdout }) => stdout.trim());
824

9-
function git_info(): string[] {
1025
if (env.GITHUB_ACTIONS === "true") {
1126
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
1227
const base = `${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}`;
13-
const info = {
14-
name: `${env.GITHUB_SHA?.slice(0, 8)} (${env.GITHUB_REF})`,
28+
return {
29+
name: `${env.GITHUB_SHA?.slice(0, 8)} (${env.GITHUB_REF_NAME})`,
1530
commit_url: `${base}/commit/${env.GITHUB_SHA}`,
1631
log_url: `${base}/actions/runs/${env.GITHUB_RUN_ID}`,
32+
latest_log: await git_log,
1733
};
18-
return ["--input", `git=${JSON.stringify(info)}`];
1934
} else if (env.NETLIFY === "true") {
2035
// https://docs.netlify.com/configure-builds/environment-variables/
21-
const info = {
36+
return {
2237
name: `${env.COMMIT_REF?.slice(0, 8)} (${env.HEAD})`,
2338
commit_url: `${env.REPOSITORY_URL}/commit/${env.COMMIT_REF}`,
2439
log_url:
2540
`https://app.netlify.com/sites/${env.SITE_NAME}/deploys/${env.DEPLOY_ID}`,
41+
latest_log: await git_log,
2642
};
27-
return ["--input", `git=${JSON.stringify(info)}`];
2843
} else {
29-
return [];
44+
return null;
3045
}
3146
}
3247

48+
function as_input(info: GitInfo | null): string[] {
49+
return info ? ["--input", `git=${JSON.stringify(info)}`] : [];
50+
}
51+
3352
if (process.argv[1] === fileURLToPath(import.meta.url)) {
3453
await precompile();
3554

@@ -38,7 +57,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
3857
"compile",
3958
"index.typ",
4059
"dist/index.html",
41-
...git_info(),
60+
...as_input(await git_info()),
4261
...extraArgs.build,
4362
]);
4463
console.log(

typ/show-example.typ

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#import "@preview/jumble:0.0.1": bytes-to-hex, md5
33

44
#import "templates/html-fix.typ": reserve-text-fill
5-
#import "templates/html-toolkit.typ": div, div-frame, img
5+
#import "templates/html-toolkit.typ": div-frame, h
66
#import "mode.typ": cache-dir, cache-ready, mode
77

88

@@ -26,7 +26,7 @@
2626
/// - preview (content): previewed result
2727
/// - annotation (str): an annotation shown when hovering
2828
/// -> content
29-
#let layout-example(code, preview, annotation: none, ..sink) = div(
29+
#let layout-example(code, preview, annotation: none, ..sink) = h.div(
3030
class: "example",
3131
..if annotation != none { (title: annotation) },
3232
{
@@ -155,3 +155,10 @@
155155

156156
body
157157
}
158+
159+
/// Layout a git log in a `<details>`
160+
#let layout-git-log(summary: [], log) = h.details(class: "example", {
161+
h.summary(summary)
162+
show text: reserve-text-fill
163+
raw(log, lang: "gitlog", block: true)
164+
})

0 commit comments

Comments
 (0)