130 lines
4.8 KiB
XML
130 lines
4.8 KiB
XML
|
|
#import "@preview/cmarker:0.1.7"
|
|
#import "@preview/mitex:0.2.6": mitex
|
|
|
|
// Get system inputs
|
|
#let filepath = sys.inputs.at("filepath", default: "input.md")
|
|
#let language = sys.inputs.at("language", default: "en")
|
|
#let show-toc = sys.inputs.at("toc", default: "false") == "true"
|
|
|
|
// Front matter inputs
|
|
#let has-frontmatter = sys.inputs.at("has_frontmatter", default: "false") == "true"
|
|
#let fm-title = sys.inputs.at("fm_title", default: none)
|
|
#let fm-subtitle = sys.inputs.at("fm_subtitle", default: none)
|
|
#let fm-author = sys.inputs.at("fm_author", default: none)
|
|
#let fm-date = sys.inputs.at("fm_date", default: none)
|
|
#let fm-tags = sys.inputs.at("fm_tags", default: none)
|
|
#let fm_version = sys.inputs.at("fm_version", default: none)
|
|
|
|
// Parse tags from comma-separated string
|
|
#let tags-list = if fm-tags != none { fm-tags.split(",") } else { () }
|
|
|
|
// Extract filename from filepath (remove path and .md extension)
|
|
#let filename = {
|
|
let path-parts = filepath.split("/")
|
|
let file = path-parts.last()
|
|
if file.ends-with(".md") {
|
|
file.slice(0, file.len() - 3)
|
|
} else if file.ends-with(".temp.md") {
|
|
file.slice(0, file.len() - 8)
|
|
} else {
|
|
file
|
|
}
|
|
}
|
|
|
|
// Use front matter data or defaults
|
|
#let document-author = if fm-author != none { fm-author } else { default_author }
|
|
#let document-title = if fm-title != none { fm-title } else { filename }
|
|
#let document-subtitle = if fm-subtitle != none { fm-subtitle } else { filename }
|
|
|
|
// Parse date
|
|
#let document-date = if fm-date != none {
|
|
// Try to parse the date string
|
|
let date-str = fm-date
|
|
if date-str.len() == 10 and date-str.contains("-") {
|
|
// Format: YYYY-MM-DD
|
|
let parts = date-str.split("-")
|
|
if parts.len() == 3 {
|
|
datetime(year: int(parts.at(0)), month: int(parts.at(1)), day: int(parts.at(2)))
|
|
} else {
|
|
datetime.today()
|
|
}
|
|
} else {
|
|
datetime.today()
|
|
}
|
|
} else {
|
|
datetime.today()
|
|
}
|
|
|
|
// Set document properties
|
|
#set document(
|
|
author: if document-author != none { document-author } else { "" },
|
|
title: document-title,
|
|
keywords: if fm-tags != none { (if document-author != none { document-author } else { "" }, document-title, "md-pdf", ..tags-list) } else { (if document-author != none { document-author } else { "" }, document-title, "md-pdf") },
|
|
date: document-date
|
|
)
|
|
|
|
// Set document language
|
|
#set text(lang: language)
|
|
|
|
// Function to create tag labels
|
|
#let badge(content) = {
|
|
let color = rgb("888888")
|
|
let textcolor = rgb("222222")
|
|
box(
|
|
inset: (x: 3pt, y: 2pt),
|
|
radius: 4pt,
|
|
fill: color.lighten(70%),
|
|
stroke: (paint: color, thickness: 0.5pt),
|
|
)[
|
|
#text(weight: "bold", size: 6pt, fill:textcolor)[#content]
|
|
]
|
|
}
|
|
|
|
// Show basic document metadata if front matter exists
|
|
#if has-frontmatter [
|
|
#if fm-title != none [
|
|
#align(center)[
|
|
#text(size: 18pt, weight: "bold")[#fm-title]
|
|
]
|
|
#v(0.3em)
|
|
]
|
|
#if fm-subtitle != none [
|
|
#align(center)[
|
|
#text(size: 14pt, style: "italic")[#fm-subtitle]
|
|
]
|
|
#v(0.3em)
|
|
]
|
|
#let metadata = ()
|
|
#if document-author != none { metadata.push(document-author) }
|
|
#if document-date != none { metadata.push(document-date.display()) }
|
|
#if fm_version != none { metadata.push(fm_version) }
|
|
#align(center)[
|
|
#for (i, data) in metadata.enumerate() [
|
|
#data
|
|
#if i < metadata.len() - 1 [ \- ]
|
|
]
|
|
]
|
|
|
|
#if fm-tags != none and tags-list.len() > 0 [
|
|
#align(center)[
|
|
#for (i, tag) in tags-list.enumerate() [
|
|
#badge(tag.trim())
|
|
]
|
|
]
|
|
]
|
|
#line(length: 100%, stroke: 0.5pt)
|
|
]
|
|
|
|
// Show table of contents if requested
|
|
#if show-toc [
|
|
#outline()
|
|
#pagebreak()
|
|
]
|
|
|
|
#cmarker.render(
|
|
read(filepath),
|
|
scope: (image: (path, alt: none) => image(path, alt: alt)),
|
|
math: mitex
|
|
)
|