Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .devenv/scripts/check-links.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def build_map(repo_root: Path, base_url: str, spec: Optional[dict]) -> List[Reso
links = extract.extract_files(repo_root, extract.iter_doc_files(repo_root / "docs"))
if spec is not None:
links += openapi.extract_spec(spec)
return resolve.resolve_all(links, routes.load_routes(repo_root), base_url)
return resolve.resolve_all(links, routes.load_routes(repo_root), base_url, repo_root)


def select(resolved: List[ResolvedLink], scope: str, files: Optional[Set[str]]) -> List[ResolvedLink]:
Expand Down
20 changes: 16 additions & 4 deletions .devenv/scripts/linkcheck/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from __future__ import annotations

import posixpath
from typing import Dict, Iterable, List
from pathlib import Path
from typing import Dict, Iterable, List, Optional
from urllib.parse import unquote, urljoin, urlsplit

from .models import EXTERNAL, INTERNAL, SKIPPED, UNRESOLVED, Link, ResolvedLink
Expand All @@ -14,6 +15,7 @@
SKIP_PREFIXES = ("mailto:", "tel:", "javascript:", "data:")
DOC_SUFFIXES = (".md", ".mdx")
DOCS_DIR = "docs"
ASSET_SUFFIXES = (".png", ".svg", ".jpg", ".jpeg", ".gif", ".webp")


def _md_candidates(link_file: str, path: str) -> List[str]:
Expand All @@ -24,7 +26,8 @@ def _md_candidates(link_file: str, path: str) -> List[str]:
return [posixpath.normpath(posixpath.join(posixpath.dirname(link_file), path))]


def resolve_link(link: Link, routes: Dict[str, str], base_url: str) -> ResolvedLink:
def resolve_link(link: Link, routes: Dict[str, str], base_url: str,
repo_root: Optional[Path] = None) -> ResolvedLink:
base = base_url.rstrip("/")
raw = link.raw.strip()

Expand Down Expand Up @@ -67,10 +70,19 @@ def made(kind: str, url: str = "", reason: str = "") -> ResolvedLink:
if path.startswith(PROD_ONLY_PREFIXES):
return made(EXTERNAL, PROD_URL + raw)
return made(INTERNAL, base + raw)
if repo_root is not None and not link.html:
# Docusaurus bundles relative links to files (images in docs/assets/) under a hashed URL,
# so the file on disk is what has to exist.
target = posixpath.normpath(posixpath.join(posixpath.dirname(link.file), plain))
if (repo_root / target).is_file():
return made(SKIPPED, reason="bundled file")
if posixpath.splitext(plain)[1].lower() in ASSET_SUFFIXES:
return made(UNRESOLVED, target, "missing-asset")
if page is None:
return made(SKIPPED, reason="relative link in file without route")
return made(INTERNAL, urljoin(base + page, raw))


def resolve_all(links: Iterable[Link], routes: Dict[str, str], base_url: str) -> List[ResolvedLink]:
return [resolve_link(link, routes, base_url) for link in links]
def resolve_all(links: Iterable[Link], routes: Dict[str, str], base_url: str,
repo_root: Optional[Path] = None) -> List[ResolvedLink]:
return [resolve_link(link, routes, base_url, repo_root) for link in links]
19 changes: 19 additions & 0 deletions .devenv/scripts/tests/test_linkcheck_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ def test_fragment_in_unrouted_partial_skipped(self):
r = resolve_link(Link("docs/documentation/_partial.md", 1, "#a"), ROUTES, BASE)
self.assertEqual(r.kind, SKIPPED)

def test_relative_asset_on_disk_is_bundled(self):
with tempfile.TemporaryDirectory() as tmp:
asset = Path(tmp) / "docs/assets/documentation/a.png"
asset.parent.mkdir(parents=True)
asset.write_bytes(b"")
r = resolve_link(Link(SRC, 7, "../../../assets/documentation/a.png"), ROUTES, BASE, Path(tmp))
self.assertEqual((r.kind, r.reason), (SKIPPED, "bundled file"))

def test_relative_asset_missing_on_disk_is_unresolved(self):
with tempfile.TemporaryDirectory() as tmp:
r = resolve_link(Link(SRC, 7, "../../../assets/documentation/b.png"), ROUTES, BASE, Path(tmp))
self.assertEqual((r.kind, r.url, r.reason),
(UNRESOLVED, "docs/assets/documentation/b.png", "missing-asset"))

def test_relative_non_asset_missing_on_disk_uses_browser_semantics(self):
with tempfile.TemporaryDirectory() as tmp:
r = resolve_link(Link(SRC, 7, "../../user-guide/history/"), ROUTES, BASE, Path(tmp))
self.assertEqual((r.kind, r.url), (INTERNAL, BASE + "/docs/documentation/user-guide/history/"))

def test_md_link_from_partial_resolves_against_partial_dir(self):
r = resolve_link(Link("docs/documentation/user-guide/_p.md", 1, "history.md"), ROUTES, BASE)
self.assertEqual((r.kind, r.url), (INTERNAL, BASE + "/docs/documentation/user-guide/history"))
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@ npm run typecheck

Run the typecheck and production build before opening a pull request.

## Images

Documentation images live in `docs/assets/`, next to the content, so they are versioned with the docs.
Reference them with a path relative to the Markdown file:

```markdown
![Example img](../../assets/documentation/user-guide/example.png)
```

For HTML attributes such as `width`, use JSX with `require`, since relative paths in a plain `src` are not resolved:

```jsx
<img src={require('../../assets/documentation/user-guide/example.png').default} width="150px"/>
```

`static/img/` only holds site-wide assets such as the logo and favicon.

## Versioning

The docs in `docs/` describe the upcoming release. To freeze them for a release, run:

```bash
npm run docusaurus docs:version 2.2
```

This copies `docs/` to `versioned_docs/version-2.2/` and adds the version to `versions.json`. The newest version is
then served at `/docs/`, the content of `docs/` at `/docs/next/`, and the navbar shows a version dropdown.
BPMN diagrams of a version are served at `/bpmn/version-2.2/`.

## Link check

`.devenv/scripts/check-links.py` finds broken internal and external links in `docs/` and reports them
Expand Down
Loading