2

in my css I use url() at some places in this way:

style="background-image:url(/images/home/abschnitt1.jpeg)"

this approach generally works and it shows me the background image the way I want when I deploy the website. However for staging purposes I would like to deploy it to github pages aswell. The problem is that with github pages my websites base-uri is not the one I need. It search the pictures at

https://<username>.github.io/

but the website is actually at

https://<username>.github.io/<repository name>

This means it never find these images. My current workaround is that since I deploy it with travis it just renames the stuff in the following way:

mv index.html index.html.old
sed "s/url(/url(\/website-staging1/g" index.html.old > index.html

While this works for this purpose thats definetly a super ugly solution. However I did not find a solution on how to do this without manually fixing the uri. So my question is how I can do this without manually renaming it in this way, whether thats by some kind of a base uri or including it in a different way

maxbachmann
  • 2,862
  • 1
  • 11
  • 35
  • Possible dup https://stackoverflow.com/questions/3812375/specifying-base-url-for-css – arieljuod May 11 '19 at 16:22
  • @arieljuod Well I do not see how this answers my question, because I have the problem that I do have really a different base url and do not just want to place my css in a different folder. – maxbachmann May 11 '19 at 16:26
  • One hacky way I can think of, since the relative urls works relative to the CSS file, you could have 2 css files, one at /pubic and one at /public/repository-name (I guess one just a link to the other) and only change the url of the CSS link tag instead of changing the urls inside the file. – arieljuod May 11 '19 at 16:27
  • the answer to your actual question is that there's no way to set the base for urls inside CSS files other than where you place the file. – arieljuod May 11 '19 at 16:28
  • as I wrote I use github pages, so there is no option to place files lower than the git repositories root. I search for options to overcome this problem, because I guess I am not the first person using github pages with background images in the css – maxbachmann May 11 '19 at 16:30

0 Answers0