@@ -8,11 +8,13 @@ use std::env::args;
8
8
use std:: fs;
9
9
use std:: io;
10
10
use std:: path:: Path ;
11
+ use std:: sync:: LazyLock ;
11
12
12
13
use anyhow:: { bail, Context } ;
13
14
use image:: codecs:: webp:: { WebPEncoder , WebPQuality } ;
14
15
use image:: imageops:: FilterType ;
15
16
use semver:: Version ;
17
+ use spdx:: LicenseId ;
16
18
use typst_syntax:: package:: { PackageInfo , PackageManifest , TemplateInfo , UnknownFields } ;
17
19
use unicode_ident:: { is_xid_continue, is_xid_start} ;
18
20
@@ -106,7 +108,7 @@ fn main() -> anyhow::Result<()> {
106
108
determine_timestamps ( & paths, & mut index) ?;
107
109
108
110
// 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 ) ) ;
110
112
111
113
println ! ( "Writing index." ) ;
112
114
fs:: write (
@@ -247,8 +249,11 @@ fn parse_manifest(path: &Path, namespace: &str) -> anyhow::Result<PackageManifes
247
249
. id ( )
248
250
. context ( "license must not contain a referencer" ) ?;
249
251
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
+ ) ;
252
257
}
253
258
}
254
259
@@ -454,3 +459,11 @@ fn is_id_start(c: char) -> bool {
454
459
fn is_id_continue ( c : char ) -> bool {
455
460
is_xid_continue ( c) || c == '_' || c == '-'
456
461
}
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