ElMassimo / iles

🏝 The joyful site generator
https://iles.pages.dev
MIT License
1.07k stars 31 forks source link

How do I load the cover image of a post on the home page #145

Closed hujintao0309 closed 2 years ago

hujintao0309 commented 2 years ago

Hello great ElMassimo,I got a list of Posts and their cover paths,I used vite2.0 for reference, but I didn't get the file path after hash after packaging

<script setup lang="ts">
import moment from 'moment';

const posts = useDocuments('~/pages/posts')
const getImageUrl = (name: string | URL) =>{
  return new URL(name,import.meta.url).href
}

</script>

<template layout="home">
   <h1>Posts</h1>
  <article v-for="post of posts">
    <time :datetime="post.lastUpdated.toISOString()">{{ moment(post.lastUpdated).format('YYYY-MM-DD hh:mm:ss') }}</time>
    <h2>
      <a :href="post.href">{{ post.title }}</a>
    </h2>
    <Picture :src="getImageUrl(post.backGround)" style="width: 300px;height:300px"/>
    <component :is="post" excerpt/>
  </article>
</template>

When I packed it, I got this result: file:///D:/persionl/iles-blog-site/.iles-ssg-temp/assets/posts/%E6%98%AF%E7%9A%84/2.png

ElMassimo commented 2 years ago

Hi, please refer to this Discussion for different ways to use images based on a post or route, or this one about dynamically processing images.

Please post in Discussions when asking for help, I'm using Issues only for bug reports. Thanks!