Skip to content

Commit 7ed7fa5

Browse files
authoredJan 7, 2025
Allow CC-BY, CC-BY-SA, and CC0 licenses (typst#1521)
1 parent 03f2d2c commit 7ed7fa5

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed
 

‎README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ Required for submissions to this repository:
2929
address, homepage, or GitHub handle in angle brackets. The latter must start
3030
with an `@` character, and URLs must start with `http://` or `https://`.
3131
- `license`: The package's license. Must contain a valid SPDX-2 expression
32-
describing one or multiple [OSI-approved][OSI] licenses.
32+
describing one or multiple licenses that are either [OSI-approved][OSI]
33+
licenses or a version of CC-BY, CC-BY-SA, or CC0. We recommend you do not
34+
license your package using a Creative Commons license unless it is a
35+
derivative work of a CC-BY-SA-licensed work or if it is not primarily code,
36+
but content or data. In most other cases, [a free/open license specific to
37+
software is better suited for Typst packages](https://creativecommons.org/faq/#can-i-apply-a-creative-commons-license-to-software).
3338
- `description`: A short description of the package. Double-check this for
3439
grammar and spelling mistakes as it will appear in the [package list][list].
3540

‎bundler/Cargo.lock

+19-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bundler/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ flate2 = "1"
1313
ignore = "0.4"
1414
image = { version = "0.24.9", default-features = false, features = ["png", "webp", "webp-encoder"] }
1515
rayon = "1.0"
16+
regex = "1.11.1"
1617
semver = { version = "1", features = ["serde"] }
1718
serde = { version = "1", features = ["derive"] }
1819
serde_json = "1"

‎bundler/src/main.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use std::env::args;
88
use std::fs;
99
use std::io;
1010
use std::path::Path;
11+
use std::sync::LazyLock;
1112

1213
use anyhow::{bail, Context};
1314
use image::codecs::webp::{WebPEncoder, WebPQuality};
1415
use image::imageops::FilterType;
1516
use semver::Version;
17+
use spdx::LicenseId;
1618
use typst_syntax::package::{PackageInfo, PackageManifest, TemplateInfo, UnknownFields};
1719
use unicode_ident::{is_xid_continue, is_xid_start};
1820

@@ -106,7 +108,7 @@ fn main() -> anyhow::Result<()> {
106108
determine_timestamps(&paths, &mut index)?;
107109

108110
// Sort the index.
109-
index.sort_by_key(|info| (info.package.name.clone(), info.package.version.clone()));
111+
index.sort_by_key(|info| (info.package.name.clone(), info.package.version));
110112

111113
println!("Writing index.");
112114
fs::write(
@@ -247,8 +249,11 @@ fn parse_manifest(path: &Path, namespace: &str) -> anyhow::Result<PackageManifes
247249
.id()
248250
.context("license must not contain a referencer")?;
249251

250-
if !id.is_osi_approved() {
251-
bail!("license is not OSI approved: {}", id.full_name);
252+
if !id.is_osi_approved() && !is_allowed_cc(id) {
253+
bail!(
254+
"license is neither OSI approved nor an allowed CC license: {}",
255+
id.full_name
256+
);
252257
}
253258
}
254259

@@ -454,3 +459,11 @@ fn is_id_start(c: char) -> bool {
454459
fn is_id_continue(c: char) -> bool {
455460
is_xid_continue(c) || c == '_' || c == '-'
456461
}
462+
463+
// Check that a license is any version of CC-BY, CC-BY-SA, or CC0.
464+
fn is_allowed_cc(license: LicenseId) -> bool {
465+
static RE: LazyLock<regex::Regex> =
466+
LazyLock::new(|| regex::Regex::new(r"^CC(-BY|-BY-SA|0)-[0-9]\.[0-9](-[A-Z]+)?$").unwrap());
467+
468+
RE.is_match(license.name)
469+
}

0 commit comments

Comments
 (0)
Please sign in to comment.