Skip to content

Commit b368edc

Browse files
authored
First pass at docs (#355)
* add basic technical overview * reorder npm tasks * Create localization.md * Create styles_architecture.md * Create scripts.md * remove dead npm scripts * update script names * create docs folder
1 parent 2526b4f commit b368edc

8 files changed

Lines changed: 203 additions & 34 deletions

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
# WIP
1+
# [BETA] p5.js Website
22

3-
This project is undergoing **major changes** currently. This will be the case until the end of April. If you are here to edit or translate content, please do so inside [the `src/content/` folder](https://github.com/bocoup/p5.js-website/tree/main/src/content)
3+
## Contributing
44

5-
## Adding Libraries
5+
### Content Changes
66

7-
Follow the steps in the <a href="./contributing_libraries.md">Contributing Libraries</a> doc if you would like to add your libary to the collection!
7+
If you are here to edit or translate content, please do so inside [the `src/content/` folder](/src/content).
8+
9+
### Code Changes
10+
11+
For making code changes, check out the [technical overview](./docs/techical-overview.md) to get started.
12+
13+
### Adding Libraries
14+
15+
Follow the steps in the <a href="./docs/contributing_libraries.md">Contributing Libraries</a> doc if you would like to add your libary to the collection!

contributing_libraries.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/contributing_libraries.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# p5.js Libraries
2+
3+
p5.js welcomes libraries contributed by others! <a href="https://github.com/processing/p5.js/blob/main/contributor_docs/creating_libraries.md">Check out the libraries tutorial</a> for more specifics about how to create one. If you have created a library and would like to have it included in the list, follow the instructions below!
4+
5+
1. Fork the repo
6+
2. Add a file to the <a href="/src/content/libraries/en/">`src/content/libraries/en`</a> folder named `yourLibraryName.yaml` (or consider <a href="src/content/libraries/en/p5.warp.yaml">copying an existing library</a> as a starting point)
7+
3. Inside it, add the following content:
8+
- `name`: The name of the library
9+
- `category`: A category that you think best fits your library. Your choices include: `drawing`, `color`, `ui`, `math`, `physics`, `algorithms`, `3d`, `ai-ml-cv`, `animation`, `shaders`, `language`, `hardware`, `sound`, `data`, `teaching`, `networking`, `export`, or `utils`.
10+
- `description`: A one-sentence description of the library
11+
- `author`: An object containing `name`, your name, and `url`, an optional link to your website. If there are multiple authors, use an array of author objects.
12+
- `sourceUrl`: A link to the library's source code (e.g. its repo on GitHub or GitLab)
13+
- (Optional) `websiteUrl`: A link to a website for the library
14+
- (Optional) `npm`: If applicable, the package name for the library on <a href="https://www.npmjs.com/">npm</a>
15+
- (Optional) `npmFilePath`: A path like `'dist/library.min.js'` if a specific file in the library should be used from npm. You can test this out by going to `https://cdn.jsdelivr.net/npm/packageName` -- if that doesn't work, try `https://cdn.jsdelivr.net/npm/packageName/path/to/file.js` and put the path you added into this property
16+
- `featuredImage`: The relative path to the preview thumbnail for the library.
17+
- `featuredImageAlt`: a short description of the contents of the thumbnail for screen readers
18+
- (Optional) `license`: A <a href="https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license">string describing the software license of the library.</a> This may be omitted if your package is on npm and has license info there
19+
4. Add a **high-res colored image of 1500x1000px** of your library into `src/content/libraries/images`
20+
5. Submit a pull request and we'll review your submission
21+
22+
We add libraries that are open-source, includes some documentation and examples, and <a href="https://github.com/processing/p5.js/blob/main/CODE_OF_CONDUCT.md">follow our code of conduct.</a> This directory targets beginner users, so we aim to ensure users have a smooth experience getting started with any library linked to.
23+
24+
If you have any questions, feel free to open an issue or create a work-in-progress PR and ask us anything!

docs/localization.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Localization Architecture
2+
3+
An important feature of the p5.js website is support multiple languages (four and counting!). This requires the website to build and serve every page in each of the supported languages.
4+
5+
Our website framework Astro has localization support, but it doesn't cover our full set of needs so the localization tooling in this repo is largely [hand rolled](https://www.quora.com/Computer-Science-Where-did-the-phrase-Roll-your-own-come-from-and-why-is-it-used-in-CS).
6+
7+
## Supported Languages and Language Codes
8+
9+
The languages that will be built and included in the language dropdown menu are defined in [`/src/i18n/const.ts`](/src/i18n/const.ts) The language codes used in that list define both the routes for localized content (for example: the "es" in https://p5js.org/es/examples) as well as the expected language folders in each content collection (every folder in [`/src/content`](/src/content)). These generally follow [these language codes](https://en.wikipedia.org/wiki/ISO_639-1).
10+
11+
## Translation Authoring Locations
12+
13+
Almost all strings and text are stored within content collections in src/content.
14+
15+
Every content collection in `src/content` is divided into language-specific folders. The pages in a collection must have the same name in each language folder.
16+
17+
Each file within these collection folders corresponds to a real page on the rendered website.
18+
19+
The ["ui" content collection](src/content/ui/) is a little different than the others. It contains yaml files that cover strings that are used across different pages for things like the navigation bar.
20+
21+
## Routes and Layouts
22+
23+
Astro uses a file-based approach to generating routes. The filepath of each file in `src/pages` becomes the url of the page it renders. Because we need to support a url scheme where English translations of pages are served at a URL with no locale prefix (for example, the English version of the tutorials page is at https://p5.js/tutorials _not_ https://p5.js/en/tutorials), there are 2 sets of routing files and folders: one in `src/pages` and another `src/pages/[locale]`. The `[locale]` set are needed to build and serve the non-English pages (whose URLs are also prefixed by the language codes).
24+
25+
Taking the tutorials page as an example:
26+
27+
- `src/pages/tutorials` is the route for the English tutorials page
28+
- `src/pages/[locale]/tutorials` is the route for all other translations of the tutorials page
29+
30+
Both of these routes use the [TutorialsLayout](/src/layouts/TutorialsLayout.astro) to render the page by passing in the content in the correct language.
31+
32+
The main difference between these two routing files is how they retrieve the correct translation. The English version retreives the English version of the content. The other translations retrieve their version of the content and then fill in any gaps with English versions. See `getCollectionInLocaleWithFallbacks()` for how this works.
33+
34+
Because of this subtle duplication, we try to keep the files in `src/pages/` as short as possible and move rendering logic into the [layout files](/src/layouts/).

docs/scripts.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Scripts
2+
3+
This repo includes a few scripts to pull content from external sources, primarily the [p5.js repo](https://github.com/processing/p5.js).
4+
5+
They are all runnable via npm scripts.
6+
7+
## Search Indices Build Script
8+
9+
`npm run build:search` generates metadata about the content of the website so the search functionality can show relevant results.
10+
11+
## Contributor Docs Build Script
12+
13+
`npm run build:contributor-docs` copies the contributor docs from the p5.js website repo and places them into the [contributor docs content collection](/src/content/contributor-docs).
14+
15+
## Reference Build Script
16+
17+
`npm run build:reference` parses the inline documentation in the p5.js source code (the JSDoc comments) and generates the pages in the [reference collection](/src/content/reference). Because the directly inline documentation for p5.js is only in English, this script will only update the English translation of the reference.
18+
19+
## Contributors List Build Script
20+
21+
`npm run build:contribtuors` parses the list of contributors from the all contributors [config file](https://github.com/processing/p5.js/blob/main/.all-contributorsrc) in the p5.js repo and adds entries in the [people collection](src/content/people/en) for anyone who is missing. These are used to render the list of contributors on the [People page](https://p5js.org/people/). This script will **not** remove or update existing entries, that must be done manually.

docs/styles_architecture.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Styling (CSS) Architecture
2+
3+
## Methods
4+
5+
There are a few ways you can write CSS in this project:
6+
7+
### 1. Use [Tailwind](https://tailwindcss.com/) css classes directly within layouts and components
8+
9+
This is often the fastest way to add custom styles if you are familair with [Tailwind](https://tailwindcss.com/). See a good example in `/src/p5/p5.js-website/src/components/Footer/index.astro`.
10+
11+
### 2. Write styles in the [SCSS](https://sass-lang.com/) files in `/styles` and use those classes in layouts and components
12+
13+
The styles folder is primarily meant for foundational styles that are used across pages and components. The majority of it is in `/styles/global.scss`.
14+
15+
### 3. Write a `styles.module.scss` file for a specific component and import it into that component
16+
17+
This can be useful for situations where the styling you need for a particular area is very complex and hard to distill in simple Tailwind classes. See a good example of this approach in `/src/components/Dropdown`.
18+
19+
#### 4. Write css in a style tag within an `.astro` file
20+
21+
This can be a good approach when you need a few custom styles for a single a layout or component but adding an extra SCSS feels like overkill. See an example in `/src/layouts/AboutLayout.astro`
22+
23+
## Useful Global Styles
24+
25+
These global classes may do exactly what you need:
26+
27+
### Grids
28+
29+
Both of these are useful for laying out a series of items in a responsive grid with the right spacing.
30+
31+
- .content-grid
32+
- .content-grid-simple
33+
34+
### Sections
35+
36+
Page layouts rely on having content within one or more `<section>`'s (or `.section`'s) to have proper spacing.
37+
38+
### Markdown
39+
40+
The `.rendered-markdown` class is intended to wrap areas where we render markdown content from a content collection. See `/src/layouts/TextDetailLayout.astro` for a simple example.

docs/technical_overview.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Technical Overview
2+
3+
## Getting Started with Development
4+
5+
### Setup
6+
7+
1. Make sure you have [node and npm installed on your machine](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs).
8+
2. Clone this repo by typing git clone https://github.com/processing/p5.js-website/ in your terminal. (You can also use [GitHub Desktop](https://desktop.github.com/)).
9+
3. Then install the project's dependencies with:
10+
11+
```shellsession
12+
npm install
13+
```
14+
15+
### Running
16+
17+
Running this will start up a local dev server and print out the address in your terminal (for example: http://localhost:4321/). Open that page in your browser to see the website.
18+
19+
```shellsession
20+
npm run dev
21+
```
22+
23+
## File Organization
24+
25+
The website code is divided into a few main folders:
26+
27+
- `src/content/` this is where almost all content authoring happens in the repo. These files contain the content that is used to generate the website.
28+
- `src/components/` holds UI elements that are rendered on different pages of the website. Things like basic buttons, as well as more specialized things like the top navigation menus are here.
29+
- `src/layouts/` this contains the basic visual structure of each page. If you are looking to edit a specific page of the website, finding the layout for it in this folder is a great place to start.
30+
- `src/pages/` these files are primarily used to create the routes (the different URLs) for the pages of the website and pull content from `src/content/`. Note that every route basically exists twice: once in `src/pages/` and again in `src/[locale]/pages/` to support localized urls. Read more about this in [./localization-architecture.md]
31+
- `src/scripts/` contains utility scripts that update the files in `src/content/` with changes in the p5.js repo
32+
- `styles/` contains globally applied css styles for the website
33+
- `test/` contains a set of unit tests that cover some important utility functions and key components
34+
35+
## Making Changes
36+
37+
As you make changes to the code on the site, the page you see rendered in the browser from `npm run dev` will update automatically. However, you may need to refresh to see some styling changes reflected.
38+
39+
You can check your work with the following commands. These will run type checking on typescript files and check for common mistakes in javascript files.
40+
41+
```shellsession
42+
npm run lint
43+
npm run check
44+
```
45+
46+
## Running Tests
47+
48+
To run the suite of unit tests, use:
49+
50+
```shellsession
51+
npm run test
52+
```
53+
54+
## Building the site
55+
56+
We are using the [Astro framework](https://astro.build) as a [static site generator](https://docs.astro.build/en/basics/rendering-modes/#pre-rendered), which means that the build process renders every single page of the website as HTML (and JavaScript and CSS) and then serves them using a simple server. These are then uploaded to [GitHub Pages](https://pages.github.com/). This all happens automatically with GitHub Actions when code is merged to the `main` branch in this repo.
57+
58+
You can try building the site locally with
59+
60+
```shellsession
61+
npm run build
62+
```
63+
64+
And then view it locally with
65+
66+
```shellsession
67+
npm run preview
68+
```

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
"build": "astro check && astro build",
1111
"preview": "astro preview",
1212
"astro": "astro",
13-
"build:contribute": "tsx ./src/scripts/builders/contribute.ts",
14-
"build:reference": "tsx ./src/scripts/builders/reference.ts",
15-
"build:search": "tsx ./src/scripts/builders/search.ts",
16-
"build:people": "tsx ./src/scripts/builders/people.ts",
1713
"test": "vitest",
18-
"build:examples": "node ./src/scripts/build-examples.js",
19-
"postprocess:links": "tsx ./src/scripts/postprocess-locale-relative-links.ts"
14+
"build:contributor-docs": "tsx ./src/scripts/builders/contribute.ts",
15+
"build:contributors": "tsx ./src/scripts/builders/people.ts",
16+
"build:reference": "tsx ./src/scripts/builders/reference.ts",
17+
"build:search": "tsx ./src/scripts/builders/search.ts"
2018
},
2119
"dependencies": {
2220
"@astrojs/check": "^0.5.5",

0 commit comments

Comments
 (0)