@ca-plant-list/ca-plant-list 0.1.8 → 0.1.10

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.
@@ -1,3 +1,5 @@
1
+ import { Utils } from "./utils.js";
2
+
1
3
  const MIN_LEN = 2;
2
4
  const MAX_RESULTS = 50;
3
5
 
@@ -75,9 +77,7 @@ class Search {
75
77
  const name = match[ 0 ];
76
78
  const syn = match[ 2 ];
77
79
  const td1 = document.createElement( "td" );
78
- const link = document.createElement( "a" );
79
- link.setAttribute( "href", "./" + name.replaceAll( ".", "" ).replaceAll( " ", "-" ) + ".html" );
80
- link.textContent = name;
80
+ const link = Utils.domTaxonLink( name );
81
81
  td1.appendChild( link );
82
82
  if ( syn ) {
83
83
  td1.appendChild( document.createTextNode( " (" + syn + ")" ) );
@@ -0,0 +1,26 @@
1
+ class Utils {
2
+
3
+ static domElement( name, attributes = {}, content ) {
4
+ const e = document.createElement( name );
5
+ for ( const [ k, v ] of Object.entries( attributes ) ) {
6
+ e.setAttribute( k, v );
7
+ }
8
+ if ( content ) {
9
+ e.textContent = content;
10
+ }
11
+ return e;
12
+ }
13
+
14
+ static domLink( href, text, attributes = {} ) {
15
+ const e = this.domElement( "a", Object.assign( { href: href }, attributes ) );
16
+ e.textContent = text;
17
+ return e;
18
+ }
19
+
20
+ static domTaxonLink( name ) {
21
+ return this.domLink( "./" + name.replaceAll( ".", "" ).replaceAll( " ", "-" ) + ".html", name );
22
+ }
23
+
24
+ }
25
+
26
+ export { Utils };
package/lib/files.js CHANGED
@@ -14,6 +14,10 @@ class Files {
14
14
  return new Promise( ( resolve ) => { implementation( fileName, inStream, resolve ); } );
15
15
  }
16
16
 
17
+ static exists( path ) {
18
+ return fs.existsSync( path );
19
+ }
20
+
17
21
  static async fetch( url, targetFileName ) {
18
22
  const response = await fetch( url );
19
23
  const data = await response.blob();
@@ -21,12 +25,16 @@ class Files {
21
25
  fs.writeFileSync( targetFileName, Buffer.from( buffer ) );
22
26
  }
23
27
 
28
+ static mkdir( path ) {
29
+ fs.mkdirSync( path, { recursive: true } );
30
+ }
31
+
24
32
  static read( path ) {
25
33
  return fs.readFileSync( path, "utf8" );
26
34
  }
27
35
 
28
36
  static write( path, data ) {
29
- if ( fs.existsSync( path ) ) {
37
+ if ( this.exists( path ) ) {
30
38
  throw new Error( path + " already exists" );
31
39
  }
32
40
  fs.writeFileSync( path, data );
package/lib/html.js CHANGED
@@ -38,7 +38,7 @@ export class HTML {
38
38
  static #getElement( elName, text, attributes, escape ) {
39
39
  let html = "<" + elName;
40
40
  html += this.renderAttributes( attributes );
41
- if ( escape ) {
41
+ if ( escape && ( typeof text === "string" ) ) {
42
42
  text = this.escapeText( text );
43
43
  }
44
44
  html += ">" + text + "</" + elName + ">";
package/lib/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export class Files {
2
2
  static createFileFromStream(fileName: any, inStream: any): Promise<any>;
3
+ static exists(path: any): boolean;
3
4
  static fetch(url: any, targetFileName: any): Promise<void>;
5
+ static mkdir(path: any): void;
4
6
  static read(path: any): string;
5
7
  static write(path: any, data: any): void;
6
8
  static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
@@ -25,3 +27,8 @@ export class HTML {
25
27
  static textElement(elName: any, text: any, attributes?: {}): string;
26
28
  static wrap(elName: any, text: any, attributes?: {}): string;
27
29
  }
30
+ export class Jekyll {
31
+ static hasInclude(baseDir: any, path: any): boolean;
32
+ static include(path: any): string;
33
+ static writeInclude(baseDir: any, path: any, data: any): void;
34
+ }
package/lib/index.js CHANGED
@@ -6,7 +6,8 @@ import { ErrorLog } from "./errorlog.js";
6
6
  import { Exceptions } from "./exceptions.js";
7
7
  import { Files } from "./files.js";
8
8
  import { HTML, HTML_OPTIONS } from "./html.js";
9
+ import { Jekyll } from "./jekyll.js";
9
10
  import { Taxa } from "./taxa.js";
10
11
  import { Taxon } from "./taxon.js";
11
12
 
12
- export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Taxa, Taxon };
13
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Jekyll, Taxa, Taxon };
package/lib/jekyll.js ADDED
@@ -0,0 +1,19 @@
1
+ import { Files } from "./files.js";
2
+
3
+ class Jekyll {
4
+
5
+ static hasInclude( baseDir, path ) {
6
+ return Files.exists( baseDir + "/_includes/" + path );
7
+ }
8
+
9
+ static include( path ) {
10
+ return "{%include " + path + "%}";
11
+ }
12
+
13
+ static writeInclude( baseDir, path, data ) {
14
+ Files.write( baseDir + "/_includes/" + path, data );
15
+ }
16
+
17
+ }
18
+
19
+ export { Jekyll };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
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": {
@@ -11,7 +11,9 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": "./lib/index.js",
14
- "./HTML": "./lib/HTML.js"
14
+ "./Files": "./lib/files.js",
15
+ "./HTML": "./lib/html.js",
16
+ "./Jekyll": "./lib/jekyll.js"
15
17
  },
16
18
  "types": "./lib/index.d.ts",
17
19
  "bin": {
@@ -27,4 +29,4 @@
27
29
  "eslint": "^8.26.0",
28
30
  "typescript": "^4.9.3"
29
31
  }
30
- }
32
+ }