gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.44k stars 7.44k forks source link

Make relativeURLs work for urls inside css file or <style> #4355

Open apporc opened 6 years ago

apporc commented 6 years ago

Currenctly, relativeURLs only process those urls specified as href, for urls inside a style tag, it doesn't work.

For example

<style>
  @font-face {
    font-family: 'Icon';
    src: url('{{ "./fonts/icon.eot"}}');
  }
</style>

This tag is coded like that in an html file, which will be included in many other htmls. Now in every html file, it is always './fonts/icon.eot', but there are cases it should be '../fonts/icon.eot' or '../../fonts/icon.eot'.

It seems like others have submitted issues similar. Let me clarify why this feature is needed, it's just like the href tag case.

I am hosting my same site code on many different production environment, and they may have different root. As in a environment A, the hugo site will be visited under http://example.com/, but in environment B, it is visited under http://example.com/hugo. As you can see, i can't use '/fonts/icon.eot' because the root is different.

This example what i extracted from ipfs static blog site. I want to visit my site from https://ipfs.io/ipns/... or a web hosting of mine with http://example.com/. Hope you understand now.

bep commented 6 years ago

This is a known limitation. Have you searched for a duplicate issue?

apporc commented 6 years ago

Is this hard to implement, i have searched the code, got to transform/absurlreplacer.go, but i am not really familar with go.

bep commented 6 years ago

Is this hard to implement

Yes it is.

I suggest you look for older threads and workarounds for this.

apporc commented 6 years ago

I searched again in the older threads, didn't find a workaround. But i thought out an ugly one for myself, to restrict all my production environment with the same root.

hanzei commented 6 years ago

Since 0.43 this can be done with hugo pipers. This issue can be closed.

hanzei commented 6 years ago

@bep Can this issue be closed?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.