ox-hugo icon indicating copy to clipboard operation
ox-hugo copied to clipboard

Copy image to static when referenced in custom front matter

Open finex opened this issue 5 years ago • 7 comments

Actual Behavior

Currently I'm using the following custom front matter:

#+HUGO_CUSTOM_FRONT_MATTER: :featured_image "/images/filename.jpg"

and I need to manually put the image in the /static/images/ directory.

With the actual implementation only inline images are copied from the local directory (where the .org file is placed) to the /static/images/ox-hugo.

Expected Behavior

It should be very useful to automatically copy the image mentioned in custom front matter to /static/.... Like inline images.

Moreover it should be very useful to add a new setting similar to org-hugo-default-static-subdirectory-for-externals in order to specify a different destination directory and keep file organization more clean.

What do you think about?

finex avatar Oct 20 '19 20:10 finex

I'll need to think this through. For now, we'll need to just manually copy the images referenced in the front-matter params.

I'd like to have a generic design so that ox-hugo doesn't need adding support for custom params like featured_image, featured-image, banner, etc.

kaushalmodi avatar Oct 28 '19 14:10 kaushalmodi

Hi, thanks for your feedback. having to manually copy only some images and some other not is quite weird. Meanwhile I will try to write a script to manually copying the images. I'd like the idea to keep all the post/page info in the same place (mainly the org files and the images). :-)

finex avatar Oct 31 '19 09:10 finex

having to manually copy only some images and some other not is quite weird.

I am not denying that.

Instead of parsing for specific custom params, I am thinking of adding certain attributes above inline images, that would prevent the rendering of those images inline, and would simply copy them using the machinery we already have in place for copying the attachments.

I haven't found time to think deeper into this idea. But I am all ears to proof-of-concept or a PR.

kaushalmodi avatar Oct 31 '19 19:10 kaushalmodi

Well, a "skip render" option on the image properties should be enough. Not bad. It requires to write at least two times the image (one on the front matter, one for the trick you're suggesting) but it's better than manually copy the image.

finex avatar May 03 '20 12:05 finex

I am facing a similar issue but with other parameters:

:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :cover '((image . "images/cover.jpg") (caption . "A cover image") (alt . "This should be the cover image"))

@finex: Did you find a feasible solution for this?

aleneum avatar Oct 23 '20 18:10 aleneum

Hi, no... currently I'm still manually copying the images :-(

finex avatar Oct 23 '20 20:10 finex

Alright,

I created a (suboptimal) workaround with an org special block and a CSS rule.

post.org

  :EXPORT_HUGO_CUSTOM_FRONT_MATTER: :cover '((image . "/ox-hugo/cover.jpg") (caption . "some code") (alt . "code"))
...
   #+begin_skipRender
   [[file:images/cover.jpg]]
   #+end_skipRender

This creates a markdown segment like this:

post.md

<div class="skipRender">
  <div></div>

{{< figure src="/ox-hugo/unsplash-code.jpg" >}}

</div>

With some custom.css (needs to be included into the used theme) the div will not be rendered:

.skipRender {
    display: none;
}

This isn't beautiful and also redundant but it gets the job done with imho reasonable overhead.

aleneum avatar Oct 26 '20 10:10 aleneum