vitepress-demo-preview icon indicating copy to clipboard operation
vitepress-demo-preview copied to clipboard

feat: support path and relative-path prop

Open hairyf opened this issue 1 year ago • 10 comments

close #24


Review PR in StackBlitz Codeflow Submitted with StackBlitz Codeflow.

hairyf avatar May 25 '23 16:05 hairyf

Jump to github demo. @vitepress-demo-preview/component package should achieve for the function. Right?

flingyp avatar May 26 '23 02:05 flingyp

It's actually not very suitable for @vitepress-demo-preview/component. It is useful when customizing the demo-preview, and we need to customize the GitHub blob address.

Reference: https://github.com/tusen-ai/naive-ui/blob/HEAD/demo/utils/EditOnGithubHeader.vue#LL11C22-L11C22

I don't think it should be added to the default component. This is just a simple use case and would add unnecessary complexity.

hairyf avatar May 26 '23 06:05 hairyf

Additionally, I haven't found any test cases to verify this functionality. The dependencies in the example are linked to remote addresses. How should I proceed with testing?

hairyf avatar May 26 '23 06:05 hairyf

OK, but the codes you modified doesn't do the function. relativePath should is a online link url but you get the absolute path of the local component.

flingyp avatar May 26 '23 07:05 flingyp

We should make sure that a relativePath prop is resolvable by the plugin. Right? Maybe you can do it in the @vitepress-demo-preview/component package and provide the function to jump the link.

flingyp avatar May 26 '23 07:05 flingyp

It shouldn't be a remote path unless githubPath is exported; otherwise, it should be a relative path provided to demo-preview.

<script lang="ts" setup>
const props = defineProps<{
  relativePath: string
}>()

const githubPath = `https://www.github.com/.../tree/main${props.relativePath}`
</script>

<template>
  <!-- .... -->
  <a :href="githubPath">to github edit</a>
</template>

hairyf avatar May 26 '23 12:05 hairyf

I added support for that feature in markdown-it-vitepress-demo#metadata and implemented other features as well. It has indeed been helpful to me. Additionally, I would like to thank the project for providing me with great inspiration!

hairyf avatar May 26 '23 18:05 hairyf

Thanks, your attention and contribution!

I can test the feature at example and this is the result I saw. You only need to custom a demo-preview component and the usage remains unchanged. image

If this meets your expectations, I will merge this PR.

flingyp avatar May 27 '23 01:05 flingyp

yes, however, it should replace \ with/

hairyf avatar May 27 '23 04:05 hairyf

yes, however, it should replace \ with/

Yeah, well, you can change the code and submit it. I will merge the pr. Then you just need to customize your own preview component. Thanks!

flingyp avatar May 27 '23 05:05 flingyp