Skip to content

Commit

Permalink
Merge branch 'master' into wuxh/feat-1463
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Mar 3, 2023
2 parents 173ae53 + edd743e commit bfef009
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
16 changes: 16 additions & 0 deletions src/client/theme-default/slots/Content/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,20 @@
background-color: lighten(@c-site-bg-dark, 3%);
}

&[data-no-footer] {
padding-bottom: @s-content-padding;
}

@media @mobile {
max-width: initial;
margin: 0 -24px;
padding: 24px 24px 0;
border-radius: 0;
box-shadow: none;

&[data-no-footer] {
padding: 24px;
}
}
}

Expand All @@ -175,4 +183,12 @@
min-height: calc(100vh - @s-header-height-m);
}
}

&[data-no-sidebar][data-no-footer] {
margin-bottom: @s-content-padding;

@media @mobile {
margin-bottom: 24px;
}
}
}
4 changes: 3 additions & 1 deletion src/client/theme-default/slots/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useSidebarData } from 'dumi';
import { useSidebarData, useSiteData } from 'dumi';
import React, { type FC, type ReactNode } from 'react';
import './heti.scss';
import './index.less';

const Content: FC<{ children: ReactNode }> = (props) => {
const sidebar = useSidebarData();
const { themeConfig } = useSiteData();

return (
<div
className="dumi-default-content"
data-no-sidebar={!sidebar || undefined}
data-no-footer={themeConfig.footer === false || undefined}
>
{props.children}
</div>
Expand Down
30 changes: 4 additions & 26 deletions src/features/routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { SP_ROUTE_PREFIX } from '@/constants';
import type { IApi } from '@/types';
import { getClientDistFile } from '@/utils';
import { getConventionRoutes } from '@umijs/core';
import { createRouteId } from '@umijs/core/dist/route/utils';
import path from 'path';
import { plural } from 'pluralize';
import type { IRoute } from 'umi';
import { glob, resolve, winPath } from 'umi/plugin-utils';
import { glob, winPath } from 'umi/plugin-utils';

const CTX_LAYOUT_ID = 'dumi-context-layout';

Expand Down Expand Up @@ -89,29 +90,6 @@ function flatRoute(route: IRoute, docLayoutId: string) {
}
}

/**
* get page route file
*/
function getClientPageFile(file: string, cwd: string) {
let clientFile: string;

try {
// why use `resolve`?
// because `require.resolve` will use the final path of symlink file
// and in tnpm project, umi will get a file path includes `@` symbol then
// generate a chunk name with `@` symbol, which is not supported by cdn
clientFile = resolve.sync(`dumi/dist/${file}`, {
basedir: cwd,
preserveSymlinks: false,
});
} catch {
// fallback to use `require.resolve`, for dumi self docs & examples
clientFile = require.resolve(`../${file}`);
}

return winPath(clientFile);
}

export default (api: IApi) => {
const extraWatchPaths = [
...(api.userConfig.resolve?.atomDirs || []),
Expand Down Expand Up @@ -284,7 +262,7 @@ export default (api: IApi) => {
path: '*',
absPath: '/*',
parentId: docLayoutId,
file: getClientPageFile('client/pages/404', api.cwd),
file: getClientDistFile('dist/client/pages/404', api.cwd),
};
}

Expand All @@ -294,7 +272,7 @@ export default (api: IApi) => {
path: `${SP_ROUTE_PREFIX}demos/:id`,
absPath: `/${SP_ROUTE_PREFIX}demos/:id`,
parentId: demoLayoutId,
file: getClientPageFile('client/pages/Demo', api.cwd),
file: getClientDistFile('dist/client/pages/Demo', api.cwd),
// disable prerender for demo render page, because umi-hd doesn't support ssr
// ref: https://github.com/umijs/dumi/pull/1451
prerender: false,
Expand Down
13 changes: 10 additions & 3 deletions src/features/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
THEME_PREFIX,
} from '@/constants';
import type { IApi } from '@/types';
import { getClientDistFile } from '@/utils';
import { parseModuleSync } from '@umijs/bundler-utils';
import fs from 'fs';
import path from 'path';
import { deepmerge, lodash, winPath } from 'umi/plugin-utils';
import { deepmerge, lodash, resolve, winPath } from 'umi/plugin-utils';
import { safeExcludeInMFSU } from '../derivative';
import loadTheme, { IThemeLoadResult } from './loader';

const DEFAULT_THEME_PATH = path.join(__dirname, '../../../theme-default');
const loadingComponentPath = winPath(
path.resolve(__dirname, '../../client/pages/Loading'),
);
Expand Down Expand Up @@ -42,7 +42,10 @@ function getPkgThemePath(api: IApi) {
return (
pkgThemeName &&
path.dirname(
require.resolve(`${pkgThemeName}/package.json`, { paths: [api.cwd] }),
resolve.sync(`${pkgThemeName}/package.json`, {
basedir: api.cwd,
preserveSymlinks: true,
}),
)
);
}
Expand All @@ -58,6 +61,10 @@ function getModuleExports(modulePath: string) {
}

export default (api: IApi) => {
const DEFAULT_THEME_PATH = path.join(
getClientDistFile('package.json', api.cwd),
'../theme-default',
);
// load default theme
const defaultThemeData = loadTheme(DEFAULT_THEME_PATH);
// try to load theme package
Expand Down
24 changes: 23 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Cache from 'file-system-cache';
import fs from 'fs';
import yaml from 'js-yaml';
import path from 'path';
import { lodash, logger, winPath } from 'umi/plugin-utils';
import { lodash, logger, resolve, winPath } from 'umi/plugin-utils';

/**
* get route path from file-system path
Expand Down Expand Up @@ -158,3 +158,25 @@ export function getProjectRoot(cwd: string) {

return winPath(cwd);
}

/**
* get dumi client dist file and preserve symlink(pnpm, tnpm & etc.) to make chunk name clean
*/
export function getClientDistFile(file: string, cwd: string) {
let clientFile: string;

try {
// why use `resolve`?
// because `require.resolve` will use the final path of symlink file
// and in tnpm or pnpm project, the long realpath make chunk name unexpected
clientFile = resolve.sync(`dumi/${file}`, {
basedir: cwd,
preserveSymlinks: true,
});
} catch {
// fallback to use `require.resolve`, for dumi self docs & examples
clientFile = require.resolve(`../${file}`);
}

return winPath(clientFile);
}
1 change: 1 addition & 0 deletions suites/boilerplate/templates/site/.gitignore.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
/dist
.dumi/tmp
.dumi/tmp-production
.DS_Store

0 comments on commit bfef009

Please sign in to comment.