From 99fd8e37880efc37f7bf35c722ecf08ed9005924 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Mon, 10 Jul 2023 13:01:07 -0400 Subject: [PATCH] overhaul a lot of stuff - added lref feature which links to files in the knowledge base without having to add ten million "../../../" - instructions changed so that now you can link to "/templates/template.typ" without having to add ten million "../../../" to the path --- README.md | 26 ++++++++++++++++++++++++-- algs.typ | 2 +- general.typ | 2 +- gensettings.sh | 13 +++++++++++++ main.typ | 16 +++++++++++++--- problems.typ | 2 +- sfd.typ | 2 +- 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 gensettings.sh diff --git a/README.md b/README.md index 37d06aa..9819f08 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,36 @@ docs/ └── ... ``` -Personally, I set up templates as a git submodule, and docs as another git repo. +## Installation + +Set up `docs/` as a git repo. + + mkdir docs + cd docs + git init + +Add `templates/` as a submodule. + + git submodule add https://github.com/dogeystamp/typst-templates templates + +Set the environment variable `TYPST_ROOT` to `docs/` in `.bashrc`, `.profile` or equivalent. +Otherwise, templates won't be able to render due to security policy. + + .profile + -------- + + export TYPST_ROOT="$HOME/docs" + +Create a settings file in `docs/`: + + templates/gensettings.sh settings.yml ## Example usage Example usage (this is test.typ in the above tree:) ```typ -#import "../templates/problems.typ": template, source_code, status +#import "/templates/problems.typ": template, source_code, status #show: template.with( title: "CCC '22 J1 - Cupcake Party", problem_url: "https://dmoj.ca/problem/cc22j1", diff --git a/algs.typ b/algs.typ index 194dc19..67b0cc9 100644 --- a/algs.typ +++ b/algs.typ @@ -1,6 +1,6 @@ // templates for compsci notes -#import "main.typ": gen_title, gen_authors, doc_template, mono_font +#import "main.typ": gen_title, gen_authors, doc_template, mono_font, lref #import "compsci.typ": source_code #let template( diff --git a/general.typ b/general.typ index 9ee9c09..4fec4ae 100644 --- a/general.typ +++ b/general.typ @@ -1,6 +1,6 @@ // general document -#import "main.typ": gen_title, gen_authors, doc_template +#import "main.typ": gen_title, gen_authors, doc_template, lref #let template( title: none, diff --git a/gensettings.sh b/gensettings.sh new file mode 100755 index 0000000..f986ef1 --- /dev/null +++ b/gensettings.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +PROGNAME=$(basename "$0") + +if [ -z "$TYPST_ROOT" ]; then + echo "$PROGNAME: "'Please set $TYPST_ROOT.' + exit 1 +fi + +cat < $1 +prefix: "$TYPST_ROOT" +me: "$USER" +EOF diff --git a/main.typ b/main.typ index f05f307..d5eba9b 100644 --- a/main.typ +++ b/main.typ @@ -6,12 +6,22 @@ #let normal-size = 12pt #let large-size = 12pt -#let me = "dogeystamp" - #let font = "IBM Plex Sans" #let heading_font = "IBM Plex Sans" #let mono_font = "DejaVu Sans Mono" +#let settings = yaml("/settings.yml") + +// reference based on TYPST_ROOT +// use paths like "/problems/problem.pdf" +// which will translate to "/home/user/docs/problems/problem.pdf" +#let lref( + url, + text +) = { + return link(settings.prefix + url, text) +} + #let gen_title( title: none, ) = { @@ -28,7 +38,7 @@ if authors == none { authors = ( ( - name: me, + name: settings.me, ), ) } diff --git a/problems.typ b/problems.typ index a1edd09..b9d9c24 100644 --- a/problems.typ +++ b/problems.typ @@ -1,6 +1,6 @@ // templates for compsci problem documents outside of contests -#import "main.typ": gen_title, gen_authors, doc_template, mono_font +#import "main.typ": gen_title, gen_authors, doc_template, mono_font, lref #import "compsci.typ": source_code, status #let template( diff --git a/sfd.typ b/sfd.typ index cfa63b0..2260ab3 100644 --- a/sfd.typ +++ b/sfd.typ @@ -1,6 +1,6 @@ // templates for online lecture notes -#import "main.typ": gen_title, gen_authors, doc_template, mono_font +#import "main.typ": gen_title, gen_authors, doc_template, mono_font, lref #let template( title: none,