@ca-plant-list/ca-plant-list 0.4.26 → 0.4.27

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.
Files changed (42) hide show
  1. package/data/taxa.csv +1 -0
  2. package/generators/eleventy/layouts/h1.njk +6 -0
  3. package/generators/eleventy/layouts/html.njk +55 -0
  4. package/lib/basepagerenderer.js +35 -15
  5. package/lib/config.js +5 -3
  6. package/lib/ebook/ebookpage.js +1 -4
  7. package/lib/ebook/ebooksitegenerator.js +4 -12
  8. package/lib/ebook/glossarypages.js +1 -3
  9. package/lib/ebook/plantbook.js +1 -1
  10. package/lib/files.js +1 -0
  11. package/lib/htmltaxon.js +8 -19
  12. package/lib/index.d.ts +20 -8
  13. package/lib/index.js +4 -2
  14. package/lib/jekyll.js +40 -59
  15. package/lib/markdown.js +3 -5
  16. package/lib/sitegenerator.js +68 -12
  17. package/lib/types.js +4 -0
  18. package/lib/utils/eleventyGenerator.js +82 -0
  19. package/lib/utils/htmlFragments.js +19 -0
  20. package/lib/web/glossarypages.js +6 -10
  21. package/lib/web/pageFamily.js +14 -14
  22. package/lib/web/pageGeneric.js +78 -0
  23. package/lib/web/{pagetaxon.js → pageTaxon.js} +4 -4
  24. package/lib/web/pageTaxonList.js +53 -0
  25. package/lib/{pagerenderer.js → web/renderAllPages.js} +38 -80
  26. package/package.json +12 -10
  27. package/scripts/build-site.js +20 -52
  28. package/static/assets/js/nameSearchData.js +2 -0
  29. package/{jekyll → static}/assets/js/name_search.js +12 -14
  30. package/static/name_search.html +15 -0
  31. package/jekyll/_includes/glossary.html +0 -0
  32. package/jekyll/name_search.html +0 -17
  33. package/lib/genericpage.js +0 -88
  34. /package/{jekyll → generators}/_includes/analytics.html +0 -0
  35. /package/{jekyll → generators}/_includes/menu_extra.html +0 -0
  36. /package/{jekyll → generators/jekyll}/_config.yml +0 -0
  37. /package/{jekyll → generators/jekyll}/_layouts/default.html +0 -0
  38. /package/{jekyll → generators/jekyll}/_layouts/html.html +0 -0
  39. /package/{jekyll → static}/assets/css/main.css +0 -0
  40. /package/{jekyll → static}/assets/js/ui.js +0 -0
  41. /package/{jekyll → static}/assets/js/utils.js +0 -0
  42. /package/{jekyll → static}/index.md +0 -0
@@ -1,76 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import * as child_process from "node:child_process";
4
- import * as path from "node:path";
5
3
  import { Config } from "../lib/config.js";
6
- import { PageRenderer } from "../lib/pagerenderer.js";
4
+ import { PageRenderer } from "../lib/web/renderAllPages.js";
7
5
  import { Files } from "../lib/files.js";
8
6
  import { Program } from "../lib/program.js";
9
7
  import { Taxa } from "../lib/taxonomy/taxa.js";
10
8
  import { ErrorLog } from "../lib/errorlog.js";
11
9
 
12
- class JekyllRenderer {
13
- #srcDir = "./output";
14
- #destDir = "./public";
15
-
16
- async renderPages() {
17
- /**
18
- * @param {string[]} configFiles
19
- * @param {string} dir
20
- * @param {string} name
21
- */
22
- function addConfigFile(configFiles, dir, name) {
23
- const fullPath = path.join(dir, name);
24
- if (Files.exists(fullPath)) {
25
- configFiles.push(fullPath);
26
- }
27
- }
28
-
29
- // Remove existing files.
30
- Files.rmDir(this.#destDir);
31
-
32
- const options = [
33
- "--source",
34
- this.#srcDir,
35
- "--destination",
36
- this.#destDir,
37
- ];
38
-
39
- // Find out what config files are available.
40
- /** @type {string[]} */
41
- const configFiles = [];
42
- addConfigFile(configFiles, this.#srcDir, "_config.yml");
43
- addConfigFile(configFiles, this.#srcDir, "_config-local.yml");
44
- addConfigFile(configFiles, ".", "_config-dev.yml");
45
- options.push("--config", `"${configFiles.join()}"`);
46
-
47
- const result = child_process.execSync(
48
- "bundle exec jekyll build " + options.join(" "),
49
- );
50
- console.log(result.toString());
51
- }
52
- }
53
-
54
10
  /**
55
- * @param {import("commander").OptionValues} options
11
+ * @param {{outputdir:string,datadir:string,webdir:string,showFlowerErrors:boolean,render:boolean}} options
56
12
  */
57
13
  async function build(options) {
58
- Files.rmDir(options.outputdir);
59
- const errorLog = new ErrorLog(options.outputdir + "/errors.tsv");
14
+ console.info("generating templates");
15
+ const outputDir = options.outputdir;
16
+ Files.rmDir(outputDir);
17
+ const errorLog = new ErrorLog(outputDir + "/errors.tsv");
60
18
  const taxa = new Taxa(
61
19
  Program.getIncludeList(options.datadir),
62
20
  errorLog,
63
21
  options.showFlowerErrors,
64
22
  );
65
- PageRenderer.render(options.outputdir, new Config(options.datadir), taxa);
23
+ const config = new Config(options.datadir);
24
+ const generator = PageRenderer.newSiteGenerator(config, outputDir);
25
+ PageRenderer.renderAll(generator, config, taxa);
66
26
  errorLog.write();
67
27
 
68
- console.log("generating site");
69
- const r = new JekyllRenderer();
70
- await r.renderPages();
28
+ if (options.render) {
29
+ console.info("generating site");
30
+ Files.rmDir(options.webdir);
31
+ await generator.generate(options.webdir);
32
+ }
71
33
  }
72
34
 
73
35
  const program = Program.getProgram();
36
+ program.option(
37
+ "--no-render",
38
+ "Do not render full HTML output (only build the templates)",
39
+ );
40
+ program.option("-w, --webdir", "Directory for fully processed files", "public");
41
+
74
42
  program.action(build);
75
43
 
76
44
  await program.parseAsync();
@@ -0,0 +1,2 @@
1
+ /** @type {import("../../../lib/types.js").NameSearchData[]} */
2
+ export const NAMES = [];
@@ -1,8 +1,8 @@
1
+ import { NAMES } from "./nameSearchData.js";
1
2
  import { Utils } from "./utils.js";
2
3
 
3
4
  /**
4
- * @typedef {[string]|[string,string]|[string,string|undefined,string[]]} RawSearchData
5
- * @typedef {{raw:RawSearchData,searchSci:string,searchCommon?:string,synonyms?:string[]}} SearchData
5
+ * @typedef {{raw:import("../../../lib/types.js").NameSearchData,searchSci:string,searchCommon?:string,synonyms?:string[]}} SearchData
6
6
  */
7
7
 
8
8
  const MIN_LEN = 2;
@@ -52,9 +52,9 @@ class Search {
52
52
  // Include any matching synonyms.
53
53
  for (const index of syns) {
54
54
  matches.push([
55
- taxon.raw[0],
56
- taxon.raw[1],
57
- taxon.raw[2] ? taxon.raw[2][index] : undefined,
55
+ taxon.raw.t,
56
+ taxon.raw.c,
57
+ taxon.raw.s ? taxon.raw.s[index] : undefined,
58
58
  ]);
59
59
  }
60
60
  } else {
@@ -62,7 +62,7 @@ class Search {
62
62
  const namesMatch =
63
63
  name.includes(value) || (cn && cn.includes(value));
64
64
  if (namesMatch) {
65
- matches.push([taxon.raw[0], taxon.raw[1]]);
65
+ matches.push([taxon.raw.t, taxon.raw.c]);
66
66
  }
67
67
  }
68
68
  }
@@ -146,23 +146,21 @@ class Search {
146
146
  /** @type {SearchData[]} */
147
147
  const searchData = [];
148
148
 
149
- /** @type {RawSearchData[]} */
150
- // @ts-ignore
151
- // eslint-disable-next-line no-undef
149
+ /** @type {import("../../../lib/types.js").NameSearchData[]} */
152
150
  const names = NAMES;
153
151
 
154
152
  for (const taxon of names) {
155
153
  /** @type {SearchData} */
156
154
  const taxonData = {
157
155
  raw: taxon,
158
- searchSci: this.#normalizeName(taxon[0]),
156
+ searchSci: this.#normalizeName(taxon.t),
159
157
  };
160
- if (taxon[1]) {
161
- taxonData.searchCommon = taxon[1].toLowerCase();
158
+ if (taxon.c) {
159
+ taxonData.searchCommon = taxon.c.toLowerCase();
162
160
  }
163
- if (taxon[2]) {
161
+ if (taxon.s) {
164
162
  const syns = [];
165
- for (const syn of taxon[2]) {
163
+ for (const syn of taxon.s) {
166
164
  syns.push(this.#normalizeName(syn));
167
165
  }
168
166
  taxonData.synonyms = syns;
@@ -0,0 +1,15 @@
1
+ ---
2
+ title: Name Search
3
+ js: name_search.js
4
+ ---
5
+
6
+ <form id="search_form">
7
+ <input type="text" id="name" />
8
+ <label for="name"
9
+ >Search for scientific name, common name, or synonym.</label
10
+ >
11
+ </form>
12
+
13
+ <div class="section" id="message"></div>
14
+
15
+ <table id="results"></table>
File without changes
@@ -1,17 +0,0 @@
1
- ---
2
- title: Name Search
3
- js: name_search.js
4
- ---
5
-
6
- <script>
7
- const NAMES = {% include names.json %};
8
- </script>
9
-
10
- <form id="search_form">
11
- <input type="text" id="name">
12
- <label for="name">Search for scientific name, common name, or synonym.</label>
13
- </form>
14
-
15
- <div class="section" id="message"></div>
16
-
17
- <table id="results"></table>
@@ -1,88 +0,0 @@
1
- import { Config } from "./config.js";
2
- import { Files } from "./files.js";
3
- import { HTML } from "./html.js";
4
- import { Jekyll } from "./jekyll.js";
5
- import { Markdown } from "./markdown.js";
6
-
7
- class GenericPage {
8
- #outputDir;
9
- #title;
10
- #baseFileName;
11
- #js;
12
-
13
- /**
14
- * @param {string} outputDir
15
- * @param {string} title
16
- * @param {string} baseFileName
17
- * @param {string} [js]
18
- */
19
- constructor(outputDir, title, baseFileName, js) {
20
- this.#outputDir = outputDir;
21
- this.#title = title;
22
- this.#baseFileName = baseFileName;
23
- this.#js = js;
24
- }
25
-
26
- getBaseFileName() {
27
- return this.#baseFileName;
28
- }
29
-
30
- getDefaultIntro() {
31
- let html = this.getFrontMatter();
32
- return html + this.getMarkdown();
33
- }
34
-
35
- getFrontMatter() {
36
- return (
37
- "---\n" +
38
- 'title: "' +
39
- this.#title +
40
- '"\n' +
41
- (this.#js ? "js: " + this.#js + "\n" : "") +
42
- "---\n"
43
- );
44
- }
45
-
46
- getMarkdown() {
47
- // Include site-specific markdown.
48
- let html = this.#getMarkdown("intros");
49
-
50
- // Include package markdown.
51
- const mdPath =
52
- Config.getPackageDir() + "/data/text/" + this.#baseFileName + ".md";
53
- const markdownHTML = Markdown.fileToHTML(mdPath);
54
- if (markdownHTML) {
55
- html += HTML.wrap("div", markdownHTML, { class: "section" });
56
- }
57
-
58
- return html;
59
- }
60
-
61
- /**
62
- * @param {string} path
63
- */
64
- #getMarkdown(path) {
65
- const textPath = path + "/" + this.#baseFileName + ".md";
66
- if (!Jekyll.hasInclude(this.#outputDir, textPath)) {
67
- return "";
68
- }
69
- return HTML.wrap("div", Jekyll.include(textPath), { class: "section" });
70
- }
71
-
72
- getOutputDir() {
73
- return this.#outputDir;
74
- }
75
-
76
- getTitle() {
77
- return this.#title;
78
- }
79
-
80
- /**
81
- * @param {string} html
82
- */
83
- writeFile(html) {
84
- Files.write(this.#outputDir + "/" + this.#baseFileName + ".html", html);
85
- }
86
- }
87
-
88
- export { GenericPage };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes