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

feat: add binding for external vars #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

maximepvrt
Copy link
Contributor

@maximepvrt maximepvrt commented Aug 29, 2023

External variables binding for nuxt/content#2053

I've implemented a feature that allows for external variable binding within the Nuxt (Content) MDC project. This enhancement enables seamless integration of external variables into the project, thereby enhancing its functionality and flexibility.

To provide a bit of context, I had initially introduced this binding capability to my personal fork of the project before the extraction of MDC from Nuxt Content. maximepvrt/nuxt-content@57d5845

As of now, I acknowledge that I haven't yet included tests for this feature. I am aware of the importance of testing in ensuring the stability and reliability of the project. However, I've encountered some challenges in devising the appropriate testing strategy, particularly given the specific nature of the binding functionality. Additionally, I've been unable to locate existing tests for the binding aspect within the MDC project.

I remain enthusiastic about contributing to the Nuxt Content MDC project and ensuring its continued growth and improvement.

<template>
  <MDC v-slot="{ data, body }" :value="md">
        <MDCRenderer
          :body="body"
          :data="data"
          :prose="false"
          :vars="mdcVars"
        />
  </MDC>
</template>

<script setup lang="ts">

const mdcVars = ref({ name: 'Maxime'});

const md = `
::alert
Hello {{ $vars.name }}
::
`
</script>

@farnabaz
Copy link
Collaborator

Hey @maximepvrt,
Is there any specific reason for not using data prop to pass external variables to the renderer?

@maximepvrt
Copy link
Contributor Author

maximepvrt commented Sep 7, 2023

Hey @farnabaz,

Thank you for your feedback. I created a new MR in nuxt/content#2296 used the data props to pass external variables to the renderer.

With this current implementation, external variables are accessible through the $doc object (e.g., $doc.firstname) within the ContentRendererMarkdown component. This behavior may appear unusual.

If you have any suggestions regarding this approach or if you believe there's a more elegant solution, please feel free to share your thoughts.

Best,

@farnabaz
Copy link
Collaborator

Introducing new user-provided source of data for runtime is a tricky thing to support in the module's roadmap.

I know that using $doc may sounds not good but for now it is the only options and note that it might face changes in next major release.

I'll keep this feature pending for now.

@maximepvrt
Copy link
Contributor Author

@farnabaz did you see my MR nuxt/content#2296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants