Skip to content

MatrixAI/Polykey-Docs

Repository files navigation

Polykey-Docs

Documentation for Polykey.

Development

Run nix develop, and once you're inside, you can use:

# starts a local version
npm run start
# build the the static site
npm run build
# deploy to cloudflare
npm run deploy
# lint the source code
npm run lint
# automatically fix the source
npm run lintfix

Deployment

Development:

npm run build
npm run deploy

Production:

npm run build
npm run deploy -- --env production

Contributing

Because we use Docusaurus, we can choose to write in markdown, TSX or MDX.

HTML Syntax

Sometimes markdown syntax just doesn't cut it, and HTML syntax needs to be used.

While Docusaurus is flexible, GitHub is not.

GitHub will process the markdown and then sanitizes the HTML: https://github.com/github/markup#github-markup.

There is a limited set of HTML tags are here: https://github.com/gjtorikian/html-pipeline/blob/03ae30d713199c2562951d627b98b75dc16939e4/lib/html/pipeline/sanitization_filter.rb#L40-L49

Furthermore not all attributes are kept. The style attribute for example is filtered out.

The most common styling attributes to be used will most likely be align, width, and height. See: https://davidwells.io/snippets/how-to-align-images-in-markdown

Linking Assets (files, images)

Markdown supports 2 ways of referencing images:

![](/images/foobar.png)
<img src="/images/foobar.png" />

The former is markdown syntax, the latter is HTML tag.

In order to maintain portability, we always use absolute paths. This works on both GitHub markdown rendering and also for Docusaurus.

On GitHub, which renders the markdown directly, the relative paths are considered relative to the location of the markdown file referencing the path. The absolute paths are considered relative to the root of the project repository. Therefore because the images directory is located at the project root, it ends up being routable.

With Docusaurus, the absolute paths are looked up relative to static directory. Inside the static directory we have created symlinks pointing back to ../images. This allows Docusaurus to also resolve these paths which will be copied into the /build/ directory.

Note that Docusaurus doesn't do any special rendering for HTML tags, it uses the src as is. While markdown references will be further processed with webpack. It is therefore preferable to use markdown syntax instead. Docusaurus does support a variant of the HTML tag:

<img src={require('/images/foobar.png').default} />

However this does not work in GitHub. So this is not recommended to use.

Therefore if you want to add inline styles to an image and still use markdown syntax so you get the benefit of Docusaurus asset processing, the styles must be applied outside the image reference in a surrounding tag:

<div align="center">

  ![](/images/foobar.png)

</div>

Take note of the whitespace newlines between, if no newlines are used, GitHub will interpret this as all HTML. Also note that <p></p> will not work.

Note that this won't work for resizing the images unfortunately. You have to apply the width attribute directly to the <img /> tag. See: facebook/docusaurus#6465 for more information.

Linking

In the navigation in Docusaurus, there are several properties that controls how the routing works. Because polykey.com is composed of separate cloudflare workers stitched together into a single domain, we have to hack around client side routing even for what looks like relative links.

{
  to: 'pathname:///docs/',
  target: '_self'
}

The to ensures it shows up as a relative link.

The pathname:// bypasses the client side routing forcing server side routing.

The target: '_self' ensures that the same frame is used instead of creating a new frame.

License

Polykey-Docs is licensed under GPL-3.0, you may read the terms of the license here.