This project was bootstrapped with Create React App. You can find the most recent version of the guide in the Create React App template README.
- yarn
- Node 20
- Chrome (for Lighthouse)
The following services are needed to run application:
This project supports two development setup options: GitHub Codespaces with dev containers (recommended) or local installation.
This project is configured to work with GitHub Codespaces using dev containers. The dev container provides a pre-configured development environment with all necessary dependencies (Node 20, yarn, Chrome, etc.) without requiring local installation.
To use GitHub Codespaces:
- Navigate to the repository on GitHub
- Click the Code button and select the Codespaces tab
- Create a new codespace or open an existing one
- Important: For dev containers to work properly, open the codespace in the desktop version of VS Code rather than the browser. When the codespace starts, VS Code will prompt you to open it in the desktop application.
- Once opened in VS Code desktop, the dev container will automatically set up the development environment
- Configure the required environment variables in
.env.local(see Running the application section) - Dependencies are installed automatically via the
postCreateCommandin the dev container configuration (you can manually runyarn installif needed) - You're ready to develop!
If you prefer to develop locally without using Codespaces, follow these steps:
Prerequisites:
- Install Node 20
- Install yarn
- Install Git LFS (required for the Git hooks)
- Install Chrome (required for Lighthouse)
Setup:
-
Clone the repository:
git clone https://github.com/ElectronicBabylonianLiterature/ebl-frontend.git cd ebl-frontend -
Install dependencies:
yarn install
This will automatically patch history in node_modules which is an indirect dependency for react-router version 5 because of remix-run/history#505 (updating react-router to version 6 would fix this issue too).
-
Configure environment variables in
.env.local(see Running the application section) -
Start the development server:
yarn startyarn lint
yarn tsc
yarn testyarn test --coverage --watchAll
A single page application has to be setup in Auth0. The frontends root URL (e.g. http://localhost:3000 for development) must be in Callback URLs, Logout URLs, and Web Origins. Domain and Client ID are needed for the environment variables (see below). In a production environment the domain must be added to frame-src in the CSP.
An organization and project need to be setup in Sentry. The applications domain must be in Allowed Domains of the project. DSN under Client Keys is needed for the for the environment variables (see below). In a production environment the domain must be added to frame-src in CSP.
In a production environment the api domain must be added to img-src in CSP.
The application reads the configuration from following environment variables:
REACT_APP_AUTH0_DOMAIN=<Auth0 domain>
REACT_APP_AUTH0_CLIENT_ID=<Auth0 client ID>
REACT_APP_AUTH0_AUDIENCE=<Auth0 audience>
REACT_APP_DICTIONARY_API_URL=<eBL API URL>
REACT_APP_SENTRY_DSN=<Sentry DSN>
REACT_APP_CORRECTIONS_EMAIL=<Email for submitting corrections>
REACT_APP_INFO_EMAIL=<Email for general questions and contact>
REACT_APP_GA_TRACKING_ID=<Google Analytics 4 tracking (measurement) Id>In production environments INLINE_RUNTIME_CHUNK must be set to false due to Content Security Policy.
yarn start starts the development server. The environment variables are read from .env.local.
Updating react-image-annotation could break Annotation.js
in the annotation-tool.
Google Lighthouse is installed as a development dependency and can be run via yarn:
yarn lighthouse <url>bluebird promises are used whenever a cancellable promise is needed. E.g. when loading data to components (see isMounted is an Antipattern). bluebird is compatible with native JavaScript promises, but care should taken that a bluebird promise is always used when Promise.cancel() is needed.
Authentication is handled with Auth0 and @auth0/auth0-spa-js.
Display of content can be controlled using SessionContext:
// Access with Context.Consumer
;<SessionContext.Consumer>
{(session: Session): JSX.Element => (
<span>{session.isAllowedToReadFragments() ? 'access' : 'no access'}</span>
)}
</SessionContext.Consumer>
// Access with useContext hook
const session = useContext(SessionContext)
const hasAccess = session.isAllowedToReadTexts()The sitemap provides a roadmap of the website's content to help search engines index all pages and improve the site's visibility in search results.
The sitemap is now updated automatically using a GitHub Actions workflow. This routine runs once a week and also allows manual execution when needed.
To manually trigger the automated sitemap update:
- Go to the repository's "Actions" tab on GitHub.
- Select the workflow named "Update Sitemap".
- Click "Run workflow" (top right) and confirm.
This action will:
- Download and regenerate the sitemap files.
- Create a pull request with the updated files.
- Automatically merge the pull request once all required checks pass.
To keep the automation working, you must refresh the SITEMAP_AUTOUPDATE secret approximately once per year, as PATs expire.
- Go to your GitHub Developer Settings → Fine-Grained Tokens.
- Create a Fine-Grained Token:
- Restrict it to just the ElectronicBabylonianLiterature/ebl-frontend repo.
- Minimal scopes. Contents: Read and write, Pull requests: Read and write.
- Name the token
sitemap-autoupdateand set an expiration period (max. 12 months). - Save the value of the new token.
- In the repository, go to Settings → Secrets and variables → Actions → Repository secrets.
- Find
SITEMAP_AUTOUPDATEand update the value with the token you just generated. - Save the secret. The next time the workflow runs, it will use the updated token.
- If the PAT user changes, update
git config user.nameandgit config user.emailinformation in.github/workflows/update-sitemaps.yml.
Manual update is possible if automation fails.
- Visit the sitemap page: https://www.ebl.lmu.de/sitemap
- Wait until all files (
sitemap.xml.gz,sitemap1.xml.gz, etc.) are downloaded. - Replace the content of the
public/sitemapdirectory with the downloaded files. - Commit the changes to the
masterbranch.
- Write clean code. Use linters and analysers to find code smells.
- Write tests for your code. Test Driven Development is recommended but not mandatory. There is no hard requirement for code coverage but it should improve over time.
- Use GitHub Flow for branches..
- Implement a proper domain model. Avoid passing data around in dictionaries.
- Prefer immutable value objects. Use Immer to update objects.
- Use Prettier code style.
- Always use TypeScript files .ts, .tsx.
- Stick to the good parts.
- Avoid Common mistakes with React Testing Library.
- Try to use semantic HTML.
- Use BEM naming convention for CSS classes.
- Use lowercase names for CSS classes.
- TypeScript files with default import should have the same name as the default import.
E.g.
MyComponent.tsx,myFunction.tsx. - CSS/Sass files for components should have the same name as
the TSX File they are used in. E.g.
MyComponent.css - Other files and folders should have kebab case names.
E.g.
test-helpers.ts
Junicode webfont by psb1558 is licensed under the SIL Open Font License, Version 1.1. You can get the full distribution from Junicode download page.
Assurbanipal, Esagil, Santakku, SantakkuM, UllikummiA webfonts by Sylvie Vanséveren are freely available for the scientific community. You can get the full distributions from Download page.
Annotation.js in the annotation-tool is from Arian Allenson Valdez