Skip to content

Commit

Permalink
fix(transformer): atomAssetId field missing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachScript committed Aug 18, 2020
1 parent cc113ba commit 84f8378
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/preset-dumi/src/transformer/remark/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ let demoIds: Object = {};

/**
* get unique id for previewer
* @param yaml meta data
* @param fileAbsPath file absolute path
* @param yaml meta data
* @param fileAbsPath file absolute path
* @param componentName the name of related component
*/
function getPreviewerId(yaml: any, fileAbsPath: string) {
function getPreviewerId(yaml: any, fileAbsPath: string, componentName: string) {
const ids = demoIds[fileAbsPath];
let id = yaml.identifier || yaml.uuid || yaml.componentName;
let id = yaml.identifier || yaml.uuid || componentName;

if (!id) {
// /path/to/md => path-to-md
Expand Down Expand Up @@ -69,8 +70,9 @@ export default () => <Demo />;
/**
* apply code block detecting event
* @param props previewer props
* @param componentName the name of related component
*/
function applyCodeBlock(props: IPreviewerComponentProps) {
function applyCodeBlock(props: IPreviewerComponentProps, componentName: string) {
ctx.umi?.applyPlugins({
key: 'dumi.detectCodeBlock',
type: ctx.umi.ApplyPluginsType.event,
Expand All @@ -80,7 +82,7 @@ function applyCodeBlock(props: IPreviewerComponentProps) {
description: props.description,
thumbnail: props.thumbnail,
tags: props.tags,
atomAssetId: props.componentName,
atomAssetId: componentName,
// for HiTu DSM
uuid: props.uuid,
dependencies: {
Expand Down Expand Up @@ -185,11 +187,11 @@ function visitor(node, i, parent: Node) {
dependencies,
...yaml,
// not allow user override identifier by frontmatter
identifier: getPreviewerId(yaml, this.data('fileAbsPath')),
identifier: getPreviewerId(yaml, this.data('fileAbsPath'), this.vFile.data.componentName),
};

// apply umi plugins
applyCodeBlock(previewerProps);
applyCodeBlock(previewerProps, this.vFile.data.componentName);
applyDemo(previewerProps, code);

// declare demo on the top page component for memo
Expand Down

0 comments on commit 84f8378

Please sign in to comment.