Skip to content

Commit

Permalink
chore: standardize Calflora observation link
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 committed Feb 7, 2025
1 parent 90c7a93 commit cb05cf7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
19 changes: 19 additions & 0 deletions lib/externalsites.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
export class ExternalSites {
/**
* @param {import("./types.js").Taxon} taxon
* @param {import("./types.js").Config} config
* @returns {URL|undefined}
*/
static getCalfloraObsLink(taxon, config) {
const name = taxon.getCalfloraName();
if (!name) {
return;
}
const url = new URL(
"https://www.calflora.org/entry/observ.html?track=m#srch=t&grezc=5&cols=b&lpcli=t&cc=" +
config.getCountyCodes().join("!") +
"&incobs=f&taxon=" +
name,
);
return url;
}

/**
* @param {import("./types.js").Taxon} taxon
* @returns {URL|undefined}
Expand Down
10 changes: 8 additions & 2 deletions lib/htmltaxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const DEFAULT_TAXA_COLUMNS = [

/** @type {Object<string,{label:string,href:function(import("./types.js").Taxon,import("./types.js").Config):URL|undefined}>} */
const OBSLINKS = {
calflora: {
label: "Calflora",
href: (taxon, config) =>
ExternalSites.getCalfloraObsLink(taxon, config),
},
cch: {
label: "CCH2",
href: (taxon, config) => ExternalSites.getCCH2ObsLink(taxon, config),
Expand Down Expand Up @@ -110,10 +115,11 @@ class HTMLTaxon {
* @param {import("./types.js").Taxon} taxon
* @param {import("./types.js").Config} config
* @param {import("./index.js").RefSourceCode} sourceCode
* @param {string} [label]
*/
static addObsLink(links, taxon, config, sourceCode) {
static addObsLink(links, taxon, config, sourceCode, label) {
const source = OBSLINKS[sourceCode];
this.addLink(links, source.href(taxon, config), source.label);
this.addLink(links, source.href(taxon, config), label ?? source.label);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class HTMLTaxon {
taxon: Taxon,
config: Config,
sourceCode: RefSourceCode,
label?: string,
): void;
static addRefLink(
links: string[],
Expand Down
14 changes: 2 additions & 12 deletions lib/web/pagetaxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,10 @@ export class PageTaxon extends GenericPage {
}

#getObsLinks() {
/** @type {string[]} */
const links = [];
links.push(
HTML.getLink(
"https://www.calflora.org/entry/observ.html?track=m#srch=t&grezc=5&cols=b&lpcli=t&cc=" +
this.#config.getCountyCodes().join("!") +
"&incobs=f&taxon=" +
this.#taxon.getCalfloraName().replaceAll(" ", "+"),
"Calflora",
{},
true,
),
);

HTMLTaxon.addObsLink(links, this.#taxon, this.#config, "inat");
HTMLTaxon.addObsLink(links, this.#taxon, this.#config, "calflora");
HTMLTaxon.addObsLink(links, this.#taxon, this.#config, "cch");
return links;
}
Expand Down

0 comments on commit cb05cf7

Please sign in to comment.