0

I want to build my documentation for being hosted in multiple offline environments, hosted on docker containers. This requires following key features in static site generator,

  • Use all resources (js / css), hosted locally with static html files.
  • Configure url and baseUrl at deployment time (when docker container is started).

These two configurations can help achieve, build once deploy anywhere, and in an offline environment.

Two questions,

  • How to set url at deploy time?
  • How to set all resources to be hosted locally?
Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
Hassan Farid
  • 133
  • 2
  • 7

2 Answers2

0

You may think you should write url in https://{{ baseUrl }}/a.js, and set baseUrl in compile options, actually you don't need to do so.

Just use the relative path, suggest you have a image tag

  • <img src="somephoto.jpg" /> means file is located in the same directory as the current page
  • <img src="../somephoto.jpg" /> means file is located in the upper directory to the current page
  • <img src="/somephoto.jpg" /> means file is located in the root of the website
BH4EHN
  • 169
  • 1
  • 10
  • The documentation suggests that you will have to do it when you run `npm run build` - https://docusaurus.io/docs/en/publishing – Hassan Farid Feb 27 '19 at 10:10
  • @HassanFarid Sorry I didn't notice the problem is about docusaurus, and I never use it before. As docusaurus build your files into static website files, which means no dynamic content exist in the build result. But maybe this is a solution, you can set the `url` field of `siteConfig` in the https://docusaurus.io/docs/en/publishing to `process.env.SITE_URL`, then add `ENV SITE_URL https://your.domain.name` to the Dockerfile, and make the `npm run build` happens in docker image building. – BH4EHN Mar 06 '19 at 08:56
  • I want to achieve, build once & deploy everywhere. There has to be some HTML / JS file, storing this variable and reloading each time. So that we can override this place at the time container is started. – Hassan Farid Mar 08 '19 at 10:12
0

You would have to write a custom script the overwrites the siteConfig.js in it. A high level flow of how this would happen:

  • Run script that replaces URL within siteConfig.js to host 1 (replace1.js)
  • Run deploy script.
  • Run script that replaces URL within siteConfig.js to host 2 (replace2.js)
  • Run deploy script.

In package.json, add a line into the scripts portion:

"scripts": {
  ...
  "deploy-multiple": "./replace1.js && docusaurus-build && ./replace2.js && docusaurus-build",
  ...
}
Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141