Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feature-linear-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
BestUsernamEver committed Jan 11, 2024
2 parents cb9adbc + 7fb5487 commit 337b061
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 37 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Tests
on: [push, pull_request]

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install just from crates.io
uses: baptiste0928/cargo-install@v2
with:
crate: just
- name: Install Typst
uses: yusancky/setup-typst@v3
id: setup-typst
- name: Run checks
run: |
just install
just docs
# TODO: run unit tests here
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright © 2024 Felix Hass

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# Notebookinator
<div align="center">

# The Notebookinator

</div>

<div align="center">

![GitHub Repo stars](https://img.shields.io/github/stars/battlech1cken/notebookinator?style=for-the-badge)
![GitHub contributors](https://img.shields.io/github/contributors/battlech1cken/notebookinator?style=for-the-badge)
![GitHub License](https://img.shields.io/github/license/battlech1cken/notebookinator?style=for-the-badge)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/battlech1cken/notebookinator/ci.yml?style=for-the-badge&label=CI)
![Discord](https://img.shields.io/discord/1183511612322222183?style=for-the-badge&logo=discord&label=Discord)

</div>

This is the Notebookinator, a [Typst](https://github.com/typst/typst) template designed for the Vex Robotics Competition. This template aims to make it as easy as possible to get you up and running with a clean and organized notebooking environment, with minimal overhead. It provides multiple themes, and can even be extended with your own.

Expand Down
38 changes: 18 additions & 20 deletions docs.typ
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,30 @@
The best way to install the Notebookinator is as a local package. Make sure you
have the following software installed on your computer:

- Typst
- Git
- VSCode
- #link("https://github.com/casey/just#installation")[Typst]
- #link("https://github.com/casey/just#installation")[Git]
- #link("https://code.visualstudio.com/")[VSCode]
- #link("https://github.com/casey/just#installation")[just]

Once you have those, find the matching command for you operating system, and
then run it:
Once you've installed everything, simply run the following commands:

*Linux:*
```bash
git clone https://github.com/BattleCh1cken/notebookinator \
~/.local/share/typst/packages/local/
```

*MacOS:*
```zsh
git clone https://github.com/BattleCh1cken/notebookinator \
~/Library/Application Support/typst/packages/local/
```

*Windows:*
// FIXME: find the correct syntax highlighting for powershell
```pwsh
git clone https://github.com/BattleCh1cken/notebookinator %APPDATA%\typst\packages\local\
git clone https://github.com/BattleCh1cken/notebookinator
cd notebookinator
just install
```

= Basic Usage

Once the template is installed, you can import it into your project like this:

#raw(
block: true,
lang: "typ",
"#import \"@local/notebookinator:"+ version + "\": *"
)


```typ
#import "@local/notebookinator": *
```
Expand Down Expand Up @@ -210,6 +205,9 @@ Minimal starting point:
#let radial_tournament_module = tidy.parse-module(read("./themes/radial/components/tournament.typ"))
#show-module(radial_tournament_module)

#let radial_graph_module = tidy.parse-module(read("./themes/radial/components/graphs.typ"))
#show-module(radial_graph_module)

= Developer Documentation

== Project Architecture
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
typstfmt.packages.${system}.default
pkgs.act
pkgs.nodePackages_latest.prettier
pkgs.just
];
};

Expand Down
8 changes: 8 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package target:
./scripts/package "{{target}}"

install:
./scripts/package "@local"

docs:
typst compile docs.typ docs.pdf
1 change: 0 additions & 1 deletion lib.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import "./internals.typ": *
#import "./entries.typ": *
#import "./globals.typ": *
#import "./utils.typ"
#import "./themes/themes.typ"
#import "./glossary.typ"
Expand Down
File renamed without changes.
77 changes: 77 additions & 0 deletions scripts/package
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
set -eu

# Credit to the Cetz package for this script
# https://github.com/johannes-wolf/cetz/blob/master/scripts/package

PKG_PREFIX="notebookinator"

# List of all files that get packaged
files=(
lib.typ
entries.typ
glossary.typ
utils.typ
globals.typ
internals.typ
themes/
typst.toml
LICENSE
README.md
docs.typ
docs-template.typ
docs.pdf
)

# Local package directories per platform
if [[ "$OSTYPE" == "linux"* ]]; then
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
elif [[ "$OSTYPE" == "darwin"* ]]; then
DATA_DIR="$HOME/Library/Application Support"
else
DATA_DIR="${APPDATA}"
fi

if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then
echo "package TARGET"
echo ""
echo "Packages all relevant files into a directory named '${PKG_PREFIX}/<version>'"
echo "at TARGET. If TARGET is set to @local, the local Typst package directory"
echo "will be used so that the package gets installed for local use."
echo "The version is read from 'typst.toml' in the project root."
echo ""
echo "Local package prefix: $DATA_DIR/typst/package/local"
exit 1
fi

function read-toml() {
local file="$1"
local key="$2"
# Read a key value pair in the format: <key> = "<value>"
# stripping surrounding quotes.
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file"
}

SOURCE="$(cd "$(dirname "$0")"; pwd -P)/.." # macOS has no realpath
TARGET="${1:?Missing target path or @local}"
VERSION="$(read-toml "$SOURCE/typst.toml" "version")"

if [[ "$TARGET" == "@local" ]] || [[ "$TARGET" == "install" ]]; then
TARGET="${DATA_DIR}/typst/packages/local/"
echo "Install dir: $TARGET"
fi

TMP="$(mktemp -d)"

for f in "${files[@]}"; do
mkdir -p "$TMP/$(dirname "$f")" 2>/dev/null
cp -r "$SOURCE/$f" "$TMP/$f"
done

TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}"
echo "Packaged to: $TARGET"
if rm -rf "${TARGET:?}" 2>/dev/null; then
echo "Overwriting existing version."
fi
mkdir -p "$TARGET"
mv "$TMP"/* "$TARGET"
5 changes: 1 addition & 4 deletions themes/radial/components/components.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#import "./headings.typ": *
#import "./code-blocks.typ": *
#import "./title.typ": *

#import "./toc.typ": *
#import "./glossary.typ": *

#import "./admonitions.typ": *
#import "./pro-con.typ": *
#import "./decision-matrix.typ": *
#import "./tournament.typ": *
#import "./graphs.typ": *
99 changes: 99 additions & 0 deletions themes/radial/components/graphs.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#import "../colors.typ": *

#import "@preview/cetz:0.1.2"

/// Creates a labeled pie chart.
///
/// Example Usage:
///
/// ```typ
/// #pie_chart(
/// (8, green, "wins"),
/// (2, red, "losses")
/// )
/// ```
///
/// - ..data (array): Each array must contain 3 fields.
/// + `<integer>` The value of the section
/// + `<color>` The value of the section
/// + `<string>` The name of the section
/// Here's an example of one of these arrays:
/// `(2, blue, "bicycles")`
/// -> content
#let pie_chart(..data) = {
let total;
let percentages = ();

for value in data.pos() {
total += value.at(0);
}

for value in data.pos() {
percentages.push(calc.round(value.at(0) / total * 100))
}

cetz.canvas(
{
import cetz.draw: *

let chart(..values, name: none) = {
let values = values.pos()
let anchor_angles = ()

let offset = 0
let total = values.fold(0, (s, v) => s + v.at(0))

let segment(from, to) = {
merge-path(close: true, {
stroke((paint: black, join: "round", thickness: 0pt))
line((0, 0), (rel: (360deg * from, 2)))
arc((), start: from * 360deg, stop: to * 360deg, radius: 2)
})
}

let chart = group(name: name, {
stroke((paint: black, join: "round"))

for v in values {
fill(v.at(1))
let value = v.at(0) / total

// Draw the segment
segment(offset, offset + value)

// Place an anchor for each segment
let angle = offset * 360deg + value * 180deg
anchor(v.at(2), (angle, 1.75))
anchor_angles.push(angle)

offset += value
}
})

return (chart, anchor_angles)
}

// Draw the chart
let (chart, angles) = chart(..data, name: "chart")

chart

set-style(mark: (fill: white, start: "o", stroke: black), content: (padding: .1))
for (index, value) in data.pos().enumerate() {
let anchor = "chart." + value.at(2)
let angle = angles.at(index)

let (line_end, anchor_direction) = if angle > 90deg and angle < 275deg {
((-0.5, 0), "right")
} else {
((0.5, 0), "left")
}

line(anchor, (to: anchor, rel: (angle, 0.5)), (rel: line_end))

content((), [#value.at(2)], anchor: "bottom-" + anchor_direction)
content((), [ #percentages.at(index)% ], anchor: "top-" + anchor_direction)
}
},
)
}
2 changes: 1 addition & 1 deletion themes/radial/components/tournament.typ
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
let bool_icon(input) = {
cell[
#set align(horizon + center)
#if input { image("/template/icons/check.svg", width: 1.5em) } else { image("/template/icons/x.svg", width: 1.5em) }
#if input { image("../icons/check.svg", width: 1.5em) } else { image("../icons/x.svg", width: 1.5em) }
]
}

Expand Down
9 changes: 3 additions & 6 deletions themes/radial/entries.typ
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "./colors.typ": *
#import "./icons/icons.typ"
#import "./components/components.typ"
#import "./components/title.typ" as components
#import "/utils.typ"
#import "./metadata.typ": entry_type_metadata

Expand All @@ -23,11 +23,8 @@
header: components.title(
beginning: image.decode(
utils.change_icon_color(raw_icon: metadata.icon, fill: white), height: 1em,
),

end: context.start_date.display(), color: metadata.color, context.title,
),
footer: [
), end: context.start_date.display("[year]/[month]/[day]"), color: metadata.color, context.title,
), footer: [
#line(length: 100%)
#align(left, [
*Designed by:* \
Expand Down
10 changes: 6 additions & 4 deletions themes/radial/rules.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "./components/components.typ"
#import "./components/headings.typ" as components_heading
#import "./components/code-blocks.typ" as components_code


#let rules(doc) = {
set text(font: "Calibri", size: 11pt)
Expand All @@ -23,10 +25,10 @@
_ #it.caption.body _
]

show raw.where(block: false): components.raw_not_block
show raw.where(block: true): it => components.raw_block(it)
show raw.where(block: false): components_code.raw_not_block
show raw.where(block: true): it => components_code.raw_block(it)

show heading: components.heading
show heading: components_heading.heading

// Display the whole document
doc
Expand Down

0 comments on commit 337b061

Please sign in to comment.