Skip to content

Commit

Permalink
feat: support zero js after production build
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 committed Sep 20, 2022
1 parent e3e5eb8 commit 0385eb0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/.island/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineConfig({
title: 'Island.js',
icon: '/island.png',
themeConfig: {
outlineTitle: 'On This Page',
socialLinks: [
{
icon: 'github',
Expand Down
4 changes: 3 additions & 1 deletion src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ class SSGBuilder {
${
this.#config.enableSpa
? `<script type="module" src="/${clientChunk.fileName}"></script>`
: `<script type="module">${clientChunk.code}</script>`
: hasIsland
? `<script type="module">${clientChunk.code}</script>`
: ''
}
</body>
</html>`.trim();
Expand Down
10 changes: 5 additions & 5 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export function resolveSiteData(
themeConfig: userConfig.themeConfig || {},
head: userConfig.head || [],
base: userConfig.base || '/',
scrollOffset: userConfig.scrollOffset || 90,
locales: userConfig.locales || {},
icon: userConfig.icon || '',
root
root,
appearance: userConfig.appearance ?? true
};
}

Expand Down Expand Up @@ -91,10 +91,10 @@ export async function resolveConfig(
configPath,
configDeps,
tempDir: resolve(root, 'node_modules', '.island'),
vite: userConfig.vite || {},
allowDeadLinks: userConfig.allowDeadLinks || false,
vite: userConfig.vite ?? {},
allowDeadLinks: userConfig.allowDeadLinks ?? false,
siteData: resolveSiteData(userConfig, root),
enableSpa: userConfig.enableSpa || false
enableSpa: userConfig.enableSpa ?? false
};

return siteConfig;
Expand Down
5 changes: 4 additions & 1 deletion src/shared/types/default-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export namespace DefaultTheme {
* @default 'On this page'
*/
outlineTitle?: string;

/**
* Whether to show the sidebar in right position.
*/
outline: boolean;
/**
* The nav items.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/shared/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export interface UserConfig<ThemeConfig = any> {
*/
allowDeadLinks?: boolean;
/**
* Whether to fail builds when there are dead links.
* Whether dark mode/light mode toggle button is displayed.
*/
scrollOffset?: string | number;
appearance?: boolean;
}

export interface LocaleConfig {
Expand All @@ -103,8 +103,8 @@ export interface SiteData<ThemeConfig = any> {
icon: string;
head: HeadConfig[];
themeConfig: ThemeConfig;
scrollOffset: number | string;
locales: Record<string, LocaleConfig>;
appearance: boolean;
// TODO: Available languages
// langs: Record<string, { lang: string; label: string }>;
}
Expand Down
9 changes: 6 additions & 3 deletions src/theme-default/components/Nav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const IconMap = {
export function Nav() {
const { siteData, pageType } = usePageData();
const hasSidebar = pageType === 'doc';
const hasAppearanceSwitch = siteData.appearance !== false;
const menuItems = siteData?.themeConfig?.nav || [];
const socialLinks = siteData?.themeConfig?.socialLinks || [];
const location = useLocation();
Expand Down Expand Up @@ -60,9 +61,11 @@ export function Nav() {
<div className={styles.content}>
<div className={styles.search}>{/* <Search /> */}</div>
<div className={styles.menu}>{renderMenuList()}</div>
<div className={styles.appearance}>
<SwitchAppearance __island />
</div>
{hasAppearanceSwitch && (
<div className={styles.appearance}>
<SwitchAppearance __island />
</div>
)}
<div className={styles.socialLinks}>
<div className={styles.socialLink}>
{socialLinks.map((item) => {
Expand Down
5 changes: 3 additions & 2 deletions src/theme-default/layout/DocLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { Content, usePageData } from 'island/client';

export function DocLayout() {
const data = usePageData();
const themeConfig = data.siteData.themeConfig;
const headers = data?.toc || [];
const sidebar = data?.siteData?.themeConfig?.sidebar || [];
const sidebar = themeConfig?.sidebar || [];
const hasSidebar =
(Array.isArray(sidebar) && sidebar.length > 0) ||
Object.keys(sidebar).length > 0;

const hasAside = headers.length > 0;
const hasAside = headers.length > 0 && themeConfig.outline !== false;
return (
<div className={styles.doc}>
<div className={styles.sideBar}>{hasSidebar ? <SideBar /> : null}</div>
Expand Down

0 comments on commit 0385eb0

Please sign in to comment.