@ca-plant-list/ca-plant-list 0.1.9 → 0.1.11

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/families.js CHANGED
@@ -1,8 +1,8 @@
1
- import * as fs from "node:fs";
2
1
  import { HTMLPage } from "./htmlpage.js";
3
2
  import { HTML } from "./html.js";
4
3
  import { Jepson } from "./jepson.js";
5
4
  import { Taxa } from "./taxa.js";
5
+ import { Files } from "./files.js";
6
6
 
7
7
  class Families {
8
8
 
@@ -13,7 +13,7 @@ class Families {
13
13
  }
14
14
 
15
15
  static init( dataDir ) {
16
- this.#families = JSON.parse( fs.readFileSync( dataDir + "/families.json" ) );
16
+ this.#families = JSON.parse( Files.read( dataDir + "/families.json" ) );
17
17
  for ( const [ k, v ] of Object.entries( this.#families ) ) {
18
18
  this.#families[ k ] = new Family( k, { id: v } );
19
19
  }
package/lib/files.js CHANGED
@@ -25,6 +25,10 @@ class Files {
25
25
  fs.writeFileSync( targetFileName, Buffer.from( buffer ) );
26
26
  }
27
27
 
28
+ static mkdir( path ) {
29
+ fs.mkdirSync( path, { recursive: true } );
30
+ }
31
+
28
32
  static read( path ) {
29
33
  return fs.readFileSync( path, "utf8" );
30
34
  }
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 + ">";
@@ -57,6 +57,11 @@ export class HTML {
57
57
  return html + ">" + this.escapeText( linkText ) + "</a >";
58
58
  }
59
59
 
60
+ static getToolTip( text, tooltip ) {
61
+ const func = text.charAt( 0 ) === "<" ? HTML.wrap : HTML.textElement;
62
+ return func( "span", text + " ⓘ", { title: tooltip } );
63
+ }
64
+
60
65
  static renderAttribute( n, v ) {
61
66
  return " " + n + "=\"" + this.escapeAttribute( v ) + "\"";
62
67
  }
@@ -70,11 +75,11 @@ export class HTML {
70
75
  }
71
76
 
72
77
  static textElement( elName, text, attributes = {} ) {
73
- return this.#getElement( elName, text, attributes, true );
78
+ return HTML.#getElement( elName, text, attributes, true );
74
79
  }
75
80
 
76
81
  static wrap( elName, text, attributes = {} ) {
77
- return this.#getElement( elName, text, attributes, false );
82
+ return HTML.#getElement( elName, text, attributes, false );
78
83
  }
79
84
 
80
85
  }
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export class Files {
2
2
  static createFileFromStream(fileName: any, inStream: any): Promise<any>;
3
3
  static exists(path: any): boolean;
4
4
  static fetch(url: any, targetFileName: any): Promise<void>;
5
+ static mkdir(path: any): void;
5
6
  static read(path: any): string;
6
7
  static write(path: any, data: any): void;
7
8
  static zipFileExtract(zipFilePath: any, fileNameToUnzip: any, targetFilePath: any): Promise<void>;
@@ -21,6 +22,7 @@ export class HTML {
21
22
  static getElement(elName: any, text: any, attributes?: {}, options?: number): string;
22
23
  static "__#2@#getElement"(elName: any, text: any, attributes: any, escape: any): string;
23
24
  static getLink(href: any, linkText: any, attributes?: {}, options?: number): string;
25
+ static getToolTip(text: any, tooltip: any): string;
24
26
  static renderAttribute(n: any, v: any): string;
25
27
  static renderAttributes(attributes: any): string;
26
28
  static textElement(elName: any, text: any, attributes?: {}): string;
@@ -29,4 +31,5 @@ export class HTML {
29
31
  export class Jekyll {
30
32
  static hasInclude(baseDir: any, path: any): boolean;
31
33
  static include(path: any): string;
34
+ static writeInclude(baseDir: any, path: any, data: any): void;
32
35
  }
package/lib/index.js CHANGED
@@ -4,10 +4,11 @@ import { CSV } from "./csv.js";
4
4
  import { DataLoader } from "./dataloader.js";
5
5
  import { ErrorLog } from "./errorlog.js";
6
6
  import { Exceptions } from "./exceptions.js";
7
+ import { Families } from "./families.js";
7
8
  import { Files } from "./files.js";
8
9
  import { HTML, HTML_OPTIONS } from "./html.js";
9
10
  import { Jekyll } from "./jekyll.js";
10
11
  import { Taxa } from "./taxa.js";
11
12
  import { Taxon } from "./taxon.js";
12
13
 
13
- export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Files, HTML, HTML_OPTIONS, Jekyll, Taxa, Taxon };
14
+ export { BasePageRenderer, Config, CSV, DataLoader, ErrorLog, Exceptions, Families, Files, HTML, HTML_OPTIONS, Jekyll, Taxa, Taxon };
package/lib/jekyll.js CHANGED
@@ -7,7 +7,12 @@ class Jekyll {
7
7
  }
8
8
 
9
9
  static include( path ) {
10
- return "{%include " + path + "%}";
10
+ // This works for .md includes; should have conditional logic to detect other types.
11
+ return "{% capture my_include %}{% include " + path + " %}{% endcapture %}{{ my_include | markdownify }}";
12
+ }
13
+
14
+ static writeInclude( baseDir, path, data ) {
15
+ Files.write( baseDir + "/_includes/" + path, data );
11
16
  }
12
17
 
13
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ca-plant-list/ca-plant-list",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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": {