nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.15k stars 630 forks source link

use unocss preset icons as page content icon #2669

Open GreyXor opened 5 months ago

GreyXor commented 5 months ago

Is your feature request related to a problem? Please describe

I try to use icon from unocss/nuxt like my other component image image

but in nuxt-content it's not working image image

Describe the solution you'd like

Icon should be showed because icon exist

  <v-list nav>
    <ContentNavigation v-slot="{ navigation }">
      <v-list-item
        v-for="link of navigation"
        :key="link._path"
        :title="link.title"
        :prepend-icon="link.icon"
        :to="link._path"
      ></v-list-item>
    </ContentNavigation>
  </v-list>

Describe alternatives you've considered

Additional context

  "devDependencies": {
    "@iconify-json/mdi": "^1.1.66",
    "@nuxt/content": "^2.12.1",
    "@unocss/nuxt": "^0.61.0",
    "nuxt": "^3.12.2",
    "vuetify-nuxt-module": "^0.14.1"
  }
owljackob commented 5 months ago

What are the values of link.title and link.icon? Did you check?

GreyXor commented 5 months ago

What are the values of link.title and link.icon? Did you check?

Hello, yes, link.title and link.icon have the good value", as expected it's working, and link.icon is correctly i-mdi:home. and i-mdi:home is a working icon. You can have a look here :

---
navigation:
  title: 'i-mdi:home'
  icon: 'i-mdi:home'
---

# Dashboard

image

But if I set the icon directly like this

  <v-list nav>
    <v-list-item title="Dashboard" prepend-icon="i-mdi:home" to="/" />
  </v-list>

image

owljackob commented 5 months ago

Please, try to use i-mdi-home or mdi-home instead.

What are the values of link.title and link.icon? Did you check?

Hello, yes, link.title and link.icon have the good value", as expected it's working, and link.icon is correctly i-mdi:home. and i-mdi:home is a working icon. You can have a look here :

---
navigation:
  title: 'i-mdi:home'
  icon: 'i-mdi:home'
---

# Dashboard

image

But if I set the icon directly like this

  <v-list nav>
    <v-list-item title="Dashboard" prepend-icon="i-mdi:home" to="/" />
  </v-list>

image

GreyXor commented 5 months ago

Please, try to use i-mdi-home or mdi-home instead.

Thank you, but it doesn't work either.

GreyXor commented 5 months ago

I've noticed that if (in dev) I replace :prepend-icon="link.icon" with prepend-icon="mdi-home". then it works, and if I put back (still in the same dev session) :prepend-icon="link.icon". then it still work. It's as if the SSR icon didn't exist because it wasn't "generated".

farnabaz commented 4 months ago

This might related to how unocss scanner acts and detects the icon names.

/cc @antfu What do you think about this issue?

antfu commented 4 months ago

UnoCSS detects usages via the transform pipeline, where in Nuxt Content, the content doesn't go into the bundler transform processor. Thus you will need to configure UnoCSS to scan from fs explicitly: https://unocss.dev/guide/extracting#extracting-from-filesystem