noxify / gridsome-plugin-remote-image

simple plugin to download remote images in gridsome
MIT License
14 stars 16 forks source link

Allow downloading from nested fields #3

Closed hacknug closed 4 years ago

hacknug commented 4 years ago

The way sourceField is currently used, prevents us from downloading images in nested fields. LokiJS seems to support using dot notation to access nested fields so it would be great if the plugin didn't expect that to be a top-level field.

noxify commented 4 years ago

Hi @hacknug,

I will take a look.

But before changing something, i have a question to make sure we're talking about the same.

We're not talking about dot walking in relationships

My opinion is, that dot walking and downloading the image from a reference makes no sense. Here i recommend to create a new definition for the referenced collection


I assume you mean something like this:

---
title: Markdown test file with local file
tags: ['Markdown','Test files']
nested:
  - sub:
    - sub1: https://url.tld/image.jpg
---

## Content

This means, when an user defines something like this:

{
      use: '@noxify/gridsome-plugin-image-download',
      options: {
        'typeName' : 'Entry',
        'sourceField': 'nested.sub.child',
        'targetField': 'imagesDownloaded',
        'targetPath': './src/assets/remoteImages'
      }
    }

They have to ensure that the field is not a reference.


Is this correct?

Thanks!

Regards, Marcus

hacknug commented 4 years ago

I have a bunch of json files (and I get a new one every day) which I digest using @gridsome/source-filesystem. Each one of them looks like this (only with ~1000 entries instead of 3):

[
  {
    "rank": 1,
    "nickname": "ゆーーち",
    "score": 293830,
    "pin_badge_image_url": "https://website-images-cdn-mariokarttour.akamaized.net/assets/global-ranking/images/1/wappens/Cpb00037.png",
    "ranking_started_at": "2019-09-25T06:00:00.000Z",
    "ranking_finished_at": "2019-09-26T15:00:00.000Z"
  },
  {
    "rank": 2,
    "nickname": "Nogla",
    "score": 292414,
    "pin_badge_image_url": "https://website-images-cdn-mariokarttour.akamaized.net/assets/global-ranking/images/1/wappens/Cpb00027.png",
    "ranking_started_at": "2019-09-25T06:00:00.000Z",
    "ranking_finished_at": "2019-09-26T15:00:00.000Z"
  },
  {
    "rank": 3,
    "nickname": "ばせぼる",
    "score": 291972,
    "pin_badge_image_url": "https://website-images-cdn-mariokarttour.akamaized.net/assets/global-ranking/images/1/wappens/Gpb00099.png",
    "ranking_started_at": "2019-09-25T06:00:00.000Z",
    "ranking_finished_at": "2019-09-26T15:00:00.000Z"
  }
]

The way I've it set up right now, Gridsome creates one Ranking post for each of those json files. The each one of those posts has a data property that contains the array with all of the players scores. The image I wanna download is ranking_started_at which from the types perspective is data.ranking_started_at.

I tried using Rankings_Data as the typeName (that's how it's called in my schema) but wasn't working, probably due the way the plugin accesses collections. Not sure there's a way to directly touch Rankings_Data while being able to modify its parent collection, that's why I though dot notation is probably the safest way to work around this.

Hope this makes it clearer.

noxify commented 4 years ago

Thanks for the update @hacknug. So it seems, my example was correct.

noxify commented 4 years ago

@hacknug pushed my updates to the feature branch and created a PR. Please review and make changes where needed.

noxify commented 4 years ago

Added with https://github.com/noxify/gridsome-plugin-remote-image/releases/tag/v1.1.0

Example: https://webstone.info/documentation/gridsome-plugin-remote-image/example-contentful