Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bbc59ec
feat: multi sidebar and header plugins
ilbertt Sep 4, 2025
75126ae
fix: shorten title
ilbertt Sep 5, 2025
f180933
fix: make modal appear below
ilbertt Sep 5, 2025
58bbed3
fix: header and sidebar border color
ilbertt Sep 5, 2025
c5e6451
feat: mobile project switcher
ilbertt Sep 5, 2025
748018a
fix: no border for project switcher
ilbertt Sep 5, 2025
faba1ec
feat: multi sidebar plugin
ilbertt Sep 5, 2025
0fd1784
feat: ignore projects assets
ilbertt Sep 5, 2025
e237d80
chore: update contributing guide and generate projects schema types
ilbertt Sep 5, 2025
bcb14f6
refactor: rename function
ilbertt Sep 5, 2025
e897e43
fix: do not slugify versions paths
ilbertt Sep 7, 2025
209bc4e
build: update deno lock
ilbertt Sep 7, 2025
ed05eb1
refactor: remove unused code
ilbertt Sep 7, 2025
e37a38c
fix: lowercase page urls
ilbertt Sep 7, 2025
0c071c6
feat: resolve relative links
ilbertt Sep 7, 2025
0ea07e8
feat: animate project selector
ilbertt Sep 7, 2025
8b51be6
build: update deno lock
ilbertt Sep 7, 2025
158394d
feat: support html pages
ilbertt Sep 8, 2025
4849275
refactor: prebuild instead of predeploy
ilbertt Sep 8, 2025
88490c7
feat: pagefind indexes
ilbertt Sep 8, 2025
76914f5
refactor: rename integrations file
ilbertt Sep 8, 2025
4534923
build: update deno lock
ilbertt Sep 8, 2025
5b6d06d
feat: pagefind for each project
ilbertt Sep 8, 2025
9aaafa9
refactor: add starlight original components
ilbertt Sep 8, 2025
20174f6
fix: accept root links in sidebar
ilbertt Sep 8, 2025
497dfef
build: pull markdown instead of final assets
ilbertt Sep 8, 2025
958f6c7
fix: use docs dist folder
ilbertt Sep 8, 2025
d8751d6
chore: add favicon
ilbertt Sep 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ To serve the root docs project, run:
deno task docs:start
```

> Note: You need to run `deno task docs:prebuild` before to ensure the projects
> files are added to the docs.

### Build root docs project

To build the root docs project, run:
Expand All @@ -141,6 +144,16 @@ To build the root docs project, run:
deno task docs:build
```

### Update projects schema

If you make changes to the [`projects-schema.json`](../projects-schema.json)
file, you need to update the [`projects-schema.d.ts`](../projects-schema.d.ts)
file. To do this, run:

```shell
deno task types:projects
```

### Serve all docs using Juno

To start the Juno emulator, run:
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ node_modules/

# MacOS
.DS_Store

# Ignore all unzipped content from projects
docs/src/content/docs/**
# Track any file you want to keep manually here
!docs/src/content/docs/index.mdx

# Ignore all unzipped html pages from projects
docs/src/pages/**
# Track any file you want to keep manually here
# e.g. !docs/src/pages/index.astro
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This repository contains the documentation for the ICP JavaScript SDK hosted on
```json
[
{
"title": "Core",
"description": "Base library for Internet Computer apps.",
"repository": "dfinity/icp-js-core",
"subdirectory": "core"
},
Expand All @@ -23,7 +25,7 @@ This repository contains the documentation for the ICP JavaScript SDK hosted on
```

2. Add a link and short description for the sub-project in the
[`index.astro`](./docs/src/pages/index.astro) file:
[`index.mdx`](./docs/src/content/docs/index.mdx) file:

```html
<CardGrid stagger>
Expand Down
17 changes: 15 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
{
"tasks": {
"predeploy": "deno run --no-prompt --allow-read --allow-write=\"./dist\" scripts/predeploy.ts",
"pull-project-docs": "deno run --no-prompt --allow-read --allow-net=\"github.com,codeload.github.com\" --allow-write=\"./public,$TMPDIR\" scripts/pull-project-docs.ts",
"fetch-project-commit": "deno run --no-prompt --allow-read --allow-env --allow-net=\"github.com,api.github.com\" --allow-write=\"$TMPDIR\" scripts/fetch-project-commit.ts",
"docs:build": "astro build --root ./docs",
"docs:prebuild": "deno run --no-prompt --allow-read --allow-write=\"./docs/src/content/docs,./docs/src/pages\" scripts/prebuild.ts",
"docs:build": "deno task docs:prebuild && astro build --root ./docs",
"docs:preview": "astro preview --root ./docs",
"docs:start": "astro dev --root ./docs",
"types:projects": "deno run --no-prompt --allow-read --allow-write=\"projects-schema.d.ts\" --allow-env --allow-sys=\"cpus\" json-schema-to-typescript --input projects-schema.json --output projects-schema.d.ts",
"juno": "juno"
},
"imports": {
"@astrojs/react": "npm:@astrojs/react@^4.3.0",
"@pagefind/default-ui": "npm:@pagefind/default-ui@^1.4.0",
"@radix-ui/react-navigation-menu": "npm:@radix-ui/react-navigation-menu@^1.2.14",
"@types/react": "npm:@types/react@^19.1.12",
"astro-integration-kit": "npm:astro-integration-kit@^0.19.0",
"fs": "node:fs",
"json-schema-to-typescript": "npm:json-schema-to-typescript@^15.0.4",
"pagefind": "npm:pagefind@^1.4.0",
"react": "npm:react@^19.1.1",
"react-dom": "npm:react-dom@^19.1.1",
"unist-util-visit": "npm:unist-util-visit@^5.0.0",
"url": "node:url",
"util": "node:util",
"path": "node:path",
"@actions/core": "npm:@actions/core@^1.11.1",
"@actions/github": "npm:@actions/github@^6.0.1",
Expand Down
540 changes: 499 additions & 41 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"canisters": {
"docs": {
"type": "assets",
"build": ["deno task docs:build", "deno task predeploy"],
"build": ["deno task docs:build"],
"source": ["dist"],
"frontend": {}
}
Expand Down
30 changes: 27 additions & 3 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
// @ts-check
import { defineConfig, passthroughImageService } from "astro/config";
import react from "@astrojs/react";
import starlight from "@astrojs/starlight";
import { multiSidebarPlugin } from "./plugins/multi-sidebar/index.ts";
import { markdownUrlsPlugin } from "./plugins/markdown-urls/index.ts";
import { getProjectsConfig, getSidebarsFromProjects } from "./projects.ts";

const projectsConfig = getProjectsConfig();

// https://astro.build/config
export default defineConfig({
site: "https://js.icp.build/",
image: {
service: passthroughImageService(),
},
output: "static",
vite: {
server: {
fs: {
strict: false,
},
},
ssr: {
// See https://docs.astro.build/en/guides/troubleshooting/#adding-dependencies-to-astro-in-a-monorepo
noExternal: ["@astrojs/react"],
},
},
integrations: [
react(),
starlight({
title: "ICP JavaScript SDK Docs",
title: "ICP JS SDK Docs",
logo: {
src: "./src/assets/icp.svg",
alt: "Internet Computer Logo",
replacesTitle: true,
},
favicon: "/favicon.png",
customCss: [
"./src/assets/layers.css",
"./src/assets/theme.css",
"./src/assets/overrides.css",
"./src/assets/elements.css",
],
pagefind: false,
tableOfContents: false,
sidebar: [],
plugins: [
multiSidebarPlugin({
sidebars: getSidebarsFromProjects(projectsConfig),
}),
markdownUrlsPlugin(),
],
}),
],
});
13 changes: 13 additions & 0 deletions docs/plugins/markdown-urls/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type StarlightPlugin } from "@astrojs/starlight/types";
import { markdownUrlsIntegration } from "./integration.ts";

export function markdownUrlsPlugin(): StarlightPlugin {
return {
name: "starlight-markdown-urls-plugin",
hooks: {
"config:setup": (ctx) => {
ctx.addIntegration(markdownUrlsIntegration());
},
},
};
}
76 changes: 76 additions & 0 deletions docs/plugins/markdown-urls/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { defineIntegration } from "astro-integration-kit";
import { type AstroIntegrationLogger, type RemarkPlugins } from "astro";
import { visit } from "unist-util-visit";
import path from "path";

const currentDir = import.meta.dirname!;
const docsDir = path.join(currentDir, "../../src/content/docs");

type RemarkPlugin = RemarkPlugins[number];

const markdownUrlsRemarkPlugin: RemarkPlugin = ([logger, site]: [
AstroIntegrationLogger,
string,
]) =>
(tree, file) => {
const currentFileDir = path.dirname(file.path);

visit(tree, "link", (node) => {
const url = node.url;

// take full URLs to the current site and make them relative
if (url.startsWith(site)) {
node.url = new URL(url).pathname;
return;
}

// skip any other full URLs
if (
url.startsWith("https://") ||
url.startsWith("/") ||
url.startsWith("http://") ||
url.startsWith("mailto:") ||
url.startsWith("#")
) {
logger.debug(`Skipping URL: ${url}`);
return;
}

const resolvedUrl = path.resolve(currentFileDir, url);
const relativeToDocs = path.relative(docsDir, resolvedUrl);
const nodeUrl = `/${
relativeToDocs
.replace(/(index)?\.mdx?(#.*)?$/, "$2")
.toLowerCase()
}`;
logger.debug(`Normalizing URL: ${url} -> ${nodeUrl}`);

node.url = nodeUrl;
});
};

export const markdownUrlsIntegration = defineIntegration({
name: "starlight-markdown-urls-integration",
setup: () => {
return {
hooks: {
"astro:config:setup": ({ updateConfig, config, logger }) => {
updateConfig({
markdown: {
remarkPlugins: [
...config.markdown.remarkPlugins,
[
markdownUrlsRemarkPlugin,
[
logger,
config.site,
],
],
],
},
});
},
},
};
},
});
3 changes: 3 additions & 0 deletions docs/plugins/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
throw new Error(
"There are no exports in the root module of this package. Import from submodules instead. Use intellisense or the docs to find the available submodules.",
);
15 changes: 15 additions & 0 deletions docs/plugins/multi-sidebar/components/ProjectSwitcher.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
import pluginConfig from 'virtual:starlight-multi-sidebar/config';
import { getCurrentPathComponents } from '../path.ts';
import { ProjectSwitcherReact } from './ProjectSwitcher.tsx';
import { getCurrentHeader } from '../config.ts';

const { projectPath } = getCurrentPathComponents(Astro.url.pathname);
const currentHeader = getCurrentHeader(pluginConfig, projectPath);
---

<ProjectSwitcherReact
client:only="react"
projectPath={projectPath}
currentHeader={currentHeader}
/>
Loading