main
  1#import "../utils/datetime-display.typ": datetime-display-full
  2#import "../utils/style.typ": , 
  3
  4// 本科生封面
  5#let bachelor-cover(
  6  // documentclass 传入的参数
  7  twoside: false,
  8  fonts: (:),
  9  info: (:),
 10  // 其他参数
 11  isdesign: false, // 是否为毕业设计
 12  isminor: false, // 是否为辅修
 13  datetime-display: datetime-display-full,
 14) = {
 15  // 1.  默认参数
 16  fonts =  + fonts
 17  info = (
 18    (
 19      title: ("基于 Typst 的", "厦门大学本科毕业论文模板"),
 20      title-en: "An XMU Undergraduate Thesis Template\nPowered by Typst",
 21      grade: "20XX",
 22      student-id: "1234567890",
 23      author: "张三",
 24      department: "某学院",
 25      major: "某专业",
 26      supervisor: ("李四", "教授"),
 27      submit-date: datetime.today(),
 28    )
 29      + info
 30  )
 31
 32  // 2.  对参数进行处理
 33  // 2.1 如果是字符串,则使用换行符将标题分隔为列表
 34  if type(info.title) == str {
 35    info.title = info.title.split("\n")
 36  }
 37  if type(info.title-en) == str {
 38    info.title-en = info.title-en.split("\n")
 39  }
 40  // 2.2 处理提交日期
 41  if type(info.submit-date) == datetime {
 42    info.submit-date = datetime-display(info.submit-date)
 43  }
 44
 45  // 3.  内置辅助函数
 46  let info-key-short(str) = {
 47    box(width: 4.5em, str.codepoints().join(h(1fr)) + ":")
 48  }
 49  let info-key-long(str) = {
 50    box(width: auto, str + ":")
 51  }
 52
 53  // 4.  正式渲染
 54  pagebreak(weak: true, to: if twoside { "odd" })
 55
 56  // 居中对齐
 57  set align(center)
 58
 59  // 学校 LOGO
 60  v(45pt)
 61  image("../assets/xmu-zi-jiageng.svg", width: 208pt)
 62  v(3em)
 63
 64  // 将中文之间的空格间隙从 0.25em 调整到 1em
 65  text(
 66    size: .,
 67    font: fonts.,
 68    spacing: 400%,
 69    weight: "bold",
 70  )[    #if isdesign [ ] else [ ]]
 71  v(0pt)
 72  if isminor {
 73    text(size: 字号.三号, font: fonts.宋体, weight: "bold")[(辅修)]
 74  }
 75
 76  v(2em)
 77
 78  text(size: 字号.二号, font: fonts.黑体, info.title.join("\n"))
 79
 80  v(1em)
 81
 82  text(
 83    size: 字号.三号,
 84    font: fonts.宋体,
 85    info.title-en.join("\n"),
 86    weight: "bold",
 87  )
 88
 89  v(2em)
 90
 91  text(
 92    size: 字号.四号,
 93    font: fonts.宋体,
 94    grid(
 95      align: (right, left),
 96      columns: (1fr, 1fr),
 97      row-gutter: 1.5em,
 98      column-gutter: 1.5em,
 99      info-key-short("姓名"), info.author,
100      info-key-short("学号"), info.student-id,
101      info-key-short("学院"), info.department,
102      info-key-short("专业"), info.major,
103      info-key-short("年级"), info.grade + "级",
104      info-key-long("校内指导老师"), info.supervisor.join(" "),
105      info-key-long("校外指导老师"),
106      if info.supervisor-outside != () { info.supervisor-outside.join(" ") },
107    ),
108  )
109
110  v(6em)
111
112  text(size: 字号.四号, font: fonts.宋体, info.submit-date)
113}