Initial commit
This commit is contained in:
17
.config/defaults.toml
Normal file
17
.config/defaults.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
university = "ХНУРЕ"
|
||||
|
||||
[default_author]
|
||||
name = "Косач Л. П."
|
||||
edu_program = "КУІБ"
|
||||
group = "23-2"
|
||||
gender = "f"
|
||||
variant = 8
|
||||
full_name_gen = "Косач Лариси Петрівни"
|
||||
course = 2
|
||||
semester = 4
|
||||
|
||||
[work_types]
|
||||
lb = "ЛБ"
|
||||
pz = "ПЗ"
|
||||
kr = "КР"
|
||||
idz = "ІДЗ"
|
||||
19
.config/subjects.toml
Normal file
19
.config/subjects.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[subjects.erv]
|
||||
name = "ЕРВ"
|
||||
full_name = "Елементи теорії розрахунків"
|
||||
mentors = [
|
||||
{name = "Шевченко Т. Г.", degree = "Доцент кафедри ПІ", gender = "m"},
|
||||
{name = "Франко І. Я.", degree = "Асистент кафедри ПІ", gender = "m"}
|
||||
]
|
||||
|
||||
[subjects.fiz]
|
||||
name = "Фізика"
|
||||
full_name = "Фізика"
|
||||
mentors = [
|
||||
{name = "Шевченко Т. Г.", degree = "Доцент кафедри ПІ", gender = "m"}
|
||||
]
|
||||
|
||||
[subjects.vyshmat]
|
||||
name = "Вишмат"
|
||||
full_name = "Вища математика"
|
||||
mentors = []
|
||||
10
.typst-template/.gitignore
vendored
Normal file
10
.typst-template/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# lib.typ
|
||||
lib/
|
||||
src/lib/
|
||||
config/universities.yaml
|
||||
|
||||
*.pdf
|
||||
|
||||
# nix artifacts
|
||||
result
|
||||
result-*
|
||||
113
.typst-template/flake.lock
generated
Normal file
113
.typst-template/flake.lock
generated
Normal file
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"local-nure": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1769126611,
|
||||
"narHash": "sha256-4qmXN7kx87pEpZHFJpyRbLfZ5GanF5Jbi1Bmfx6ZXss=",
|
||||
"path": "/storage/git/typst_nure_template",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"path": "/storage/git/typst_nure_template",
|
||||
"type": "path"
|
||||
}
|
||||
},
|
||||
"local-nure-upstream": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1768301144,
|
||||
"narHash": "sha256-VHZXALfaAw5f32mClZTS7MeTSaDSQtErAjI+lgpYIZk=",
|
||||
"ref": "refs/heads/0.1.0",
|
||||
"rev": "549d7f060f81a6356c43b2c231e6453ddae19fca",
|
||||
"revCount": 111,
|
||||
"type": "git",
|
||||
"url": "ssh://gitea@gitea.linerds.us/pencelheimer/typst_nure_template"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "ssh://gitea@gitea.linerds.us/pencelheimer/typst_nure_template"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1763421233,
|
||||
"narHash": "sha256-Stk9ZYRkGrnnpyJ4eqt9eQtdFWRRIvMxpNRf4sIegnw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "89c2b2330e733d6cdb5eae7b899326930c2c0648",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"local-nure": "local-nure",
|
||||
"local-nure-upstream": "local-nure-upstream",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"typix": "typix"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"typix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769071922,
|
||||
"narHash": "sha256-WD8cMrUlqWJWDAD8+B6MUyEuWvi/fgGgv5Wg0xF/Zkc=",
|
||||
"owner": "loqusion",
|
||||
"repo": "typix",
|
||||
"rev": "5d334996b24af342b0992f7f432fcb301ed67314",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "loqusion",
|
||||
"repo": "typix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
176
.typst-template/flake.nix
Normal file
176
.typst-template/flake.nix
Normal file
@@ -0,0 +1,176 @@
|
||||
{
|
||||
description = "A Nix flake for compiling NURE works";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
typix.url = "github:loqusion/typix";
|
||||
typix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
# local-nure.url = "git+ssh://gitea@gitea.linerds.us/unexplrd/typst_nure_template";
|
||||
local-nure-upstream.url = "git+ssh://gitea@gitea.linerds.us/pencelheimer/typst_nure_template";
|
||||
local-nure-upstream.flake = false;
|
||||
|
||||
local-nure.url = "path:/storage/git/typst_nure_template";
|
||||
local-nure.flake = false;
|
||||
|
||||
# Example of downloading icons from a non-flake source
|
||||
# font-awesome = {
|
||||
# url = "github:FortAwesome/Font-Awesome";
|
||||
# flake = false;
|
||||
# };
|
||||
};
|
||||
|
||||
outputs = inputs @ {
|
||||
nixpkgs,
|
||||
typix,
|
||||
flake-utils,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (pkgs) lib;
|
||||
inherit (lib.strings) escapeShellArg;
|
||||
|
||||
typixLib = typix.lib.${system};
|
||||
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = lib.fileset.unions [
|
||||
# lib/ gets imported, which is unwanted
|
||||
# (lib.fileset.fromSource (typixLib.cleanTypstSource ./.))
|
||||
# ./main.typ
|
||||
# (lib.fileset.maybeMissing ./doc.toml)
|
||||
# (lib.fileset.maybeMissing ./utils.typ)
|
||||
# (lib.fileset.maybeMissing ./chapters)
|
||||
# (lib.fileset.maybeMissing ./assets)
|
||||
# (lib.fileset.maybeMissing ./figures)
|
||||
./src
|
||||
];
|
||||
};
|
||||
commonArgs = {
|
||||
typstSource = "src/main.typ";
|
||||
|
||||
fontPaths = [
|
||||
"${pkgs.liberation_ttf}/share/fonts/truetype"
|
||||
];
|
||||
|
||||
# Make sure to override outdated files/links (in case of updated flake.lock)
|
||||
# (may be undesirable with config/universities.yaml in case of custom subjects)
|
||||
forceVirtualPaths = true;
|
||||
|
||||
virtualPaths = [
|
||||
# Add paths that must be locally accessible to typst here
|
||||
# {
|
||||
# dest = "src/lib";
|
||||
# src = "${inputs.local-nure}/src";
|
||||
# }
|
||||
# {
|
||||
# dest = "config/universities.yaml";
|
||||
# src = "${inputs.local-nure}/src/config/universities.yaml";
|
||||
# }
|
||||
];
|
||||
};
|
||||
|
||||
mkTypstPackagesDrv = name: entries: let
|
||||
linkFarmEntries =
|
||||
lib.foldl (set: {
|
||||
name,
|
||||
version,
|
||||
namespace,
|
||||
input,
|
||||
}:
|
||||
set
|
||||
// {
|
||||
"${namespace}/${name}/${version}" = input;
|
||||
})
|
||||
{}
|
||||
entries;
|
||||
in
|
||||
pkgs.linkFarm name linkFarmEntries;
|
||||
|
||||
unpublishedTypstPackages = mkTypstPackagesDrv "unpublished-packages" [
|
||||
{
|
||||
namespace = "unexplrd";
|
||||
name = "test-multifile";
|
||||
version = "0.1.0";
|
||||
input = inputs.local-nure;
|
||||
}
|
||||
{
|
||||
namespace = "local";
|
||||
name = "nure";
|
||||
version = "0.1.0";
|
||||
input = inputs.local-nure-upstream;
|
||||
}
|
||||
];
|
||||
|
||||
# Any transitive dependencies must be added here
|
||||
# See https://loqusion.github.io/typix/recipes/using-typst-packages.html#the-typstpackages-attribute
|
||||
# unstable_typstPackages = [
|
||||
# {
|
||||
# name = "oxifmt";
|
||||
# version = "0.2.1";
|
||||
# hash = "sha256-8PNPa9TGFybMZ1uuJwb5ET0WGIInmIgg8h24BmdfxlU=";
|
||||
# }
|
||||
# ];
|
||||
|
||||
# Compile a Typst project, *without* copying the result
|
||||
# to the current directory
|
||||
build-drv = typixLib.buildTypstProject (commonArgs
|
||||
// {
|
||||
inherit src;
|
||||
# inherit unstable_typstPackages;
|
||||
TYPST_PACKAGE_PATH = unpublishedTypstPackages;
|
||||
});
|
||||
|
||||
# Compile a Typst project, and then copy the result
|
||||
# to the current directory
|
||||
build-script = typixLib.buildTypstProjectLocal (commonArgs
|
||||
// {
|
||||
inherit src;
|
||||
# inherit unstable_typstPackages;
|
||||
TYPST_PACKAGE_PATH = unpublishedTypstPackages;
|
||||
});
|
||||
|
||||
# Watch a project and recompile on changes
|
||||
watch-script = typixLib.watchTypstProject (lib.recursiveUpdate commonArgs
|
||||
{
|
||||
typstWatchCommand = "TYPST_PACKAGE_PATH=${escapeShellArg unpublishedTypstPackages} typst watch";
|
||||
});
|
||||
in {
|
||||
checks = {inherit build-drv build-script watch-script;};
|
||||
|
||||
packages.default = build-drv;
|
||||
packages.watch = watch-script;
|
||||
|
||||
apps = rec {
|
||||
default = watch;
|
||||
build = flake-utils.lib.mkApp {
|
||||
drv = build-script;
|
||||
};
|
||||
watch = flake-utils.lib.mkApp {
|
||||
drv = watch-script;
|
||||
};
|
||||
};
|
||||
|
||||
devShells.default = typixLib.devShell {
|
||||
inherit (commonArgs) fontPaths virtualPaths;
|
||||
|
||||
env = {
|
||||
TYPST_PACKAGE_PATH = escapeShellArg unpublishedTypstPackages;
|
||||
};
|
||||
packages = with pkgs; [
|
||||
# WARNING: Don't run `typst-build` directly, instead use `nix run .#build`
|
||||
# See https://github.com/loqusion/typix/issues/2
|
||||
# build-script
|
||||
watch-script
|
||||
|
||||
just
|
||||
typstyle
|
||||
yq
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
||||
79
.typst-template/justfile
Normal file
79
.typst-template/justfile
Normal file
@@ -0,0 +1,79 @@
|
||||
# File aliases for common commands
|
||||
alias w := watch
|
||||
alias c := compile
|
||||
alias nw := nix-watch
|
||||
alias nb := nix-build
|
||||
alias nd := nix-develop
|
||||
|
||||
|
||||
# Configuration
|
||||
set shell := ["fish", "-ic"]
|
||||
|
||||
file := "src/main.typ"
|
||||
doc_config := "src/doc.toml"
|
||||
# out := `cat {{doc_config}} | tomlq '.doctype + (.worknumber | tostring) + "_" + (.authors[0].name | split(" ")[0]) + "_" + (.authors[0].edu + "-" + .authors[0].group) + "_" + .subject + ".pdf"'`
|
||||
# out := 'bla'
|
||||
|
||||
# Default target - show available recipes
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# Validate required files exist
|
||||
_check-files:
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [[ ! -f "{{file}}" ]]; then
|
||||
echo "Error: Source file {{file}} not found"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "{{doc_config}}" ]]; then
|
||||
echo "Error: Config file {{doc_config}} not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Watch file for changes and recompile automatically
|
||||
[group('typst')]
|
||||
watch: _check-files
|
||||
typst w {{file}}
|
||||
|
||||
# Compile the document once
|
||||
[group('typst')]
|
||||
compile: _check-files
|
||||
typst c {{file}}
|
||||
|
||||
# Compile and copy to parent directory
|
||||
[group('typst')]
|
||||
copy: compile
|
||||
#!/usr/bin/env bash
|
||||
# set -euo pipefail
|
||||
# if [[ ! -f "{{out}}" ]]; then
|
||||
# echo "Error: Output file {{out}} not found after compilation"
|
||||
# exit 1
|
||||
# fi
|
||||
local final_name = $(cat {{doc_config}} | tomlq '.doctype + (.worknumber | tostring) + "_" + (.authors[0].name | split(" ")[0]) + "_" + (.authors[0].edu + "-" + .authors[0].group) + "_" + .subject + ".pdf"')
|
||||
cp "main.typ" "$final_name"
|
||||
|
||||
# Enter nix development environment
|
||||
[group('nix')]
|
||||
nix-develop:
|
||||
nix develop .
|
||||
|
||||
# Watch using nix environment
|
||||
[group('nix')]
|
||||
nix-watch:
|
||||
nix run .#watch
|
||||
|
||||
# Build using nix environment
|
||||
[group('nix')]
|
||||
nix-build:
|
||||
nix run .#build
|
||||
|
||||
# Clean generated PDFs
|
||||
[group('utils'), confirm]
|
||||
clean:
|
||||
@rm -rvf *.pdf
|
||||
|
||||
# Show generated filename
|
||||
# [group('utils')]
|
||||
# show-output:
|
||||
# @echo "{{out}}"
|
||||
30
.typst-template/src/assets/sample.c
Normal file
30
.typst-template/src/assets/sample.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
int i, j;
|
||||
|
||||
// Number of rows
|
||||
int rows = 3;
|
||||
|
||||
// Taking first character of alphabet
|
||||
// which is useful to print pattern
|
||||
char character = 'A';
|
||||
|
||||
// This loop is used to identify
|
||||
// number rows
|
||||
for (i = 0; i < rows; i++) {
|
||||
// This for loop is used to
|
||||
// identify number of columns
|
||||
// based on the rows
|
||||
for (j = 0; j <= i; j++) {
|
||||
// Printing character to get
|
||||
// the required pattern
|
||||
printf("%c ", character);
|
||||
|
||||
// Incrementing character value so
|
||||
// that it will print the next character
|
||||
character++;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
2
.typst-template/src/assets/table.csv
Normal file
2
.typst-template/src/assets/table.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
1,2,3,4
|
||||
5,6,7,8
|
||||
|
4
.typst-template/src/chapters/appendices.typ
Normal file
4
.typst-template/src/chapters/appendices.typ
Normal file
@@ -0,0 +1,4 @@
|
||||
#import "/utils.typ": code
|
||||
|
||||
= Код програми sample.c <foo-c>
|
||||
#code(read("/assets/sample.c"))
|
||||
26
.typst-template/src/doc.toml
Normal file
26
.typst-template/src/doc.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
university = "ХНУРЕ"
|
||||
|
||||
subject = "ЕРВ"
|
||||
type = "ЛБ"
|
||||
number = 3
|
||||
|
||||
[[mentors]]
|
||||
name = "Шевченко Т. Г."
|
||||
degree = "Доцент кафедри ПІ"
|
||||
gender = "m"
|
||||
|
||||
[[mentors]]
|
||||
name = "Франко І. Я."
|
||||
degree = "Асистент кафедри ПІ"
|
||||
gender = "m"
|
||||
|
||||
[[authors]]
|
||||
name = "Косач Л. П."
|
||||
edu_program = "КУІБ"
|
||||
group = "23-2"
|
||||
gender = "f"
|
||||
variant = 8
|
||||
# For coursework
|
||||
full_name_gen = "Косач Лариси Петрівни"
|
||||
course = 2
|
||||
semester = 4
|
||||
BIN
.typst-template/src/figures/Google-Logo-700x394.png
Normal file
BIN
.typst-template/src/figures/Google-Logo-700x394.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
54
.typst-template/src/main.typ
Normal file
54
.typst-template/src/main.typ
Normal file
@@ -0,0 +1,54 @@
|
||||
#import "@unexplrd/test-multifile:0.1.0": *
|
||||
// #import "/lib/lib.typ": *
|
||||
#import "utils.typ": *
|
||||
|
||||
#import style: spacing
|
||||
|
||||
// #show: correctly-indent-list-and-enum-items
|
||||
|
||||
// #show: style.dstu
|
||||
#show: pz-lb.with(
|
||||
..toml("doc.toml"),
|
||||
title: lorem(2),
|
||||
)
|
||||
|
||||
== #lorem(3)
|
||||
#v(-spacing)
|
||||
=== #lorem(5)
|
||||
|
||||
#lorem(20)
|
||||
|
||||
+ #lorem(10)
|
||||
+ #lorem(10)
|
||||
+ #lorem(10)
|
||||
+ #lorem(10)
|
||||
$ 1/2 dot 3 = 3/2 $
|
||||
+ #lorem(10)
|
||||
$ 1/2 dot 3 = 3/2 $
|
||||
+ #lorem(10)
|
||||
+ #lorem(10)
|
||||
+ #lorem(10)
|
||||
|
||||
#lorem(20)
|
||||
|
||||
// #img("/figures/Google-Logo-700x394.png", [Корпорація зла], width: 60%)
|
||||
|
||||
|
||||
#lorem(50)
|
||||
|
||||
#figure(caption: "Приклад коду на C", code(read("assets/sample.c")))
|
||||
|
||||
#lorem(20)
|
||||
|
||||
#figure(
|
||||
caption: [Цифри],
|
||||
table(
|
||||
columns: 4,
|
||||
table.header([Один], [Два], [Три], [Чотири]),
|
||||
..csv("assets/table.csv").flatten(),
|
||||
),
|
||||
)
|
||||
|
||||
#lorem(20)
|
||||
|
||||
#style.appendices(include "chapters/appendices.typ")
|
||||
109
.typst-template/src/utils.typ
Normal file
109
.typst-template/src/utils.typ
Normal file
@@ -0,0 +1,109 @@
|
||||
/// takes in a string of code, e.g. #code(read("foo.c"))
|
||||
#let code(content) = raw(block: true, theme: none, content)
|
||||
|
||||
/// read file as bytes
|
||||
#let p(path) = bytes(read(path, encoding: none))
|
||||
|
||||
/// include chapters by file names from /chapters
|
||||
#let chapters(ch) = (
|
||||
array(ch).map(chapter => include str(chapter) + ".typ").join()
|
||||
)
|
||||
|
||||
#let pz-header(worknumber, name) = columns[#text(weight: "bold", [
|
||||
#align(left)[Практичне заняття №#worknumber]
|
||||
#colbreak()
|
||||
#align(right)[#name]
|
||||
])]
|
||||
|
||||
/// https://forum.typst.app/t/how-to-make-bullet-list-item-bodies-flow-like-paragraphs/3756/3?u=andrew
|
||||
/// Spacing doesn't work the same way as native solution if par leading and
|
||||
/// spacing are different.
|
||||
#let correctly-indent-list-and-enum-items(doc) = {
|
||||
let first-line-indent() = if type(par.first-line-indent) == dictionary {
|
||||
par.first-line-indent.amount
|
||||
} else {
|
||||
par.first-line-indent
|
||||
}
|
||||
|
||||
show list: li => {
|
||||
for (i, it) in li.children.enumerate() {
|
||||
let nesting = state("list-nesting", 0)
|
||||
let indent = context h((nesting.get() + 1) * li.indent)
|
||||
let get-nesting() = calc.div-euclid(nesting.get(), 10)
|
||||
let marker = context {
|
||||
let n = get-nesting()
|
||||
if type(li.marker) == array {
|
||||
li.marker.at(calc.rem-euclid(n, li.marker.len()))
|
||||
} else if type(li.marker) == content {
|
||||
li.marker
|
||||
} else {
|
||||
li.marker(n)
|
||||
}
|
||||
}
|
||||
let parents = state("enum-parents", ()) // Support enum nesting.
|
||||
let body = {
|
||||
parents.update(arr => arr + (-1,))
|
||||
nesting.update(x => x + 10)
|
||||
it.body + parbreak()
|
||||
nesting.update(x => x - 10)
|
||||
parents.update(arr => arr.slice(0, -1))
|
||||
}
|
||||
let content = {
|
||||
marker
|
||||
h(li.body-indent)
|
||||
body
|
||||
}
|
||||
context pad(left: int(nesting.get() != 0) * li.indent, content)
|
||||
}
|
||||
}
|
||||
|
||||
show enum: en => {
|
||||
let start = if en.start == auto {
|
||||
if en.children.first().has("number") {
|
||||
if en.reversed { en.children.first().number } else { 1 }
|
||||
} else {
|
||||
if en.reversed { en.children.len() } else { 1 }
|
||||
}
|
||||
} else {
|
||||
en.start
|
||||
}
|
||||
let number = start
|
||||
for (i, it) in en.children.enumerate() {
|
||||
number = if it.number != auto { it.number } else { number }
|
||||
if en.reversed { number = start - i }
|
||||
let parents = state("enum-parents", ())
|
||||
let get-parents() = parents.get().filter(x => x >= 0)
|
||||
let indent = context h((get-parents().len() + 1) * en.indent)
|
||||
let num = if en.full {
|
||||
context numbering(en.numbering, ..get-parents(), number)
|
||||
} else {
|
||||
numbering(en.numbering, number)
|
||||
}
|
||||
let max-num = if en.full {
|
||||
context numbering(en.numbering, ..get-parents(), en.children.len())
|
||||
} else {
|
||||
numbering(en.numbering, en.children.len())
|
||||
}
|
||||
num = context box(
|
||||
width: measure(max-num).width,
|
||||
align(right, text(overhang: false, num)),
|
||||
)
|
||||
let list-nesting = state("list-nesting", 0) // Support list nesting.
|
||||
let body = {
|
||||
parents.update(arr => arr + (number,))
|
||||
list-nesting.update(x => x + 1)
|
||||
it.body + parbreak()
|
||||
list-nesting.update(x => x - 1)
|
||||
parents.update(arr => arr.slice(0, -1))
|
||||
}
|
||||
if not en.reversed { number += 1 }
|
||||
let content = {
|
||||
num
|
||||
h(en.body-indent)
|
||||
body
|
||||
}
|
||||
context pad(left: int(parents.get().len() != 0) * en.indent, content)
|
||||
}
|
||||
}
|
||||
doc
|
||||
}
|
||||
143
justfile
Normal file
143
justfile
Normal file
@@ -0,0 +1,143 @@
|
||||
# Configuration
|
||||
template_dir := ".typst-template"
|
||||
config_dir := ".config"
|
||||
out_dir := ""
|
||||
|
||||
# Default target
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# Create new work from template
|
||||
new subject shortcode number="":
|
||||
#!/usr/bin/env nu
|
||||
# Convert to lowercase for config lookup
|
||||
let subject_lower = ("{{subject}}" | str downcase)
|
||||
let shortcode_lower = ("{{shortcode}}" | str downcase)
|
||||
|
||||
# Use number if provided, otherwise empty string
|
||||
let number = "{{number}}"
|
||||
|
||||
just _validate-input "{{shortcode}}" $number "{{subject}}"
|
||||
|
||||
# Create temporary directory first
|
||||
let temp_dir = (mktemp -d)
|
||||
let final_dir = if "{{out_dir}}" != "" {
|
||||
$"{{out_dir}}/($subject_lower)/($shortcode_lower)($number)"
|
||||
} else {
|
||||
$"($subject_lower)/($shortcode_lower)"
|
||||
}
|
||||
let subject_dir = if "{{out_dir}}" != "" {
|
||||
$"{{out_dir}}/($subject_lower)"
|
||||
} else {
|
||||
$"($subject_lower)"
|
||||
}
|
||||
|
||||
# Copy template to temp
|
||||
just _copy-template $temp_dir
|
||||
|
||||
# Generate customized files in temp
|
||||
just _generate-doc-toml $shortcode_lower $subject_lower $temp_dir $number
|
||||
|
||||
# Move to final location
|
||||
# NOTE: mkdir then cp: that way it copies to final_dir and not final_dir/temp_dir
|
||||
if "{{out_dir}}" != "" and not ("{{out_dir}}" | path exists) {
|
||||
mkdir {{out_dir}}
|
||||
}
|
||||
mkdir $subject_dir
|
||||
cp -r $temp_dir $final_dir
|
||||
|
||||
print $"=> Created new work: ($final_dir)"
|
||||
|
||||
# rm -rf $temp_dir
|
||||
|
||||
# Validation helper
|
||||
_validate-input shortcode number subject:
|
||||
#!/usr/bin/env nu
|
||||
if not ("{{config_dir}}" | path exists) {
|
||||
error make -u {msg: "Config directory not found"}
|
||||
}
|
||||
|
||||
let defaults_toml = "{{config_dir}}/defaults.toml"
|
||||
let subjects_toml = "{{config_dir}}/subjects.toml"
|
||||
|
||||
if not ($defaults_toml | path exists) {
|
||||
error make -u {msg: $"defaults.toml not found in config directory"}
|
||||
}
|
||||
|
||||
if not ($subjects_toml | path exists) {
|
||||
error make -u {msg: "subjects.toml not found in config directory"}
|
||||
}
|
||||
|
||||
if "{{number}}" != "" {
|
||||
if ("{{number}}" | into int) <= 0 {
|
||||
error make -u {msg: "Number must be positive integer"}
|
||||
}
|
||||
}
|
||||
|
||||
# Check subject exists (case insensitive)
|
||||
let subject_lower = ("{{subject}}" | str downcase)
|
||||
let subjects = (open $subjects_toml | get subjects | columns)
|
||||
if $subject_lower not-in $subjects {
|
||||
error make -u {
|
||||
msg: $"Subject '{{subject}}' not found in configuration"
|
||||
help: $"Available subjects: ($subjects | str join ', ')"
|
||||
}
|
||||
}
|
||||
|
||||
# Directory creation
|
||||
_create-dir target_dir:
|
||||
#!/usr/bin/env nu
|
||||
if ("{{target_dir}}" | path exists) {
|
||||
error make -u {msg: $"Directory {{target_dir}} already exists"}
|
||||
}
|
||||
|
||||
mkdir "{{target_dir}}"
|
||||
|
||||
# Copy template files
|
||||
_copy-template target_dir:
|
||||
#!/usr/bin/env nu
|
||||
if not ("{{template_dir}}" | path exists) {
|
||||
error make -u {msg: $"Template directory {{template_dir}} not found"}
|
||||
}
|
||||
|
||||
cd {{template_dir}}; cp -r * {{target_dir}}/
|
||||
|
||||
# Generate customized doc.toml
|
||||
_generate-doc-toml shortcode subject target_dir number="":
|
||||
#!/usr/bin/env nu
|
||||
let defaults_toml = $"{{config_dir}}/defaults.toml"
|
||||
let subjects_toml = $"{{config_dir}}/subjects.toml"
|
||||
|
||||
# Extract data using Nushell's builtin TOML parsing
|
||||
let defaults = (open $defaults_toml)
|
||||
let subjects = (open $subjects_toml)
|
||||
|
||||
let university = ($defaults | get university)
|
||||
let subject_data = ($subjects | get subjects | get {{subject}})
|
||||
let subject_name = ($subject_data | get name)
|
||||
|
||||
# Get work type, with fallback for unknown shortcodes
|
||||
let work_type = ($defaults | get work_types | try { get "{{shortcode}}" } catch { "{{shortcode}}" })
|
||||
|
||||
let author = ($defaults | get default_author)
|
||||
|
||||
# Get mentors directly from the subject
|
||||
let mentors_data = ($subject_data | get mentors)
|
||||
|
||||
# Build the complete TOML structure as a record
|
||||
let base_config = {
|
||||
university: $university
|
||||
subject: $subject_name
|
||||
type: $work_type
|
||||
mentors: $mentors_data
|
||||
authors: [$author]
|
||||
}
|
||||
|
||||
let doc_config = if "{{number}}" != "" {
|
||||
$base_config | merge {number: ("{{number}}" | into int)}
|
||||
} else {
|
||||
$base_config
|
||||
}
|
||||
|
||||
# Output directly to TOML format
|
||||
$doc_config | to toml | save $"{{target_dir}}/src/doc.toml" --force
|
||||
Reference in New Issue
Block a user