Skip to content

Commit

Permalink
Merge branch 'typst:main' into release-0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisely authored Feb 4, 2025
2 parents c3b3dff + c3dcffd commit 7642f5d
Show file tree
Hide file tree
Showing 3,511 changed files with 431,489 additions and 19 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ Required for submissions to this repository:
address, homepage, or GitHub handle in angle brackets. The latter must start
with an `@` character, and URLs must start with `http://` or `https://`.
- `license`: The package's license. Must contain a valid SPDX-2 expression
describing one or multiple [OSI-approved][OSI] licenses.
describing one or multiple licenses that are either [OSI-approved][OSI]
licenses or a version of CC-BY, CC-BY-SA, or CC0. We recommend you do not
license your package using a Creative Commons license unless it is a
derivative work of a CC-BY-SA-licensed work or if it is not primarily code,
but content or data. In most other cases, [a free/open license specific to
software is better suited for Typst packages](https://creativecommons.org/faq/#can-i-apply-a-creative-commons-license-to-software).
- `description`: A short description of the package. Double-check this for
grammar and spelling mistakes as it will appear in the [package list][list].

Expand Down
25 changes: 19 additions & 6 deletions bundler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ flate2 = "1"
ignore = "0.4"
image = { version = "0.24.9", default-features = false, features = ["png", "webp", "webp-encoder"] }
rayon = "1.0"
regex = "1.11.1"
semver = { version = "1", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
57 changes: 46 additions & 11 deletions bundler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use std::env::args;
use std::fs;
use std::io;
use std::path::Path;
use std::sync::LazyLock;

use anyhow::{bail, Context};
use image::codecs::webp::{WebPEncoder, WebPQuality};
use image::imageops::FilterType;
use semver::Version;
use spdx::LicenseId;
use typst_syntax::package::{PackageInfo, PackageManifest, TemplateInfo, UnknownFields};
use unicode_ident::{is_xid_continue, is_xid_start};

Expand Down Expand Up @@ -48,8 +50,12 @@ fn main() -> anyhow::Result<()> {
.max_depth(1)
.sort_by_file_name()
{
let entry = entry?;
if !entry.metadata()?.is_dir() {
let entry = entry.context("cannot read entries in directory \"packages\".\nHint: does the current working directory contain a directory \"packages\"?")?;
if !entry
.metadata()
.context("cannot read metadata for entries in directory \"packages\"")?
.is_dir()
{
continue;
}

Expand All @@ -66,11 +72,27 @@ fn main() -> anyhow::Result<()> {
let mut paths = vec![];
let mut index = vec![];
let mut package_errors = vec![];
fs::create_dir_all(namespace_dir.join(THUMBS_DIR))?;
fs::create_dir_all(namespace_dir.join(THUMBS_DIR))
.context("could not create output directory")?;

for entry in walkdir::WalkDir::new(&path).min_depth(2).max_depth(2) {
let entry = entry?;
if !entry.metadata()?.is_dir() {
let entry = entry.with_context(|| {
format!(
"could not read item in namespace directory \"packages/{}\"",
namespace
)
})?;

if !entry
.metadata()
.with_context(|| {
format!(
"could not read metadata for item in namespace directory \"packages/{}\"",
namespace
)
})?
.is_dir()
{
bail!(
"{}: a package directory may only contain version sub-directories, not files.",
entry.path().display()
Expand Down Expand Up @@ -103,19 +125,21 @@ fn main() -> anyhow::Result<()> {
}

println!("Determining timestamps.");
determine_timestamps(&paths, &mut index)?;
determine_timestamps(&paths, &mut index)
.context("failed to determine package creation timestamps")?;

// Sort the index.
index.sort_by_key(|info| (info.package.name.clone(), info.package.version.clone()));
index.sort_by_key(|info| (info.package.name.clone(), info.package.version));

println!("Writing index.");
fs::write(
namespace_dir.join("index.json"),
serde_json::to_vec(&index.iter().map(IndexPackageInfo::from).collect::<Vec<_>>())?,
serde_json::to_vec(&index.iter().map(IndexPackageInfo::from).collect::<Vec<_>>())
.context("serialization of compact package index failed")?,
)?;
fs::write(
namespace_dir.join("index.full.json"),
serde_json::to_vec(&index)?,
serde_json::to_vec(&index).context("serialization of full package index failed")?,
)?;

if !package_errors.is_empty() {
Expand Down Expand Up @@ -247,8 +271,11 @@ fn parse_manifest(path: &Path, namespace: &str) -> anyhow::Result<PackageManifes
.id()
.context("license must not contain a referencer")?;

if !id.is_osi_approved() {
bail!("license is not OSI approved: {}", id.full_name);
if !id.is_osi_approved() && !is_allowed_cc(id) {
bail!(
"license is neither OSI approved nor an allowed CC license: {}",
id.full_name
);
}
}

Expand Down Expand Up @@ -454,3 +481,11 @@ fn is_id_start(c: char) -> bool {
fn is_id_continue(c: char) -> bool {
is_xid_continue(c) || c == '_' || c == '-'
}

// Check that a license is any version of CC-BY, CC-BY-SA, or CC0.
fn is_allowed_cc(license: LicenseId) -> bool {
static RE: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r"^CC(-BY|-BY-SA|0)-[0-9]\.[0-9](-[A-Z]+)?$").unwrap());

RE.is_match(license.name)
}
21 changes: 21 additions & 0 deletions packages/preview/abbr/0.1.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Jonathan Halmen

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.
89 changes: 89 additions & 0 deletions packages/preview/abbr/0.1.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Abbr -- eviations made simple

Short package for making the handling of abbreviations, acronyms, and
initialisms _easy_.

Declare your abbreviations anywhere, use everywhere -- they get picked up
automatically.

## Features
- Automatic plurals, with optional overrides.
- Automatic 1- or 2-column sorted list of abbreviations
- Automatic links to list of abbreviations, if included.
- styling configuration

## Getting started

```typst
#import "@preview/abbr:0.1.1"
#abbr.list()
#abbr.make(
("PDE", "Partial Differential Equation"),
("BC", "Boundary Condition"),
("DOF", "Degree of Freedom", "Degrees of Freedom"),
)
= Constrained Equations
#abbr.pla[BC] constrain the #abbr.pla[DOF] of the #abbr.pla[PDE] they act on.\
#abbr.pla[BC] constrain the #abbr.pla[DOF] of the #abbr.pla[PDE] they act on.
#abbr.add("MOL", "Method of Lines")
The #abbr.a[MOL] is a procedure to solve #abbr.pla[PDE] in time.
```
![](example.png)


## API Reference
### Configuration
- **style**`(func)`\
Set a callable for styling the short version in the text.

### Creation
- **add**`(short, long, long-plural)`\
Add single entry to use later.\
`long-plural` is *optional*, if not given but used, an `s` is appended to create a
plural.

- **make**`(list, of, entries)`\
Add multiple entries, each of the form `(short, long, long-plural)`.

### Listing
- **list**`(title)`\
Create an outline with all abbreviations in short and expanded form

### Usage
- **s**`()` - short\
force short form of abbreviation
- **l**`()` - long\
force long form of abbreviation
- **a**`()` - auto\
first occurence will be long form, the rest short
- **pls**`()` - plural short\
plural short form
- **pll**`()` - plural long\
plural long form
- **pl**`()` - plural automatic\
plural. first occurence long form, then short


## Why yet another Abbreviations package?

This mostly exists because I started working on it before checking if somebody
already made a package for it. After I saw that e.g. `acrotastic` exists, I kept
convincing myself a new package still makes sense for the following reasons:
* Getting to know Typst
* More automatic handling than other packages
* Ability to keep keys as [Content] instead of having to stringify everything

Especially the last part seems to lower the friction of writing for me. It seems
silly, I know.

## Contributing

Please head over to the [hub](https://sr.ht/~slowjo/typst-packages) to find the
mailing list and ticket tracker.

Or simply reach out on IRC ([#typst on
libera.chat](https://web.libera.chat/gamja/?autojoin=#typst))!
Loading

0 comments on commit 7642f5d

Please sign in to comment.