Skip to content

Commit 992c1fd

Browse files
authored
Merge branch 'dev-2.0' into vector-messages
2 parents dc38176 + 6f5899a commit 992c1fd

1 file changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<!-- How to write, edit, and preview contributor documents. -->
2+
# Working with contributor documents
3+
4+
## Table of Contents
5+
* [Where are they?](#where-are-they)
6+
* [Build process overview](#build-process-overview)
7+
* [Generating and previewing contributor documents](#generating-and-previewing-contributor-documents)
8+
* [Adding a new contributor document](#adding-a-new-contributor-document)
9+
10+
## Where are they?
11+
Contributor documents are displayed on the p5.js website at either:
12+
13+
* https://p5js.org/contribute/ (for p5.js v1)
14+
* https://beta.p5js.org/contribute/ (for p5.js v2)
15+
16+
Their source materials are kept in:
17+
* repo: `p5.js`
18+
* path: `contributor_docs/`
19+
20+
(Note: The v1.x and v2.x branches have different documents.)
21+
22+
## Build process overview
23+
24+
During the _website_ build process `build:contributor-docs` the documents are cloned from the requested branch of the p5.js repo into the relevant website file-system locations. From here, the astro dev server can show previews of how they will look. (Exact instructions and paths follow.)
25+
26+
## Generating and previewing contributor documents
27+
28+
### Quick preview
29+
For a quick preview, various editors have a feature to render markdown files. For example, if you're using vs code here's how to do that:
30+
31+
* open the .md file you wish to preview
32+
* open the command-palette (`F1` or `cmd-shift-p` or `ctrl-shift-p`)
33+
* type `Markdown: open preview`
34+
35+
There are various limitations to this quick-preview. For example, the p5.js website page layout and styling (colors, fonts, line-width, etc) will not be applied.
36+
37+
### Preview on local p5.js-website clone
38+
39+
At some point you will want to preview how your changes will look on the website. This involves run the website locally and having it import the contributor docs from a branch of your p5.js repo.
40+
41+
In the following steps we'll assume your p5.js repository is in a folder called `p5.js` and your p5.js-website repo is in a folder next to it called `p5.js-website`.
42+
43+
```mermaid
44+
---
45+
title: Assumed local repo folder setup
46+
---
47+
flowchart TD
48+
parent --- p5.js
49+
parent --- p5.js-website
50+
```
51+
52+
#### Steps:
53+
54+
1. Commit your changes to a local branch of your fork of the p5.js repo. The changes don't need to be pushed to github for this purpose, but they do need to be committed on a branch.
55+
1. Clone [the p5.js-website repo](https://github.com/processing/p5.js-website/tree/2.0) locally.
56+
1. Open a terminal in your new p5.js-website repo
57+
1. Check out the branch "2.0"
58+
1. Run `npm install`
59+
1. Modify and run the following command, using the path to **your** local p5.js repo, and the name of **your** branch:
60+
61+
(Note the following is a single line, not two lines!)
62+
63+
```sh
64+
P5_REPO_URL=path/to/your/p5/repo P5_BRANCH=your-branch-goes-here npm run build:contributor-docs && npm run dev
65+
```
66+
67+
For example, if your work is in a branch called `my-amazing-branch` on a local p5.js repo called `p5.js` as a sibling folder next to the current `p5.js-website` folder, you could run the following:
68+
69+
```sh
70+
P5_REPO_URL=../p5.js P5_BRANCH=my-amazing-branch npm run build:contributor-docs && npm run dev
71+
```
72+
73+
This will do three things:
74+
1. import and build local website `.mdx` pages from the `.md` files in `contributor_docs/` in your branch
75+
2. start a development preview of the website
76+
3. display a URL in the console where you can visit the local website
77+
78+
Use your browser to visit the URL mentioned in the last step, in order to test out your changes.
79+
80+
#### Alternative: Building from a branch on github
81+
82+
If you prefer to preview work that's already on github, you can do so. In the final command, use the repo URL instead of its local path, as follows:
83+
84+
(Again, note the following is a single line, not two lines!)
85+
86+
```sh
87+
P5_REPO_URL=https://github.com/yourUsername/p5.js.git P5_BRANCH=your-branch-goes-here npm run build:contributor-docs && npm run dev
88+
```
89+
90+
#### Troubleshooting
91+
92+
If your file isn't appearing in the list the website shows at the path `contribute/`:
93+
94+
* Note that it will appear with a title taken from the first level 1 markdown heading, NOT the name of the file.
95+
96+
* Check that a corresponding `.mdx` file is being generated in `src/content/contributor-docs/en` in the website file-structure. If not, check if your .md file is git in the branch you've specified, in the correct location, and check the logs, during the website build:contributor-docs
97+
98+
* Review the log from the above run of the npm `build:contributor-docs` process, for mentions of your file(s).
99+
100+
* If you see that an .mdx file _is_ being generated, check that you can access it directly on the website by typing its URL. e.g. if your file is called myFile.md, the path in the URL would be: `contribute/myFile/`
101+
102+
* Ensure you see in the log that your repo _has_ actually been cloned. There is a caching mechanism in the website build process which prevents a recently cloned repo from being cloned again. Removing the website folder `in/p5.js/` will force the build process to make a new clone.
103+
104+
#### Limitations
105+
106+
The website won't be _fully_ functional when partially prepared in this way. Notably:
107+
108+
* Links between pages may be broken:
109+
* You'll need to ensure local links end with a trailing slash '/', to be matched by Astro when it is in development mode.
110+
* The search facility will not work by default
111+
* Look into `npm run build:search` to build the necessary index files.
112+
113+
114+
## Adding a new contributor document
115+
116+
We'll consider file path, filename, file extension, title, subtitle, and eventual URL path for your new document.
117+
118+
#### The file path
119+
120+
It should be stored in `contributor_docs/` folder in the _p5.js_ repo.
121+
122+
It should be stored as a direct child of that folder, _not_ in a subfolder.
123+
124+
#### The filename and extension
125+
126+
The filename won't be used as the document title but _will_ be used in URLs. The filename should be all in lowercase, and use underscore characters `_` instead of spaces or dashes.
127+
128+
It should have a `.md` file extension.
129+
130+
Keep the filename concise but do not use contractions. e.g. "documentation_style_guide" not "doc_style_guide". If in doubt check the names of the other documents in the folder and try to stay aligned with those.
131+
132+
#### The _name_ of your document
133+
For presentation purposes in the list of contributor docs and for search results, your document title will be taken from the first level 1 markdown heading, NOT the name of the file.
134+
135+
#### The subtitle for your document
136+
In the list of contributor docs, each page is listed not only with its title but also a subtitle or short description.
137+
138+
This description is extracted from the first HTML-style comment in your file. This should be on the first line, before the level 1 heading.
139+
140+
Example:
141+
142+
<!-- The following weird syntax is necessary to show the reader an HTML comment, as our current MDX generation process won't leave alone such a comment in a code-block. -->
143+
144+
In `contributor_docs/unit_testing.md` the file content starts:
145+
146+
<div className="astro-code">
147+
&lt;!&dash;- Guide to writing tests for p5.js source code. &dash;-&gt;
148+
149+
\# Unit Testing
150+
</div>
151+
152+
As a result, this will list a page titled "Unit Testing" with a description of "Guide to writing tests for p5.js source code.".
153+
154+
#### The URL for your document
155+
156+
The path in the eventual URL will be
157+
`contribute/your_filename_without_extension/`
158+
Note that the trailing slash is necessary in development mode.
159+
160+
Example:
161+
162+
The source document `contributor_docs/unit_testing.md` will be served as `https://beta.p5js.org/contribute/unit_testing/`
163+

0 commit comments

Comments
 (0)