aksakalli / jekyll-doc-theme

Jekyll theme for creating project documentation websites
https://aksakalli.github.io/jekyll-doc-theme/
MIT License
288 stars 261 forks source link

Static resources links invalid if site run in docker #24

Closed olsove closed 6 years ago

olsove commented 6 years ago

Problem: nginx is compaining that it can not find the static js resources while run under other contextpath

My solution:

1: Create a Dockerfile

FROM nginx:alpine
COPY _site /usr/share/nginx/html
EXPOSE 80

2: create a build.sh file

#!/usr/bin/env bash
set -e # halt script on error
#building dev
bundle exec jekyll build --config _config.yml,_config_dev.yml

docker build -t nginx-build-docspages . && docker run --rm -p 80:80 --name build-docspages nginx-build-docspages

3: create a _config_dev.yml file:

# Site settings
baseurl: "" # <-- perhaps alternate solution is to set this as the same as on github?

# theme options from https://bootswatch.com/
# comment out this to use default Bootstrap
bootwatch: journal

# Build settings
markdown: kramdown
highlighter: rouge
plugins:
  - jekyll-feed
  - jekyll-redirect-from
  - jekyll-seo-tag
  - jekyll-sitemap

exclude:
  - Gemfile
  - Gemfile.lock
  - .idea/
  - .gitignore
  - README.md
  - Dockerfile
  - build.sh

4: Some changes to _includes/js_files.html are required:

<script>
  var baseurl = '{{ site.baseurl }}'
</script>
<script src="{{ '/js/jquery-1.10.2.min.js' | prepend: site.baseurl }}"></script>
<script src="{{ '/js/bootstrap.min.js' | prepend: site.baseurl }}"></script>
<script src="{{ '/js/typeahead.bundle.min.js' | prepend: site.baseurl }}"></script>
<script src="{{ '/js/main.js' | prepend: site.baseurl }}"></script>

The file jquery-1.10.2.min.js must be added to the js folder.

5: run the build.sh script and navigate to http://localhost

aksakalli commented 6 years ago

maybe you can build it as bundle exec jekyll build --baseurl '' ?

aksakalli commented 6 years ago

I pushed a working example https://github.com/aksakalli/jekyll-doc-theme/commit/8ef3c13c7d5554173f59be22920edc63d06fd57c

olsove commented 6 years ago

maybe you can build it as bundle exec jekyll build --baseurl '' ?

That means i dont need an extra config.yaml file. Thanks, I didn't think of that.

It still leave me with the 404 problem in _includes/js_files.html from this code

<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>

Perhaps its missing http: ?

I thought adding the file to the js folder would seem cleaner so I did that.

aksakalli commented 6 years ago

hey, I think it is not related to the server. double slash // means relative protocol. see for more details