Skip to content

Commit

Permalink
Merge branch 'master' into wuxh/feat-1463
Browse files Browse the repository at this point in the history
# Conflicts:
#	pnpm-lock.yaml
#	src/features/derivative.ts
  • Loading branch information
Wxh16144 committed Mar 9, 2023
2 parents bfef009 + b0feb12 commit 6b344d9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dumi",
"version": "2.1.14",
"version": "2.1.15",
"description": "馃摉 Documentation Generator of React Component",
"keywords": [
"generator",
Expand Down
20 changes: 19 additions & 1 deletion src/features/derivative.ts
Expand Up @@ -3,7 +3,7 @@ import type { IApi } from '@/types';
import assert from 'assert';
import fs from 'fs';
import path from 'path';
import { deepmerge, fsExtra, logger, winPath } from 'umi/plugin-utils';
import { deepmerge, fsExtra, logger, semver, winPath } from 'umi/plugin-utils';

/**
* exclude pre-compiling modules in mfsu mode
Expand Down Expand Up @@ -200,6 +200,24 @@ export default (api: IApi) => {
USELESS_TMP_FILES.forEach((file) => {
fsExtra.rmSync(path.join(api.paths.absTmpPath, file), { force: true });
});

// replace helmet for ssr since @umi@4.0.54
// ref: https://github.com/umijs/umi/pull/10633
if (
api.config.ssr &&
semver.subset(api.appData.umi.version, '4.0.54 - 4.0.55')
) {
const helmetPath = path.join(api.paths.absTmpPath, 'core/helmet.ts');
fsExtra.writeFileSync(
helmetPath,
fsExtra
.readFileSync(helmetPath, 'utf-8')
.replace(
/(return )(React\.createElement)/,
"$1typeof window === 'undefined' ? container : $2",
),
);
}
},
});

Expand Down
20 changes: 13 additions & 7 deletions src/loaders/markdown/transformer/rehypeLink.ts
Expand Up @@ -21,13 +21,22 @@ export default function rehypeLink(
): Transformer<Root> {
return (tree) => {
visit<Root, 'element'>(tree, 'element', (node, i, parent) => {
if (node.tagName === 'a' && typeof node.properties?.href === 'string') {
if (
node.tagName === 'a' &&
typeof node.properties?.href === 'string' &&
// skip target specified link
!node.properties?.target &&
// skip download link
!node.properties?.download
) {
const href = node.properties.href;
const parsedUrl = url.parse(href);
const hostAbsPath = getHostForTabRouteFile(opts.fileAbsPath);

// handle internal link
if (parsedUrl.hostname) return SKIP;
// skip external or special links:
// - http://www.example.com or mailto:xxx@example.com or data:image/xxx
// - //www.example.com
if (parsedUrl.protocol || href.startsWith('//')) return SKIP;

if (/\.md$/i.test(parsedUrl.pathname!)) {
// handle markdown link
Expand All @@ -41,10 +50,7 @@ export default function rehypeLink(
parsedUrl.pathname = routes[key].absPath;
}
});
} else if (
/^\.?\.\//.test(parsedUrl.pathname!) ||
/^(\w+:)?\/\//.test(parsedUrl.pathname!)
) {
} else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
// handle relative link
// transform relative link to absolute link
// because react-router@6 and HTML href are different in processing relative link
Expand Down
2 changes: 1 addition & 1 deletion suites/boilerplate/package.json
@@ -1,6 +1,6 @@
{
"name": "create-dumi",
"version": "2.0.7",
"version": "2.0.8",
"description": "Creator for dumi boilerplate",
"homepage": "https://github.com/umijs/dumi/tree/master/suites/boilerplate#readme",
"bugs": "https://github.com/umijs/dumi/issues",
Expand Down
2 changes: 2 additions & 0 deletions suites/boilerplate/templates/react/package.json.tpl
Expand Up @@ -56,6 +56,8 @@
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@umijs/lint": "^4.0.0",
"dumi": "{{{ version }}}",
"eslint": "^8.23.0",
Expand Down

0 comments on commit 6b344d9

Please sign in to comment.