Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
2154c52
ci: upload docs on icp-pages branch
ilbertt Aug 6, 2025
7627f76
ci: update workflow title
ilbertt Aug 6, 2025
acdab8d
fix: remove backticks and add push step
ilbertt Aug 6, 2025
952c6e2
fix: add github token
ilbertt Aug 6, 2025
2f609fe
ci: build docs only
ilbertt Aug 6, 2025
fb43fba
fix: remove colon
ilbertt Aug 6, 2025
c6a72b6
fix: build only docs
ilbertt Aug 6, 2025
acec887
fix: typos
ilbertt Aug 6, 2025
e97dccd
fix: remove symlink if it exist
ilbertt Aug 6, 2025
2a8cbfe
ci: test action with beta
ilbertt Aug 6, 2025
acbd392
fix: beta check
ilbertt Aug 6, 2025
6ab1b2b
fix: check for STABLE_VERSION
ilbertt Aug 6, 2025
c90f3af
ci: test a non-valid version
ilbertt Aug 6, 2025
34e0729
ci: test next version
ilbertt Aug 6, 2025
dbc318e
fix: latest should not change
ilbertt Aug 6, 2025
60dfdac
ci: test v3 again
ilbertt Aug 6, 2025
0a101aa
ci: test label
ilbertt Aug 6, 2025
1c168f3
ci: test another version
ilbertt Aug 6, 2025
7982fda
ci: test beta
ilbertt Aug 6, 2025
46cc614
ci: test not allowed version
ilbertt Aug 6, 2025
b47a743
ci: test v3 again
ilbertt Aug 6, 2025
03c4d88
ci: test with v5
ilbertt Aug 6, 2025
65ab630
chore: test minor
ilbertt Aug 7, 2025
70d50ec
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 7, 2025
9e7b0d0
ci: test patch version
ilbertt Aug 7, 2025
db3936e
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 7, 2025
e871c0e
fix: do not commit and push if no file was touched
ilbertt Aug 7, 2025
cf0f2f6
ci: simplify detecting git changes
ilbertt Aug 7, 2025
56977f4
ci: use github action from ci-tools
ilbertt Aug 8, 2025
8785a3e
fix: prefix with `v`
ilbertt Aug 8, 2025
5e4a501
ci: point to specific commit
ilbertt Aug 11, 2025
e8695a1
ci: update commit
ilbertt Aug 11, 2025
3ee3117
ci: update commit
ilbertt Aug 11, 2025
ec38169
ci: change commit and prepare version step
ilbertt Aug 11, 2025
4bcec5c
ci: fix version
ilbertt Aug 11, 2025
1dd2c1e
ci: update assemble docs action commit
ilbertt Aug 11, 2025
409d570
ci: update ref for assemble docs
ilbertt Aug 11, 2025
3a28013
ci: update ref for assemble docs
ilbertt Aug 11, 2025
fef692b
ci: test beta version
ilbertt Aug 11, 2025
57c65d7
ci: test next tag
ilbertt Aug 11, 2025
d33ba69
chore: update action version
ilbertt Aug 11, 2025
e195b0b
feat: submit docs to dfinity/icp-js-sdk-docs repo
ilbertt Aug 11, 2025
8254712
refactor: explicit params
ilbertt Aug 11, 2025
1bd7adc
feat: versions dropdown plugin
ilbertt Aug 11, 2025
f3a97ea
ci: pin submit-docs action version
ilbertt Aug 11, 2025
6d55abf
ci:m update submit-docs action ref
ilbertt Aug 11, 2025
2279b63
fix: correct versions.json path
ilbertt Aug 11, 2025
f6ebaa7
ci: use action branch
ilbertt Aug 11, 2025
18b1508
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 12, 2025
5072f5c
ci: update param
ilbertt Aug 12, 2025
d6ec937
ci: add token for icp-js-sdk-docs
ilbertt Aug 12, 2025
68293cb
fix: add current tag to version dropdown if not present
ilbertt Aug 12, 2025
5e3e965
refactor: rename from core to agent
ilbertt Aug 12, 2025
85a02c9
feat: index page and version dropdown fixes
ilbertt Aug 12, 2025
4a008ef
feat: add publish docs step to publish action
ilbertt Aug 12, 2025
573d45e
refactor: add todos
ilbertt Aug 12, 2025
717d3b2
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 12, 2025
4c4b54a
ci: update actions branches
ilbertt Aug 13, 2025
976c81a
ci: update actions references
ilbertt Aug 13, 2025
24c9aef
ci: update steps
ilbertt Aug 13, 2025
d301638
ci: point main branch for docs actions
ilbertt Aug 13, 2025
132a32f
chore: remove temporary action
ilbertt Aug 13, 2025
99d58c3
Revert "chore: remove temporary action"
ilbertt Aug 13, 2025
6ad707b
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 13, 2025
002194d
fix: use text size from theme
ilbertt Aug 13, 2025
643fd8a
refactor: update versions labels
ilbertt Aug 14, 2025
f2761e0
fix: handle trailing slash
ilbertt Aug 14, 2025
9e47d5b
feat: show version above dropdown
ilbertt Aug 15, 2025
7527033
ci: update publish action
ilbertt Aug 18, 2025
145da31
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 20, 2025
0567692
refactor: move to plugins
ilbertt Aug 20, 2025
042538d
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 20, 2025
261ff67
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 20, 2025
ed5ce57
refactor: move release notes to upgrading folder
ilbertt Aug 20, 2025
831c478
refactor: move upgrading guide to v4 path
ilbertt Aug 20, 2025
341c253
Merge remote-tracking branch 'origin/luca/upgrading-guide' into luca/…
ilbertt Aug 20, 2025
f08aa65
Merge remote-tracking branch 'origin/main' into luca/upgrading-guide
ilbertt Aug 20, 2025
532ccca
Merge remote-tracking branch 'origin/main' into luca/upgrading-guide
ilbertt Aug 20, 2025
17bda4f
Merge remote-tracking branch 'origin/luca/upgrading-guide' into luca/…
ilbertt Aug 20, 2025
7ffb50b
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 20, 2025
faa053f
ci: remove temporary action
ilbertt Aug 20, 2025
9695ac6
Merge remote-tracking branch 'origin/main' into luca/SDK-2264-push-docs
ilbertt Aug 20, 2025
638e025
Revert "ci: remove temporary action"
ilbertt Aug 20, 2025
33390f2
docs: remove @icp-sdk/core references for now
ilbertt Aug 20, 2025
5d4ab0a
Merge remote-tracking branch 'origin/luca/SDK-2264-push-docs' into lu…
ilbertt Aug 20, 2025
029f198
feat: v4 docs
ilbertt Aug 20, 2025
52724ec
ci: remove temporary action
ilbertt Aug 20, 2025
2b37627
Merge remote-tracking branch 'origin/main' into luca/v4-docs
ilbertt Aug 21, 2025
b6bbc0d
chore: remove packages
ilbertt Aug 21, 2025
9a426f1
Merge remote-tracking branch 'origin/main' into luca/v4-docs
ilbertt Aug 22, 2025
5c99f2d
refactor: docs revamp
ilbertt Aug 22, 2025
746b280
Merge remote-tracking branch 'origin/main' into luca/v4-docs
ilbertt Aug 22, 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
35 changes: 20 additions & 15 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const BASE_DOCS_PATH = '/core';
const docsVersion = process.env.DOCS_VERSION ?? 'local';
const packagesDir = '../packages';

const UPGRADE_BANNER_CONTENT =
'Still using <code>@dfinity/agent</code>? Migrate to <a href="/core/latest/upgrading/v4">@icp-sdk/core</a>!';

// https://astro.build/config
export default defineConfig({
site: 'https://js.icp.build/',
Expand All @@ -37,16 +34,33 @@ export default defineConfig({
exclude: [
`${packagesDir}/core`,
`${packagesDir}/migrate`,
`${packagesDir}/assets`,
`${packagesDir}/auth-client`,
`${packagesDir}/use-auth-client`,
],
},
frontmatter: {
editUrl: false,
next: true,
prev: true,
banner: {
content: UPGRADE_BANNER_CONTENT,
},
},
prependSidebar: [
{
label: 'Getting Started',
items: [
{ label: 'Overview', link: '/' },
{ label: 'Installation', link: '/installation' },
{ label: 'Quick Start', link: '/quick-start' },
{ label: 'Typescript', link: '/typescript' },
],
},
],
appendSidebar: [
{
label: 'Upgrading',
autogenerate: { directory: 'upgrading', collapsed: true },
},
],
}),
additionalFilesPlugin({
additionalFiles: [
Expand All @@ -58,9 +72,6 @@ export default defineConfig({
editUrl: false,
next: false,
prev: false,
banner: {
content: UPGRADE_BANNER_CONTENT,
},
},
},
],
Expand All @@ -69,12 +80,6 @@ export default defineConfig({
versionsJsonPath: `${BASE_DOCS_PATH}/versions.json`,
}),
],
sidebar: [
{
label: 'Upgrading',
autogenerate: { directory: 'upgrading', collapsed: true },
},
],
}),
],
});
92 changes: 48 additions & 44 deletions docs/plugins/src/libs.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import fs from "node:fs/promises";
import path from "node:path";
import {
Application,
ProjectReflection,
ReflectionKind,
type TypeDocOptions,
} from "typedoc";
import type { StarlightPlugin } from "@astrojs/starlight/types";
import { type PluginOptions as TypeDocMarkdownOptions } from "typedoc-plugin-markdown";

import { DOCS_DIR, TMP_DIR } from "./utils/constants.ts";
import { type Frontmatter } from "./utils/types.ts";
import { titleFromFilename, titleFromIdCapitalized } from "./utils/string.ts";
import { processMarkdown } from "./utils/markdown.ts";
import fs from 'node:fs/promises';
import path from 'node:path';
import { Application, ProjectReflection, ReflectionKind, type TypeDocOptions } from 'typedoc';
import type { StarlightPlugin } from '@astrojs/starlight/types';
import { type PluginOptions as TypeDocMarkdownOptions } from 'typedoc-plugin-markdown';

import { DOCS_DIR, TMP_DIR } from './utils/constants.ts';
import type { Frontmatter, Sidebar } from './utils/types.ts';
import { titleFromFilename, titleFromIdCapitalized } from './utils/string.ts';
import { processMarkdown } from './utils/markdown.ts';

async function generateApiDocs({
baseDir,
typeDoc,
}: LibsLoaderOptions): Promise<ProjectReflection> {
const defaultTypeDocOptions: LibsLoaderTypeDocOptions = {
entryPoints: [`${baseDir}/*`],
entryPointStrategy: "packages",
entryPointStrategy: 'packages',
packageOptions: {
entryPoints: ["src/index.ts"],
tsconfig: "./tsconfig.json",
readme: "none",
entryPoints: ['src/index.ts'],
tsconfig: './tsconfig.json',
readme: 'none',
},
plugin: ["typedoc-plugin-markdown", "typedoc-plugin-frontmatter"],
tsconfig: "./tsconfig.typedoc.json",
outputs: [{ name: "markdown", path: TMP_DIR }],
readme: "none",
plugin: ['typedoc-plugin-markdown', 'typedoc-plugin-frontmatter'],
tsconfig: './tsconfig.typedoc.json',
outputs: [{ name: 'markdown', path: TMP_DIR }],
readme: 'none',
hidePageTitle: true,
hideBreadcrumbs: true,
hidePageHeader: true,
Expand All @@ -42,7 +37,7 @@ async function generateApiDocs({

const project = await app.convert();
if (!project) {
throw new Error("Failed to convert project with TypeDoc");
throw new Error('Failed to convert project with TypeDoc');
}
await app.generateOutputs(project);

Expand Down Expand Up @@ -84,25 +79,32 @@ export interface LibsLoaderOptions {
* Frontmatter applied to every markdown file generated by TypeDoc.
*/
frontmatter?: Frontmatter;

/**
* Sidebar items to add before the generated sidebar items.
*/
prependSidebar?: Sidebar;

/**
* Sidebar items to add after the generated sidebar items.
*/
appendSidebar?: Sidebar;
Comment thread
ilbertt marked this conversation as resolved.
}

export type LibsLoaderTypeDocOptions = TypeDocMarkdownOptions & TypeDocOptions;

export function libsPlugin(opts: LibsLoaderOptions): StarlightPlugin {
return {
name: "@dfinity/starlight/libs",
name: '@dfinity/starlight/libs',
hooks: {
async "config:setup"(ctx) {
async 'config:setup'(ctx) {
const site = ctx.astroConfig.site;
const baseDir = path.resolve(opts.baseDir.toString());
const outDir = path.resolve(
DOCS_DIR,
opts.outDir?.toString() ?? "libs",
);
const outDir = path.resolve(DOCS_DIR, opts.outDir?.toString() ?? 'libs');
const clean = opts.clean ?? true;

if (!site) {
throw new Error("Site URL is not defined in Astro config");
throw new Error('Site URL is not defined in Astro config');
}

if (clean) {
Expand All @@ -115,13 +117,13 @@ export function libsPlugin(opts: LibsLoaderOptions): StarlightPlugin {
const librarySidebarItems = [];
const modules = project.getChildrenByKind(ReflectionKind.Module);
for (const { name } of modules) {
const id = name.startsWith("@") ? name.split("/")[1]! : name;
const id = name.startsWith('@') ? name.split('/')[1]! : name;
const outputRootDir = path.resolve(outDir, id);
const outputApiDir = path.resolve(outputRootDir, "api");
const outputApiDir = path.resolve(outputRootDir, 'api');
const title = titleFromIdCapitalized(id);

await processMarkdown({
inputPath: path.resolve(baseDir, id, "README.md"),
inputPath: path.resolve(baseDir, id, 'README.md'),
outputPath: path.resolve(outputRootDir, `index.md`),
frontmatter: {
title,
Expand All @@ -135,14 +137,12 @@ export function libsPlugin(opts: LibsLoaderOptions): StarlightPlugin {
recursive: true,
});
for (const file of files) {
if (file.isFile() && file.name.endsWith(".md")) {
if (file.isFile() && file.name.endsWith('.md')) {
const prefix = path.relative(apiSrcDir, file.parentPath);
const inputFileName = file.name;
const isReadme = inputFileName.endsWith("README.md");
const outputFileName = isReadme ? "index.md" : inputFileName;
const title = isReadme
? "Overview"
: titleFromFilename(file.name);
const isReadme = inputFileName.endsWith('README.md');
const outputFileName = isReadme ? 'index.md' : inputFileName;
const title = isReadme ? 'Overview' : titleFromFilename(file.name);

await processMarkdown({
inputPath: path.resolve(apiSrcDir, prefix, inputFileName),
Expand All @@ -160,11 +160,11 @@ export function libsPlugin(opts: LibsLoaderOptions): StarlightPlugin {
collapsed: true,
items: [
{
label: "Overview",
label: 'Overview',
link: `/libs/${id}`,
},
{
label: "API Reference",
label: 'API Reference',
collapsed: true,
autogenerate: {
collapsed: true,
Expand All @@ -177,8 +177,12 @@ export function libsPlugin(opts: LibsLoaderOptions): StarlightPlugin {

ctx.updateConfig({
sidebar: [
{ label: "Overview", link: "/" },
{ label: "Libraries", items: librarySidebarItems },
...(opts.prependSidebar || []),
{
label: 'Modules',
items: librarySidebarItems,
},
...(opts.appendSidebar || []),
Comment thread
ilbertt marked this conversation as resolved.
...(ctx.config.sidebar || []),
],
});
Expand Down
106 changes: 51 additions & 55 deletions docs/plugins/src/markdown-urls.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,86 @@
import { type AstroIntegrationLogger, type RemarkPlugins } from "astro";
import { visit } from "unist-util-visit";
import path from "node:path";
import { type StarlightPlugin } from "@astrojs/starlight/types";
import { DOCS_DIR } from "./utils/constants.ts";
import { readdirSync } from "node:fs";
import { type AstroIntegrationLogger, type RemarkPlugins } from 'astro';
import { visit } from 'unist-util-visit';
import path from 'node:path';
import { type StarlightPlugin } from '@astrojs/starlight/types';
import { DOCS_DIR } from './utils/constants.ts';
import { readdirSync } from 'node:fs';

type RemarkPlugin = RemarkPlugins[number];

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

visit(tree, "link", (node) => {
const url = node.url;
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;
}
// 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;
}
// 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;
}

// if the url is a cross-package link, go back one level and add the api directory
const normalizedUrl = url.replace(crossPackageUrlRegex, '../../$1/api');
const absoluteLinkedFilePath = path.resolve(currentFileDir, normalizedUrl);
// if the url is a cross-package link, go back one level and add the api directory
const normalizedUrl = url.replace(crossPackageUrlRegex, '../../$1/api');
const absoluteLinkedFilePath = path.resolve(currentFileDir, normalizedUrl);

// normalize all other relative URLs to the docs directory
const relativeToDocs = path.relative(docsDir, absoluteLinkedFilePath);
const nodeUrl = `${baseUrl}${
relativeToDocs.replace(/(index)?\.mdx?(#.*)?$/, "$2").toLowerCase()
}`;
logger.debug(`Normalizing URL: ${url} -> ${nodeUrl}`);
// normalize all other relative URLs to the docs directory
const relativeToDocs = path.relative(docsDir, absoluteLinkedFilePath);
const nodeUrl = `${baseUrl}${relativeToDocs
.replace(/(index)?\.mdx?(#.*)?$/, '$2')
.toLowerCase()}`;
logger.debug(`Normalizing URL: ${url} -> ${nodeUrl}`);

node.url = nodeUrl;
});
};
node.url = nodeUrl;
});
};

interface MarkdownUrlsPluginOptions {
interface MarkdownUrlsPluginOptions {
packagesDir: string;
}

export function markdownUrlsPlugin({ packagesDir }: MarkdownUrlsPluginOptions): StarlightPlugin {
return {
name: "@dfinity/starlight/markdown-urls",
name: '@dfinity/starlight/markdown-urls',
hooks: {
"config:setup": (ctx) => {
'config:setup': ctx => {
const site = ctx.astroConfig.site;

// get all the packages in the packagesDir
const packages = readdirSync(packagesDir);
const crossPackageUrlRegex = new RegExp(`\\.\\.\\/(${packages.join('|')})`);
const crossPackageUrlRegex = new RegExp(`\\.\\.\\/(${packages.join('|')})/`);
Comment thread
ilbertt marked this conversation as resolved.

ctx.addIntegration({
name: "libs-astro-plugin",
name: 'libs-astro-plugin',
hooks: {
"astro:config:setup": ({ updateConfig, config, logger }) => {
'astro:config:setup': ({ updateConfig, config, logger }) => {
updateConfig({
markdown: {
remarkPlugins: [
...config.markdown.remarkPlugins,
[markdownUrlsRemarkPlugin, [
logger,
DOCS_DIR,
site,
ctx.astroConfig.base,
crossPackageUrlRegex,
]],
[
markdownUrlsRemarkPlugin,
[logger, DOCS_DIR, site, ctx.astroConfig.base, crossPackageUrlRegex],
],
],
},
});
Expand Down
11 changes: 6 additions & 5 deletions docs/plugins/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { docsSchema } from "@astrojs/starlight/schema";
import type { z } from "astro/zod";
import { docsSchema } from '@astrojs/starlight/schema';
import { type StarlightUserConfig } from '@astrojs/starlight/types';
import type { z } from 'astro/zod';

export type Frontmatter = Partial<
z.infer<ReturnType<ReturnType<typeof docsSchema>>>
>;
export type Frontmatter = Partial<z.infer<ReturnType<ReturnType<typeof docsSchema>>>>;

export type Sidebar = StarlightUserConfig['sidebar'];
Loading
Loading