Skip to content

Commit e95a244

Browse files
authored
feat!: use markdown for projects assets (#89)
Switches projects assets to publish markdown docs instead of compiled web assets. Related: dfinity/ci-tools#52
1 parent 740a5bd commit e95a244

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2381
-145
lines changed

.github/CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ To serve the root docs project, run:
133133
deno task docs:start
134134
```
135135

136+
> Note: You need to run `deno task docs:prebuild` before to ensure the projects
137+
> files are added to the docs.
138+
136139
### Build root docs project
137140

138141
To build the root docs project, run:
@@ -141,6 +144,16 @@ To build the root docs project, run:
141144
deno task docs:build
142145
```
143146

147+
### Update projects schema
148+
149+
If you make changes to the [`projects-schema.json`](../projects-schema.json)
150+
file, you need to update the [`projects-schema.d.ts`](../projects-schema.d.ts)
151+
file. To do this, run:
152+
153+
```shell
154+
deno task types:projects
155+
```
156+
144157
### Serve all docs using Juno
145158

146159
To start the Juno emulator, run:

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ node_modules/
99

1010
# MacOS
1111
.DS_Store
12+
13+
# Ignore all unzipped content from projects
14+
docs/src/content/docs/**
15+
# Track any file you want to keep manually here
16+
!docs/src/content/docs/index.mdx
17+
18+
# Ignore all unzipped html pages from projects
19+
docs/src/pages/**
20+
# Track any file you want to keep manually here
21+
# e.g. !docs/src/pages/index.astro

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This repository contains the documentation for the ICP JavaScript SDK hosted on
1111
```json
1212
[
1313
{
14+
"title": "Core",
15+
"description": "Base library for Internet Computer apps.",
1416
"repository": "dfinity/icp-js-core",
1517
"subdirectory": "core"
1618
},
@@ -23,7 +25,7 @@ This repository contains the documentation for the ICP JavaScript SDK hosted on
2325
```
2426

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

2830
```html
2931
<CardGrid stagger>

deno.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
{
22
"tasks": {
3-
"predeploy": "deno run --no-prompt --allow-read --allow-write=\"./dist\" scripts/predeploy.ts",
43
"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",
54
"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",
6-
"docs:build": "astro build --root ./docs",
5+
"docs:prebuild": "deno run --no-prompt --allow-read --allow-write=\"./docs/src/content/docs,./docs/src/pages\" scripts/prebuild.ts",
6+
"docs:build": "deno task docs:prebuild && astro build --root ./docs",
7+
"docs:preview": "astro preview --root ./docs",
78
"docs:start": "astro dev --root ./docs",
9+
"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",
810
"juno": "juno"
911
},
1012
"imports": {
13+
"@astrojs/react": "npm:@astrojs/react@^4.3.0",
14+
"@pagefind/default-ui": "npm:@pagefind/default-ui@^1.4.0",
15+
"@radix-ui/react-navigation-menu": "npm:@radix-ui/react-navigation-menu@^1.2.14",
16+
"@types/react": "npm:@types/react@^19.1.12",
17+
"astro-integration-kit": "npm:astro-integration-kit@^0.19.0",
1118
"fs": "node:fs",
19+
"json-schema-to-typescript": "npm:json-schema-to-typescript@^15.0.4",
20+
"pagefind": "npm:pagefind@^1.4.0",
21+
"react": "npm:react@^19.1.1",
22+
"react-dom": "npm:react-dom@^19.1.1",
23+
"unist-util-visit": "npm:unist-util-visit@^5.0.0",
1224
"url": "node:url",
25+
"util": "node:util",
1326
"path": "node:path",
1427
"@actions/core": "npm:@actions/core@^1.11.1",
1528
"@actions/github": "npm:@actions/github@^6.0.1",

deno.lock

Lines changed: 499 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"canisters": {
1212
"docs": {
1313
"type": "assets",
14-
"build": ["deno task docs:build", "deno task predeploy"],
14+
"build": ["deno task docs:build"],
1515
"source": ["dist"],
1616
"frontend": {}
1717
}

docs/astro.config.mjs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,54 @@
11
// @ts-check
22
import { defineConfig, passthroughImageService } from "astro/config";
3+
import react from "@astrojs/react";
34
import starlight from "@astrojs/starlight";
5+
import { multiSidebarPlugin } from "./plugins/multi-sidebar/index.ts";
6+
import { markdownUrlsPlugin } from "./plugins/markdown-urls/index.ts";
7+
import { getProjectsConfig, getSidebarsFromProjects } from "./projects.ts";
8+
9+
const projectsConfig = getProjectsConfig();
410

511
// https://astro.build/config
612
export default defineConfig({
713
site: "https://js.icp.build/",
814
image: {
915
service: passthroughImageService(),
1016
},
17+
output: "static",
18+
vite: {
19+
server: {
20+
fs: {
21+
strict: false,
22+
},
23+
},
24+
ssr: {
25+
// See https://docs.astro.build/en/guides/troubleshooting/#adding-dependencies-to-astro-in-a-monorepo
26+
noExternal: ["@astrojs/react"],
27+
},
28+
},
1129
integrations: [
30+
react(),
1231
starlight({
13-
title: "ICP JavaScript SDK Docs",
32+
title: "ICP JS SDK Docs",
1433
logo: {
1534
src: "./src/assets/icp.svg",
1635
alt: "Internet Computer Logo",
17-
replacesTitle: true,
1836
},
37+
favicon: "/favicon.png",
1938
customCss: [
2039
"./src/assets/layers.css",
2140
"./src/assets/theme.css",
2241
"./src/assets/overrides.css",
2342
"./src/assets/elements.css",
2443
],
2544
pagefind: false,
26-
tableOfContents: false,
2745
sidebar: [],
46+
plugins: [
47+
multiSidebarPlugin({
48+
sidebars: getSidebarsFromProjects(projectsConfig),
49+
}),
50+
markdownUrlsPlugin(),
51+
],
2852
}),
2953
],
3054
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type StarlightPlugin } from "@astrojs/starlight/types";
2+
import { markdownUrlsIntegration } from "./integration.ts";
3+
4+
export function markdownUrlsPlugin(): StarlightPlugin {
5+
return {
6+
name: "starlight-markdown-urls-plugin",
7+
hooks: {
8+
"config:setup": (ctx) => {
9+
ctx.addIntegration(markdownUrlsIntegration());
10+
},
11+
},
12+
};
13+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { defineIntegration } from "astro-integration-kit";
2+
import { type AstroIntegrationLogger, type RemarkPlugins } from "astro";
3+
import { visit } from "unist-util-visit";
4+
import path from "path";
5+
6+
const currentDir = import.meta.dirname!;
7+
const docsDir = path.join(currentDir, "../../src/content/docs");
8+
9+
type RemarkPlugin = RemarkPlugins[number];
10+
11+
const markdownUrlsRemarkPlugin: RemarkPlugin = ([logger, site]: [
12+
AstroIntegrationLogger,
13+
string,
14+
]) =>
15+
(tree, file) => {
16+
const currentFileDir = path.dirname(file.path);
17+
18+
visit(tree, "link", (node) => {
19+
const url = node.url;
20+
21+
// take full URLs to the current site and make them relative
22+
if (url.startsWith(site)) {
23+
node.url = new URL(url).pathname;
24+
return;
25+
}
26+
27+
// skip any other full URLs
28+
if (
29+
url.startsWith("https://") ||
30+
url.startsWith("/") ||
31+
url.startsWith("http://") ||
32+
url.startsWith("mailto:") ||
33+
url.startsWith("#")
34+
) {
35+
logger.debug(`Skipping URL: ${url}`);
36+
return;
37+
}
38+
39+
const resolvedUrl = path.resolve(currentFileDir, url);
40+
const relativeToDocs = path.relative(docsDir, resolvedUrl);
41+
const nodeUrl = `/${
42+
relativeToDocs
43+
.replace(/(index)?\.mdx?(#.*)?$/, "$2")
44+
.toLowerCase()
45+
}`;
46+
logger.debug(`Normalizing URL: ${url} -> ${nodeUrl}`);
47+
48+
node.url = nodeUrl;
49+
});
50+
};
51+
52+
export const markdownUrlsIntegration = defineIntegration({
53+
name: "starlight-markdown-urls-integration",
54+
setup: () => {
55+
return {
56+
hooks: {
57+
"astro:config:setup": ({ updateConfig, config, logger }) => {
58+
updateConfig({
59+
markdown: {
60+
remarkPlugins: [
61+
...config.markdown.remarkPlugins,
62+
[
63+
markdownUrlsRemarkPlugin,
64+
[
65+
logger,
66+
config.site,
67+
],
68+
],
69+
],
70+
},
71+
});
72+
},
73+
},
74+
};
75+
},
76+
});

docs/plugins/mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
throw new Error(
2+
"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.",
3+
);

0 commit comments

Comments
 (0)