Development
Tech Docs is a Node.js application, built with Astro and its Starlight documentation site framework. The source code is hosted on GitHub. The site is statically built and (temporarily) hosted via Cloudflare Pages. Content is written in Markdown. When the source code changes, a new set of static files are generated and published shortly after.
Dependencies
Tech Docs depends on the following open source software (see .nvmrc
and package.json
for versions):
- Node.js - JavaScript development and build environment
- Astro - Static site generator conceptually based on “components” (React, Vue, Svelte, etc.) rather than “templates” (Jekyll, Handlebars, Pug, etc.)
- Cypress - End-to-end testing framework
- Stylelint - CSS linter used locally in text editors and remotely in CI for testing
- stylelint-config-recommended - Base set of lint rules
- postcss-html - PostCSS syntax for parsing HTML (and HTML-like including .astro files)
- stylelint-config-html - Allows Stylelint to parse .astro files
- Prettier - Source code formatter used locally in text editors and remotely in CI for testing
- prettier-plugin-astro - Allows Prettier to parse .astro files via the command line
Local development
Run Tech Docs locally by cloning the Tech Docs repository, installing project dependencies, and spinning up a development server:
Now go to localhost:4321 to see Tech Docs running locally. Changes to the source code will be immediately reflected in the browser.
Building the site
Building the site creates a set of static files, found in dist
after build, that can be served locally or deployed to a server. Sometimes building the site surfaces errors not found in the development environment.
Available npm
scripts
The following scripts are made available via package.json
. Invoke any script on the command line from the project root by prepending it with the npm run
command, ie: npm run start
.
start
— run Astro dev serverbuild
— build Tech Docs for productionpreview
— serve the static buildastro
— get Astro helptest:dev
— run tests in development modetest:prod
— run tests in production modetest
— defaults to run tests in production modeprettier:check
— check formatting with Prettierprettier:fix
— fix possible format errors with Prettierstylelint:check
— lint CSS with Stylelintstylelint:fix
— fix possible CSS lint errors with Stylelint
Search
Site search is a Starlight feature:
By default, Starlight sites include full-text search powered by Pagefind, which is a fast and low-bandwidth search tool for static sites.
No configuration is required to enable search. Build and deploy your site, then use the search bar in the site header to find content.
Theme customization
Starlight can be customized in various ways, including:
- Settings — see
astro.config.mjs
- CSS — see
src/styles/custom.css
- Components — see
src/components
Static assets
Images
Most image files should be stored in src/images
. This allows for processing by Astro which includes performance optimizations.
Images that should not be processed by Astro, like favicons, should be stored in public
.
The public
directory
Files placed in public
are not processed by Astro. They are copied directly to the output and made available from the root of the site, so public/favicon.svg
becomes available at docs.archivesspace.org/favicon.svg
, while public/example/slides.pdf
becomes available at docs.archivesspace.org/example/slides.pdf
.
Update npm dependencies
Run the following commands locally to update the npm dependencies, then push the changes upstream.
Import aliases
Astro supports import aliases which provide shortcuts to writing long relative import paths.
Sitemap
Starlight has built-in sitemap support which is enabled via the top-level site
key in astro.config.mjs
. This key generates /sitemap-index.xml
and /sitemap-0.xml
when Tech Docs is built, and adds the sitemap link to the <head>
of every page. public/robots.txt
also points to the sitemap.
Testing
End-to-end
Tech Docs uses Cypress for end-to-end testing customizations made to the underlying Starlight framework and other project needs. End-to-end tests are located in cypress/e2e
.
Run the Cypress tests locally by first building and serving the site:
Then in a different terminal initiate the tests:
Code style
Nearly all files in the Tech Docs code base get formatted by Prettier to ensure consistent readability and syntax. Run Prettier locally to find format errors and automatically fix them when possible:
All CSS in .css and .astro files are linted by Stylelint to help avoid errors and enforce conventions. Run Stylelint locally to find lint errors and automatically fix them when possible:
CI/CD
Before new changes are accepted into the code base, the end-to-end and code style tests need to pass. Tech Docs uses GitHub Actions for its continuous integration and continuous delivery (CI/CD) platform, which automates the testing and deployment processes. The tests are defined in yaml files found in .github/workflows/
and are run automatically when new changes are proposed.