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

Optimize images in markdown? #390

Closed
saturnonearth opened this issue Aug 17, 2020 · 12 comments
Closed

Optimize images in markdown? #390

saturnonearth opened this issue Aug 17, 2020 · 12 comments
Labels

Comments

@saturnonearth
Copy link

Hi there,

How would I automatically optimize static images in markdown files on build?

@saturnonearth saturnonearth added the question Further information is requested label Aug 17, 2020
Copy link
Member

atinux commented Nov 26, 2020

It will be made as soon as we have a stable release of @nuxt/image.

@atinux atinux added pending and removed question Further information is requested labels Nov 26, 2020
@P4sca1
Copy link

P4sca1 commented Oct 4, 2022

@atinux How to use images in my content (v2) with @nuxt/image-edge (v1)?

Copy link
Member

atinux commented Oct 4, 2022

You should be able to use:

:nuxt-img{src="/my-image.png"}

@P4sca1
Copy link

P4sca1 commented Oct 4, 2022

The problem is, that the component is not found. Do I need to register it globally or is there some way for nuxt to automatically import it?

Copy link
Member

atinux commented Oct 4, 2022

Indeed the component is not registered globally here: https://github.com/nuxt/image/blob/v1/src/module.ts#L94-L97

Wondering if we could overwrite this with Nuxt Content to set it globally, WDYT @danielroe @pi0 ?

@P4sca1
Copy link

P4sca1 commented Oct 4, 2022

I don’t know if it is possible, but it would be great if nuxt auto import could work in .md files, like it does in single file components.

Copy link
Member

atinux commented Oct 4, 2022

We could work on a parser to detect this but it is harder since not related to pages directly.

And I want the ability to have live preview in production when editing Markdown files.

One solution could be to flag component with a plugin as global I guess.

@hartmut-co-uk
Copy link

hartmut-co-uk commented Dec 9, 2022

As far as I'm aware this is already in the process of being addressed and solved out of the box.

Until then here's how you can solve this:

Create following file at this exact path: components/content/ProseImg.vue
with content:

<template>
  <NuxtImg v-bind="$attrs" />
</template>

With that in place, images in your content xyz.md files, e.g.

### Basic usage
![](/images/cats/jiji.jpg)

### usage with additional nuxt-image props
![](/images/cats/fluffy.jpg){width="700",height="800",quality="80",sizes="xs:288 sm:352",preload}

Note: tested with @nuxt/image-edge:1.0.0-27821548.ab054e4

(I think this is going to be shipped by nuxt-image out of the with once official GA 1.0.0 some time soon)

@dosstx
Copy link

dosstx commented Apr 28, 2023

I have a use case for this. I see @hartmut-co-uk has a workaround. Before I test it, does anyone know if there have been any updates to the work flow of using Nuxt Image in markdown files? Has there been a release that addresses this issue? Or, is the consensus still to do the solution @hartmut-co-uk has provided? Thank you.

@jvolker
Copy link

jvolker commented Aug 28, 2023

I'm trying to use @hartmut-co-uk's workaround:

### usage with additional nuxt-image props
{width="700",height="800",quality="80",sizes="xs:288 sm:352",preload}

Unfortunately, for me, the additional nuxt-image props are being displayed as text and not parsed and forwarded to nuxt-image. I'm using @nuxt/image-edge:1.0.0-27821548.ab054e4.

What could be the reason for this? Thanks.

@nobkd
Copy link
Contributor

nobkd commented Aug 28, 2023

@jvolker
Have you tried using spaces to separate the attributes instead of commas ,?
Like this:

- ![](imglink){width="700",height="800",quality="80",sizes="xs:288 sm:352",preload}
+ ![](imglink){width="700" height="800" quality="80" sizes="xs:288 sm:352" preload}

Reference: #2082 (comment)

@jvolker
Copy link

jvolker commented Aug 29, 2023

@jvolker Have you tried using spaces to separate the attributes instead of commas ,? Like this:

- ![](imglink){width="700",height="800",quality="80",sizes="xs:288 sm:352",preload}
+ ![](imglink){width="700" height="800" quality="80" sizes="xs:288 sm:352" preload}

Reference: #2082 (comment)

It worked. Perfect. Thank you!

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

No branches or pull requests

8 participants