Refactor website JS and add model comparison tool #1473
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR mainly includes two improvements to the website and the interactive features and JavaScript layer. I was a little stubborn about this and decided to do it entirely in Vanilla JS and with very few dependencies. But hey, it's still very lightweight and I made an effort to document it, so it should be easy to maintain (which will mostly be done by "future me" anyways).
Refactor JavaScript
Use ES6 modules to split up the individual components into modules, e.g.
GithubEmbed
,ModelLoader
, andimport
and initialise them in in the templates if needed. This is important, since the spaCy website initialises the JS components with stringified JSON data from the static CMS to avoid duplicate data – for example, the available models and languages. This needs to be populated by the template in_includes/_scripts.jade
. It looks a bit hacky, but it's very convenient.On build, a
rollup.js
is compiled usingrollup
, which includes a bundle of all modules and makes them available to thewindow
object. The file is included as<script nomodule
>, which is only fetched if the browser does not yet support JS modules. All module-related JS is loaded as<script type="module">
and only interpreted if the browser supports modules.See this blog post for more details on ES6 modules. In general, JS is only supposed to enhance the spaCy website – not to provide crucial information. While interactive components and auto-loaded code/model details from GitHub are nice, they're not a must. In all cases, fallbacks (e.g. links and the most important info) are provided. The site should always be fully functional with JS disabled, so this PR provides some fixes to make this work more smoothly as well.
Add experimental model comparison tool
The tool will be available at
/models/comparison
and lets the user compare two models by features, accuracy and speed. Model data is fetched from GitHub and presented in a chart (accuracy) and table (feature and accuracy/speed figures). The main goal is to make it easier to show and visualise the differences and trade-offs between models of the same type – for example,en_core_web_lg
anden_core_web_sm
.Website build process
This is only relevant for deployment and not for users running the site locally, as
harp serve
takes care of this and is all you need.All steps of the build process are also available as short commands via
npm run
, set in thepackage.json
. There's one main problem with the full build process (which has always existed, but only came up now): when installing the dependencies from thepackage.json
, npm will create anode_models
directory within the website directory. There's currently no way to prevent Harp to building this directory (see sintaxi/harp#275) – and no way to prefix it with an underscore, as this won't work with npm (which is by design and makes sense in context). So for now, all dev dependencies (babel-cli
,harp
,rollup
,uglify-js
) have to be installed locally vianpm install -g
. A solution would be to move the site into another subdirectory, but that's quite ugly and inconvenient.Description
Types of changes
documentation
Checklist