@ca-plant-list/ca-plant-list 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ class BasePageRenderer {
6
6
  static render( outputDir, Taxa ) {
7
7
 
8
8
  // Copy static files
9
- fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 200 } );
9
+ fs.rmSync( outputDir, { force: true, recursive: true, maxRetries: 2, retryDelay: 300 } );
10
10
  // First copy default Jekyll files from package.
11
11
  fs.cpSync( Config.getPackageDir() + "/jekyll", outputDir, { recursive: true } );
12
12
  // Then copy Jekyll files from current dir (which may override default files).
package/lib/dataloader.js CHANGED
@@ -14,16 +14,22 @@ class DataLoader {
14
14
  return OPTION_DEFS;
15
15
  }
16
16
 
17
- static load( options ) {
17
+ static init( taxaDir ) {
18
18
 
19
19
  const defaultDataDir = Config.getPackageDir() + "/data";
20
- const taxaDir = options.datadir;
21
-
22
- console.log( "loading data" );
23
20
 
24
21
  Exceptions.init( taxaDir );
25
22
  Families.init( defaultDataDir );
26
23
  Genera.init( defaultDataDir );
24
+ }
25
+
26
+ static load( options ) {
27
+
28
+ const taxaDir = options.datadir;
29
+
30
+ console.log( "loading data" );
31
+
32
+ this.init( taxaDir );
27
33
  Taxa.init( taxaDir );
28
34
 
29
35
  }
package/lib/genera.js CHANGED
@@ -9,6 +9,11 @@ class Genera {
9
9
 
10
10
  const genusName = taxon.getGenusName();
11
11
  const genusData = this.#genera[ genusName ];
12
+ if ( !genusData ) {
13
+ console.log( taxon.getName() + " genus not found" );
14
+ return;
15
+ }
16
+
12
17
  if ( genusData.taxa === undefined ) {
13
18
  genusData.taxa = [];
14
19
  }
@@ -16,7 +21,7 @@ class Genera {
16
21
 
17
22
  const family = this.getFamily( genusName );
18
23
  if ( !family ) {
19
- console.log( taxon.getName() + " genus/family not found" );
24
+ console.log( taxon.getName() + " family not found" );
20
25
  return;
21
26
  }
22
27
  family.addTaxon( taxon );
package/lib/index.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import { BasePageRenderer } from "./basepagerenderer.js";
2
2
  import { Config } from "./config.js";
3
+ import { CSV } from "./csv.js";
4
+ import { DataLoader } from "./dataloader.js";
5
+ import { ErrorLog } from "./errorlog.js";
6
+ import { Exceptions } from "./exceptions.js";
7
+ import { Files } from "./files.js";
3
8
  import { HTML, HTML_OPTIONS } from "./html.js";
9
+ import { Taxa } from "./taxa.js";
10
+ import { Taxon } from "./taxon.js";
4
11
 
5
- export { BasePageRenderer, Config, HTML, HTML_OPTIONS };
12
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Taxa, Taxon };
package/lib/pagetaxon.js CHANGED
@@ -20,27 +20,17 @@ class PageTaxon extends HTMLPage {
20
20
  if ( jepsonID ) {
21
21
  links.push( Jepson.getEFloraLink( jepsonID ) );
22
22
  }
23
- const calRecNum = this.#taxon.getCalfloraID();
24
- if ( calRecNum ) {
25
- links.push(
26
- HTML.getLink(
27
- "https://www.calflora.org/app/taxon?crn=" + calRecNum,
28
- "Calflora",
29
- {},
30
- HTML_OPTIONS.OPEN_NEW
31
- )
32
- );
23
+ const cfLink = this.#taxon.getCalfloraTaxonLink();
24
+ if ( cfLink ) {
25
+ links.push( cfLink );
33
26
  }
34
- const iNatID = this.#taxon.getINatID();
35
- if ( iNatID ) {
36
- links.push(
37
- HTML.getLink(
38
- "https://www.inaturalist.org/taxa/" + iNatID,
39
- "iNaturalist",
40
- {},
41
- HTML_OPTIONS.OPEN_NEW
42
- )
43
- );
27
+ const iNatLink = this.#taxon.getINatTaxonLink();
28
+ if ( iNatLink ) {
29
+ links.push( iNatLink );
30
+ }
31
+ const rpiLink = this.#taxon.getRPITaxonLink();
32
+ if ( rpiLink ) {
33
+ links.push( rpiLink );
44
34
  }
45
35
  return links;
46
36
  }
package/lib/taxa.js CHANGED
@@ -62,6 +62,7 @@ class Taxa {
62
62
  jepsonID,
63
63
  row[ "calrecnum" ],
64
64
  row[ "inat id" ],
65
+ row[ "RPI ID" ],
65
66
  row[ "CRPR" ],
66
67
  row[ "CESA" ]
67
68
  );
package/lib/taxon.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Config } from "./config.js";
2
- import { ErrorLog } from "./errorlog.js";
3
2
  import { Genera } from "./genera.js";
4
3
  import { HTML, HTML_OPTIONS } from "./html.js";
5
4
  import { RarePlants } from "./rareplants.js";
@@ -12,13 +11,15 @@ class Taxon {
12
11
  #status;
13
12
  #jepsonID;
14
13
  #calRecNum;
14
+ #cfSyn;
15
15
  #iNatID;
16
16
  #iNatSyn;
17
+ #rpiID;
17
18
  #rankRPI;
18
19
  #cesa;
19
20
  #synonyms = [];
20
21
 
21
- constructor( name, commonNames, status, jepsonID, calRecNum, iNatID, rankRPI, cesa ) {
22
+ constructor( name, commonNames, status, jepsonID, calRecNum, iNatID, rpiID, rankRPI, cesa ) {
22
23
  this.#name = name;
23
24
  this.#genus = name.split( " " )[ 0 ];
24
25
  this.#commonNames = commonNames ? commonNames.split( "," ).map( t => t.trim() ) : [];
@@ -26,33 +27,50 @@ class Taxon {
26
27
  this.#jepsonID = jepsonID;
27
28
  this.#calRecNum = calRecNum;
28
29
  this.#iNatID = iNatID;
30
+ this.#rpiID = rpiID;
29
31
  this.#rankRPI = rankRPI;
30
32
  this.#cesa = cesa;
31
33
  Genera.addTaxon( this );
32
- if ( !calRecNum ) {
33
- ErrorLog.log( this.getName(), "has no Calflora ID" );
34
- }
35
- if ( !iNatID ) {
36
- ErrorLog.log( this.getName(), "has no iNat ID" );
37
- }
38
34
  }
39
35
 
40
36
  addSynonym( syn, type ) {
41
37
  this.#synonyms.push( syn );
42
- if ( type === "INAT" ) {
43
- // Synonyms should be in Jepson format, but store iNatName in iNat format (no var or subsp, space after x).
44
- this.#iNatSyn = syn;
38
+ switch ( type ) {
39
+ case "CF":
40
+ // Synonym is in Calflora format.
41
+ this.#cfSyn = syn;
42
+ break;
43
+ case "INAT":
44
+ // Synonyms should be in Jepson format, but store iNatName in iNat format (no var or subsp, space after x).
45
+ this.#iNatSyn = syn;
46
+ break;
45
47
  }
46
48
  }
47
49
 
48
50
  getCalfloraName() {
49
- return this.#name.replace( " subsp.", " ssp." ).replace( "×", "X" );
51
+ if ( this.#cfSyn ) {
52
+ return this.#cfSyn;
53
+ }
54
+ return this.getName().replace( " subsp.", " ssp." ).replace( "×", "X" );
50
55
  }
51
56
 
52
57
  getCalfloraID() {
53
58
  return this.#calRecNum;
54
59
  }
55
60
 
61
+ getCalfloraTaxonLink() {
62
+ const calfloraID = this.getCalfloraID();
63
+ if ( !calfloraID ) {
64
+ return;
65
+ }
66
+ return HTML.getLink(
67
+ "https://www.calflora.org/app/taxon?crn=" + calfloraID,
68
+ "Calflora",
69
+ {},
70
+ HTML_OPTIONS.OPEN_NEW
71
+ );
72
+ }
73
+
56
74
  getCESA() {
57
75
  return this.#cesa;
58
76
  }
@@ -65,9 +83,13 @@ class Taxon {
65
83
  return Genera.getFamily( this.#genus );
66
84
  }
67
85
 
68
- getFileName( ext = "html" ) {
86
+ getFileName( ext ) {
87
+ return Taxon.getFileName( this.getName(), ext );
88
+ }
89
+
90
+ static getFileName( name, ext = "html" ) {
69
91
  // Convert spaces to "-" and remove ".".
70
- return this.getName().replaceAll( " ", "-" ).replaceAll( ".", "" ) + "." + ext;
92
+ return name.replaceAll( " ", "-" ).replaceAll( ".", "" ) + "." + ext;
71
93
  }
72
94
 
73
95
  getGenus() {
@@ -97,6 +119,15 @@ class Taxon {
97
119
  return name.replace( / (subsp|var)\./, "" ).replace( "×", "× " );
98
120
  }
99
121
 
122
+ getINatTaxonLink() {
123
+ const iNatID = this.getINatID();
124
+ if ( !iNatID ) {
125
+ return "";
126
+ }
127
+ const link = HTML.getLink( "https://www.inaturalist.org/taxa/" + iNatID, "iNaturalist", {}, HTML_OPTIONS.OPEN_NEW );
128
+ return this.#iNatSyn ? ( link + " (" + this.#iNatSyn + ")" ) : link;
129
+ }
130
+
100
131
  getJepsonID() {
101
132
  return this.#jepsonID;
102
133
  }
@@ -105,6 +136,10 @@ class Taxon {
105
136
  return this.#name;
106
137
  }
107
138
 
139
+ getRPIID() {
140
+ return this.#rpiID;
141
+ }
142
+
108
143
  getRPIRank() {
109
144
  if ( !this.#rankRPI ) {
110
145
  return this.#rankRPI;
@@ -116,6 +151,15 @@ class Taxon {
116
151
  return this.#rankRPI;
117
152
  }
118
153
 
154
+ getRPITaxonLink() {
155
+ const rpiID = this.getRPIID();
156
+ if ( !rpiID ) {
157
+ return "";
158
+ }
159
+ const link = HTML.getLink( "https://rareplants.cnps.org/Plants/Details/" + rpiID, "CNPS Rare Plant Inventory", {}, HTML_OPTIONS.OPEN_NEW );
160
+ return link;
161
+ }
162
+
119
163
  getStatus() {
120
164
  return this.#status;
121
165
  }
@@ -136,6 +180,10 @@ class Taxon {
136
180
  return this.#synonyms;
137
181
  }
138
182
 
183
+ isCANative() {
184
+ return this.#status === "N" || this.#status === "NC";
185
+ }
186
+
139
187
  isNative() {
140
188
  return this.#status === "N";
141
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Tools to create Jekyll files for a website listing plants in an area of California.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,22 +10,7 @@
10
10
  "homepage": "https://github.com/ca-plants/ca-plant-list",
11
11
  "type": "module",
12
12
  "exports": {
13
- ".": "./lib/index.js",
14
- "./CSV": {
15
- "import": "./lib/csv.js"
16
- },
17
- "./DataLoader": {
18
- "import": "./lib/dataloader.js"
19
- },
20
- "./Exceptions": {
21
- "import": "./lib/exceptions.js"
22
- },
23
- "./Files": {
24
- "import": "./lib/files.js"
25
- },
26
- "./Taxa": {
27
- "import": "./lib/taxa.js"
28
- }
13
+ ".": "./lib/index.js"
29
14
  },
30
15
  "bin": {
31
16
  "ca-plant-list": "build-site.js"