Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS and IMG not loading in GitHub Enterprise Pages #857

Closed
theletterf opened this issue Jul 17, 2018 · 8 comments
Closed

CSS and IMG not loading in GitHub Enterprise Pages #857

theletterf opened this issue Jul 17, 2018 · 8 comments
Labels
status: needs more information There is not enough information to take action on the issue.

Comments

@theletterf
Copy link
Contributor

theletterf commented Jul 17, 2018

🐛 Bug Report

I work in a GitHub Enterprise environment. Publishing, as implemented by #689 , works well. Files are pushed to the repo with the same folder structure as in local. The site loads well in localhost:3000.

The problem is that the static pages reference '/css/main.css' instead of '../css/main.css'. The CSS is there. This happens with custom CSS and images, too. If I manually tweak the path to '../css/', the site renders as intended. I troubleshooted this with @endiliey on Discourse, but we couldn't find the root cause.

This may be similar to #448 .

Have you read the Contributing Guidelines on issues?

Yes.

To Reproduce

  1. Set up a new Docusaurus project using the stable version.
  2. Edit siteConfig.js to add githubHost. Set baseUrl to '/'.
  3. Run publish-gh-pages.
  4. Load any page inside {githubHost}/pages/{organizationName}/{projectName}/docs/

Expected behavior

CSS should load fine and styles should be applied to the static pages. Images put under /website/static/img should load.

Actual Behavior

Pages load without styles nor images.

@theletterf theletterf changed the title CSS not loading in GitHub Enterprise Pages CSS and IMG not loading in GitHub Enterprise Pages Jul 17, 2018
@endiliey
Copy link
Contributor

endiliey commented Jul 17, 2018

This is caused due to how / resolves in GitHub Enterprise

Example:
/css/main.css in https://reasonml.github.io/ will resolve to https://reasonml.github.io/css/main.css

/css/main.css in https://git.company.com/pages/username/repo actually resolves to https://git.company.com/css/main.css instead of https://git.company.com/pages/username/repo/css/main.css

I think baseUrl in this case shouldn't be / but /pages/username/repo/

@theletterf
Copy link
Contributor Author

I fixed this by changing the baseUrl from / to

https://{githubHost}/pages/{organizationName}/{projectName}/

In other words, I had to specify the full URL. That, I think, is not the expected behavior. The documentation should be updated to reflect that. Or #689 be fixed.

@endiliey
Copy link
Contributor

endiliey commented Jul 18, 2018

Did you try /pages/{organizationName}/{projectName}/ ?

@endiliey endiliey added the status: needs more information There is not enough information to take action on the issue. label Jul 18, 2018
@JoelMarcey
Copy link
Contributor

Hi @theletterf - The baseUrl should generally not have a full URL, including http(s) associated with it -- can you try what @endiliey mentioned above?

@theletterf
Copy link
Contributor Author

theletterf commented Jul 20, 2018

@endiliey @JoelMarcey It works that way :-)

@endiliey
Copy link
Contributor

This is because GH Enterprise serve from one endpoint which is {githubHost} so the baseUrl should be set as according.

Closing this.

P.S We accept better documentation PR for https://docusaurus.io/docs/en/site-config.html#mandatory-fields documentation on https://github.com/facebook/docusaurus/edit/master/docs/api-site-config.md
😉

@stephen-james
Copy link

stephen-james commented Jul 20, 2018

Hi All, while the solution from @endiliey works for publishing (to GH Pages), I've found that when I run locally I need to use a baseUrl of / in order to serve images correctly.

The MD image links I am using are in the format:

![alt text](/docs/assets/{image-file.png})

I believe this is a side effect of applying the baseUrl in local development mode as per this commit : e619884

I suppose I could use relative image urls ![some alt text](assets/{image-file.png}) but this would go against the docs in https://docusaurus.io/docs/en/doc-markdown#linking-to-images-and-other-assets

Another option may be if we introduce another baseUrl for when running a local development server... ie:

        ...
        baseUrl: '/pages/{organizationName}/{projectName}/',
        localBaseUrl: '/',
        ...

or maybe modifying the index.html template to use a <base> tag could help?

If you feel any of these approaches may be feasible I can investigate further and PR.

Thanks!!

@endiliey
Copy link
Contributor

@stephen-james

You should link the image with ![some alt text](assets/{image-file.png}) or even better -> ![alt text]({baseUrl}docs/assets/{image-file.png})

Referring (assets/ will be replaced to {baseUrl}/docs/assets/
https://github.com/facebook/Docusaurus/blob/22f3a85a494ddf46bc29964a7989335a7dba4a9a/lib/server/docs.js#L79-L83

The RAW Markdown is below:
https://github.com/facebook/Docusaurus/blob/master/docs/api-doc-markdown.md
correct-documentation

It got transformed into {baseUrl}/docs/assets/ in the website as a side effect 😭
wrong-documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs more information There is not enough information to take action on the issue.
Projects
None yet
Development

No branches or pull requests

4 participants