Skip to content

Relative images in YAML front matter handling in custom layout #165

Closed
@imfing

Description

@imfing

Simply, I want to load images from paths relative to the README.md directory in a custom layout.

Beause in some cases (customized layouts), image resouces couldn't always be placed under the .vuepress/public directory or loaded with markdown.

For example, the title/background image for a blog post.
So I'm wondering what's the best practice to achieve so with vuepress.

In my case, the yaml front matter of the README.md would expected to be something like:

# README.md
---
avatar: ./path1/image.png  # relative to README.md
background: ./path2/image.png
layout: Post
---

And the Post.vue would be like:

<template>
  <div>
    <img :src="data.avatar">
    <Content/>
  <div>
</template>

However, the image isn't being parsed and loaded correctly since vuepress only injected its .vuepress/public path and copied them with copy-plugin. Also, webpack didn't handle the resources in yaml front matter.

Node.js v8.7.0
VuePress 1.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions