Using minio to store assets


#1

I want to save my assets in a minio server which is a self-hosted S3.

My problem is this. I want to link to my assets like normal in my local PC and do jekyll serve to see my website. for example I link to my stylesheets like this:

<link rel="stylesheet" href="/assets/css/skeleton.css">

then I transfer the stylesheet to minio server and its link would be somthing like

minio.mywebsite.com/bucketname/assets/css/skeleton.css

And I need to link to this stylesheet in my code in production mode. How can I achieve this ?

So simply in my local I need to link to my assets relatively. but for production, I need to create absolute links by adding minio bucket url endpoint.


#2

I can think of a few ways to do this, most of which require multiple config files.
You could set a variable in your primary config and prepend that to the asset paths.

When you build for production it uses that path. When you build locally you load another config file that overwrites the path.

Something like this:

_config.yml

asset_server: "https://minio.mywebsite.com/bucketname"

In your layouts and includes you’d do this:

<link rel="stylesheet" href="{{ site.asset_server }}/assets/css/skeleton.css">

When you run jekyll build it’ll give you a path of https://minio.mywebsite.com/bucketname/assets/css/skeleton.css

To handle the local part and keep that path relative you can create another config file (filename doesn’t matter)

_config.dev.yml

asset_server: ""

Then to build locally you’d just use the --config flag to load the default config followed by your dev one. Any variables that appear in the dev one will overwrite those in the first config.

jekyll serve --config _config.yml,_config.dev.yml

Will make the asset path above /assets/css/skeleton.css