Skip to content

Commit 5f6b16d

Browse files
authored
Merge pull request #25 from sanyuan0704/feat/support-0-js
feat: support zero js after production build
2 parents e3e5eb8 + 86ca50c commit 5f6b16d

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

docs/.island/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default defineConfig({
55
title: 'Island.js',
66
icon: '/island.png',
77
themeConfig: {
8+
outlineTitle: 'ON THIS PAGE',
89
socialLinks: [
910
{
1011
icon: 'github',

src/node/build.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ class SSGBuilder {
272272
${
273273
this.#config.enableSpa
274274
? `<script type="module" src="/${clientChunk.fileName}"></script>`
275-
: `<script type="module">${clientChunk.code}</script>`
275+
: hasIsland
276+
? `<script type="module">${clientChunk.code}</script>`
277+
: ''
276278
}
277279
</body>
278280
</html>`.trim();

src/node/config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export function resolveSiteData(
6060
themeConfig: userConfig.themeConfig || {},
6161
head: userConfig.head || [],
6262
base: userConfig.base || '/',
63-
scrollOffset: userConfig.scrollOffset || 90,
6463
locales: userConfig.locales || {},
6564
icon: userConfig.icon || '',
66-
root
65+
root,
66+
appearance: userConfig.appearance ?? true
6767
};
6868
}
6969

@@ -91,10 +91,10 @@ export async function resolveConfig(
9191
configPath,
9292
configDeps,
9393
tempDir: resolve(root, 'node_modules', '.island'),
94-
vite: userConfig.vite || {},
95-
allowDeadLinks: userConfig.allowDeadLinks || false,
94+
vite: userConfig.vite ?? {},
95+
allowDeadLinks: userConfig.allowDeadLinks ?? false,
9696
siteData: resolveSiteData(userConfig, root),
97-
enableSpa: userConfig.enableSpa || false
97+
enableSpa: userConfig.enableSpa ?? false
9898
};
9999

100100
return siteConfig;

src/shared/types/default-theme.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export namespace DefaultTheme {
2222
* @default 'On this page'
2323
*/
2424
outlineTitle?: string;
25-
25+
/**
26+
* Whether to show the sidebar in right position.
27+
*/
28+
outline: boolean;
2629
/**
2730
* The nav items.
2831
*/

src/shared/types/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ export interface UserConfig<ThemeConfig = any> {
7979
*/
8080
allowDeadLinks?: boolean;
8181
/**
82-
* Whether to fail builds when there are dead links.
82+
* Whether dark mode/light mode toggle button is displayed.
8383
*/
84-
scrollOffset?: string | number;
84+
appearance?: boolean;
8585
}
8686

8787
export interface LocaleConfig {
@@ -103,8 +103,8 @@ export interface SiteData<ThemeConfig = any> {
103103
icon: string;
104104
head: HeadConfig[];
105105
themeConfig: ThemeConfig;
106-
scrollOffset: number | string;
107106
locales: Record<string, LocaleConfig>;
107+
appearance: boolean;
108108
// TODO: Available languages
109109
// langs: Record<string, { lang: string; label: string }>;
110110
}

src/theme-default/components/Aside/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { ComponentPropsWithIsland, Header } from 'shared/types/index';
44
import { useAsideAnchor } from '../../logic';
55

66
export function Aside(
7-
props: ComponentPropsWithIsland<{ headers: Header[]; pagePath: string }>
7+
props: ComponentPropsWithIsland<{
8+
headers: Header[];
9+
pagePath: string;
10+
outlineTitle: string;
11+
}>
812
) {
913
const [headers, setHeaders] = useState(props.headers || []);
1014
// For outline text highlight
@@ -52,7 +56,7 @@ export function Aside(
5256
<div className={styles.docsAsideOutline}>
5357
<div className={styles.content} ref={asideRef}>
5458
<div className={styles.outlineMarker} ref={markerRef}></div>
55-
<div className={styles.outlineTitle}>ON THIS PAGE</div>
59+
<div className={styles.outlineTitle}>{props.outlineTitle}</div>
5660
<nav>
5761
<ul className={styles.root}>{headers.map(renderHeader)}</ul>
5862
</nav>

src/theme-default/components/Nav/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const IconMap = {
1515
export function Nav() {
1616
const { siteData, pageType } = usePageData();
1717
const hasSidebar = pageType === 'doc';
18+
const hasAppearanceSwitch = siteData.appearance !== false;
1819
const menuItems = siteData?.themeConfig?.nav || [];
1920
const socialLinks = siteData?.themeConfig?.socialLinks || [];
2021
const location = useLocation();
@@ -60,9 +61,11 @@ export function Nav() {
6061
<div className={styles.content}>
6162
<div className={styles.search}>{/* <Search /> */}</div>
6263
<div className={styles.menu}>{renderMenuList()}</div>
63-
<div className={styles.appearance}>
64-
<SwitchAppearance __island />
65-
</div>
64+
{hasAppearanceSwitch && (
65+
<div className={styles.appearance}>
66+
<SwitchAppearance __island />
67+
</div>
68+
)}
6669
<div className={styles.socialLinks}>
6770
<div className={styles.socialLink}>
6871
{socialLinks.map((item) => {

src/theme-default/layout/DocLayout/index.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { Content, usePageData } from 'island/client';
77

88
export function DocLayout() {
99
const data = usePageData();
10+
const themeConfig = data.siteData.themeConfig;
1011
const headers = data?.toc || [];
11-
const sidebar = data?.siteData?.themeConfig?.sidebar || [];
12+
const sidebar = themeConfig?.sidebar || [];
1213
const hasSidebar =
1314
(Array.isArray(sidebar) && sidebar.length > 0) ||
1415
Object.keys(sidebar).length > 0;
16+
const outlineTitle = themeConfig?.outlineTitle || 'ON THIS PAGE';
1517

16-
const hasAside = headers.length > 0;
18+
const hasAside = headers.length > 0 && themeConfig.outline !== false;
1719
return (
1820
<div className={styles.doc}>
1921
<div className={styles.sideBar}>{hasSidebar ? <SideBar /> : null}</div>
@@ -35,7 +37,12 @@ export function DocLayout() {
3537
<div className={styles.asideContainer}>
3638
<div className={styles.asideContent}>
3739
{hasAside ? (
38-
<Aside __island headers={headers} pagePath={data.pagePath} />
40+
<Aside
41+
__island
42+
headers={headers}
43+
outlineTitle={outlineTitle}
44+
pagePath={data.pagePath}
45+
/>
3946
) : null}
4047
</div>
4148
</div>

0 commit comments

Comments
 (0)