Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: share markdown absolute path with custom unified plugins #1901

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/loaders/markdown/transformer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { ILocalesConfig, IRouteMeta } from '@/client/theme-api/types';
import { VERSION_2_DEPRECATE_SOFT_BREAKS } from '@/constants';
import type { IApi, IDumiConfig, IDumiTechStack } from '@/types';
import enhancedResolve from 'enhanced-resolve';
import path from 'path';
import type { IRoute } from 'umi';
import { semver } from 'umi/plugin-utils';
import { semver, winPath } from 'umi/plugin-utils';
import type { Plugin, Processor } from 'unified';
import type { Data } from 'vfile';
import rehypeDemo from './rehypeDemo';
Expand Down Expand Up @@ -197,6 +198,13 @@ export default async (raw: string, opts: IMdTransformerOptions) => {
}),
);

// information is stored in an object.
processor.data({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先只设置单个 fileAbsPath?应该也不需要 winPath 吧,只有要参与 webpack 编译的内容中的路径需要 winPath

...(processor.data() ?? {}),
filename: winPath(path.relative(opts.cwd, opts.fileAbsPath)),
fileAbsPath: opts.fileAbsPath,
});

const result = await processor.use(rehypeJsxify).process(raw);

return {
Expand Down