Skip to content
audioblastPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

corpus

The shared front end for sites built on an audioBLAST collection: the app (js/), its base stylesheet (css/style.css), the page skeleton (skeleton/), and the tools that make a site's pages (tools/). A site supplies content only: its settings, copy and colours, in a config/ folder.

bio.acousti.ca and soil.acousti.ca run on it, and load it from cdn.audioblast.org/corpus/<version>/.

What a site supplies

A config/ folder, with:

  • site.js: its settings and copy, with the shape of js/config.js. It sets source and whatever differs from the defaults: names, logo, hero, filter examples, links, recording types, map tiles, the wavesurfer.js its player loads (wavesurferVersion), and the features it leaves out (see Features).
  • about.html: the About page's content, an HTML fragment that the app loads into the page.
  • theme.css, if the site has its own colours (see Styles).
  • redirects.json, if the site had other addresses before it ran on corpus (see Old addresses).

Add a favicon, and a CNAME if the site has its own domain.

A site's page

tools/build-page.mjs writes the site's index.html and main.js from skeleton/, filled in from config/site.js and pinned to this corpus version. Commit both, and the site runs as it is, with no build step.

A site sets the corpus version it runs on in one place, corpusVersion in config/site.js. The tool stops if that isn't its own version, and the site's Pages workflow reads the version from there. From the site's root, with this repo checked out at the site's version:

node ../corpus/tools/build-page.mjs
  • --check writes nothing, and fails if either file is not what this version writes. A site's Pages workflow runs it, so a hand edit, or a change to config/site.js without a rebuild, stops the deploy.
  • --core loads the core from somewhere else, to test a version that isn't on the CDN yet, and skips the version check.

The page's Content-Security-Policy and preconnect hints come from the skeleton, and the basemap's host from mapTiles, so nothing in the page is copied by hand. To move a site to another version, change corpusVersion, run that version's build-page.mjs and review the diff.

main.js imports start() from the core and hands it the site's config. start() merges that config over js/config.js and then sets up the page, so the core's modules never read a site's values before that. The tools merge it the same way.

The tools also use the app's own escaping, URL checks and taxon names, from js/format.js. Node loads that module, so it imports nothing and touches no browser globals.

Features

A site can leave out Browse taxa, Browse traits, Browse annotations, the Recordings map, specimens and publications. Each is on unless config/site.js turns it off, by its name in features: features: { browse: false, map: false }. js/config.js says what each one covers.

  • build-page.mjs leaves a feature that is off out of the page: its nav button and its page, the home page's button for Browse taxa, and the header's count of traits or annotations. Without the map, the page's Content-Security-Policy doesn't allow the basemap's images either. A name that isn't a feature stops the build.
  • The app doesn't show it or ask the API for it: no traits tab or traits column without traits, no annotations tab without annotations, no Specimens tab or list of specimens without specimens, and no Browse specimens page or nav button; without publications, no Literature or Descriptions tab and no publications on a recording's page. A recording keeps its own annotations. The address of a page that is off shows home.
  • build-static.mjs writes no specimen pages, and no lists of specimens on a recording's or a taxon's page, without specimens. Without publications, it writes no publication pages, and no publications or descriptions on a recording's or a taxon's page.
  • Taxon views and taxon pages are not part of Browse taxa, and stay: recordings link to them.

In skeleton/index.html, {{#map}}…{{/map}} marks what the map puts in the page, and the same for each feature.

Static pages

From the site's root, after its pages are assembled (see bio's .github/workflows/pages.yml):

node corpus/tools/build-static.mjs --site https://example.org --out _site

--site is required. --config (default config/site.js) and --page (default index.html) name the site's files, and --base is the path the site is served from. Node 22, as the Pages workflow uses.

build-static.mjs writes a page for each recording, specimen and publication of the source (r/<id>/, s/<id>/ and p/<id>/), and for each taxon with a recording, description or publication about it or under it (t/<id>/). A recording's page lists the specimens it is of and the publications that cite it. A taxon's page lists the specimens of it and of the taxa under it, its own descriptions, and the publications about it and about the taxa under it. A specimen's page links to the recordings it is of and to the taxon it is identified as. A publication's page lists the recordings that cite it, the taxa it is about and the descriptions that cite it.

Old addresses

A site that had other addresses before it ran on corpus, which papers, datasets and other sites still link to, lists them in a JSON file, each with the page it is now, both from the site's root:

{
  "node/10756": "r/10756/",
  "classification/gryllotalpa-vineae": "t/247/",
  "node/11164": "/?page=map",
  "content/ml-130104": "https://macaulaylibrary.org/asset/130104"
}

redirects in config/site.js names the file, as 'config/redirects.json'. / is the home page, for an old page with nothing in its place, and a page that moved to another site is given by its full http(s) address. Only build-static.mjs reads the file, so the app's pages never load it, however long it is.

A static host can't redirect, so build-static.mjs writes a page at each old address, <old address>/index.html, which refreshes at once to the new page and names it as canonical: search engines take that as a permanent move, and a reader whose browser doesn't refresh has a link. The host sends a request for the old address without its last slash on to the address with it. Those pages aren't in the sitemap.

  • An old address that would take the place of the site's own pages or files (r/…, t/…, config/…, or a file the build has written, such as sitemap.xml), or that isn't a path a file can be written at (.., ?, #, %, \), stops the build, and so does a new page that is neither on the site nor an http(s) address.
  • An old address that goes to a recording's or a taxon's page this build doesn't write, such as one of a recording type the site leaves out, is left out, with a warning that counts them.
  • On the recording pages, the original page (the recording's info_url, or recordingPageUrl) is linked only when it is on another site. An address on the site itself is the page, or one of its old addresses, which sends the reader back to it.

Versions

package.json holds the version, and build-page.mjs pins a site's page to it. A published version folder should never change afterwards, because Cloudflare caches a request for a file that doesn't exist yet as a 404. Publishing to cdn.audioblast.org/corpus/<version>/ is manual for now.

0.4.3 lets a site choose the wavesurfer.js its player loads, by its folder on the CDN, with wavesurferVersion in config/site.js: a release, or a build of a commit that isn't in a release yet, such as main-66742ba. The default stays 8.0.3. A site moves to it by setting corpusVersion to 0.4.3 and running build-page.mjs.

0.4.2 adds publications: a page for each publication, at p/<id>/, with its citation, abstract, DOI and the recordings, taxa and descriptions it links to (see Features). A recording lists the publications that cite it, a taxon has Literature and Descriptions tabs, and a description's sources link to their publications. A taxon has a page when a recording, a description or a publication is about it or under it, and a taxon with no recordings shows its hierarchy from its own row. It comes with publications, and a site with none sets features: { publications: false }, which leaves them out too. A site moves to it by setting corpusVersion to 0.4.2 and running build-page.mjs.

0.4.1 adds Browse specimens: a page in the navigation that lists the specimens a page at a time, filtered by name, country, basis of record and collector (see Features). It comes with specimens, and a site with none sets features: { specimens: false }, which leaves it out too. A site moves to it by setting corpusVersion to 0.4.1 and running build-page.mjs.

0.4.0 gives each specimen a page, at s/<id>/, with its details, the recordings it is of and the taxon it is identified as (see Features). A recording's page lists its specimens, a taxon's page lists the specimens of the taxon and of the taxa under it (a Specimens tab in the app), and a map popup links each specimen to its page. An old address of a specimen can go to its page. A site moves to it by setting corpusVersion to 0.4.0 and running build-page.mjs; a site with no specimens sets features: { specimens: false }.

0.3.1 fixes the links, such as "Page for this taxon", on a recording or taxon opened from the home page: they went to an address under that page, which doesn't exist. A site on 0.3.0 moves to it by setting corpusVersion to 0.3.1 and running build-page.mjs.

0.3.0 lets a site send its old addresses on to the pages they are now (see Old addresses), and links a recording's original page only when that is on another site. A site on 0.2.x moves to it by setting corpusVersion to 0.3.0 and running build-page.mjs, and adds redirects to config/site.js if it has old addresses.

0.2.1 names a taxon identified above species, as soil's recordings are to an order, once: in the browse tree, in its taxonomy, and on its recordings' cards. A site on 0.2.0 moves to it by setting corpusVersion to 0.2.1 and running build-page.mjs.

0.2.0 moves the page skeleton into corpus, so a site supplies content only, and sets a site's corpus version in one place. It also lets a site leave features out, shares the app's helpers with the tools, adds the browser checks to CI, licenses corpus under the GPL, and draws the map when its page was hidden while the map loaded. To move a site from 0.1.x:

  1. Move site.js, about.html and css/theme.css into config/.
  2. Add corpusVersion, logo, hero and, if the defaults don't suit the collection, examples to config/site.js.
  3. Run build-page.mjs, which replaces the hand-written index.html and main.js.
  4. In the Pages workflow, read the version from corpusVersion in config/site.js instead of setting CORPUS_VERSION, copy config/ into the build, replace the version-pin check with build-page.mjs --check, and drop --config site.js from the static-page step. bio's pages.yml shows each of these.

Tests

npm test runs the tests in tests/, with no network access:

  • the helpers that the app and the tools share (js/format.js): escaping, the two URL checks and taxon names;
  • the static-page generator, against a fake audioBlast API: a page for each recording, specimen and publication, a page for each taxon with a recording, description or publication about it or under it, and the links between them, requests scoped to the source, a page at each old address that sends the reader on (under a base path too), old addresses that stop the build or are left out, the original page linked only when it is on another site, a source with no records (only the sitemap and robots.txt, with a warning), and failures that must be clear;
  • the page builder: a site's page and main.js from its config/, with escaping, the defaults a site leaves out and its own basemap host; a theme link only when there is a theme; the features a site leaves out, with no gaps where they were; --core and --check; and a page the static-page generator builds on, with and without Browse taxa;
  • the default config: the empty source, the recording-type rules, and the features;
  • prepaint.js: the page it shows first for each kind of address, and home for a feature the site leaves out.

npm run test:browser runs the browser checks in tests/browser/, with Playwright, in Chromium, Firefox and WebKit. They run the app on four check sites, made as a site is made: one on a small collection like bio's, two more on that collection that each leave features out, and one on a source with no records, like soil's. A harness answers every request the pages make, so the checks never reach the live API, the tile server or the CDN. They cover the home page, search, the browse pages, a recording's page and its player, taxon pages, specimen pages and the lists of specimens, publication pages with a taxon's literature and descriptions, the About page, the recordings map, and what a site that leaves features out shows and loads, and fail on any console error. Before the first run, install the dependencies and the browsers with npm ci and npx playwright install. See tests/browser/README.md for how the fakes work, and what to change when the app does.

.github/workflows/test.yml syntax-checks the modules, the tools and the tests, then runs npm test on each push and pull request, and the browser checks in a job for each browser.

Styles

The base stylesheet, css/style.css, is neutral. Every colour in it is a variable, with a neutral default in :root. A site sets its own colours in config/theme.css, which loads after the base and overrides the variables:

  • --bg, --bg2, --bg3, --surface, --surface2: the page and card backgrounds.
  • --accent, --accent2, --accent-dim, --accent-dim2, --on-accent: buttons, links and the logo.
  • --text, --text2, --text3: text, from strongest to muted. Keep --text3 at 4.5:1 or better on the backgrounds.
  • --border, --border2, --red, --amber: lines, errors and notes.
  • --header-bg, --note-bg, --note-border, --error-bg, --error-border, --tag-taxon-border, --tag-type-border, --tag-type-bg, --axis-border, --label-text, --label-bg, --label-border, --dot-ring, --play-icon-on-accent: the remaining colours the base used to fix.

The shadows are black, which is neutral, so they are not variables.

Browser support

As bio: Chrome 80, Safari 13.1, Firefox 74, Edge 80. js/compat-check.js and js/nomodule-warning.js show a message to anything older.

Licence

GNU General Public License, version 2 or (at your option) any later version: see LICENSE. The libraries in js/vendor/ keep their own licences, with a LICENSE file in each folder: BSD-2-Clause for Leaflet and MIT for Leaflet.markercluster. Both are compatible with the GPL.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages