Skip to content

Commit

Permalink
wip: attempt to fix base url issue, closes jekyll#471
Browse files Browse the repository at this point in the history
  • Loading branch information
lexoyo committed Apr 15, 2019
1 parent bc053b3 commit 366eb76
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll-admin/static_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class StaticServer < Sinatra::Base

# Allow `/admin` and `/admin/`, and `/admin/*` to serve `/public/dist/index.html`
get "/*" do
send_file index_path
File.read(index_path).gsub(/%baseurl%/, JekyllAdmin.site.config["baseurl"])
end

# Provide a descriptive error message in dev. if frontend is not build
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def start_up_webrick(opts, destination)
end

def jekyll_admin_monkey_patch(server)
server.mount "/admin", Rack::Handler::WEBrick, JekyllAdmin::StaticServer
server.mount "/_api", Rack::Handler::WEBrick, JekyllAdmin::Server
server.mount JekyllAdmin.site.config["baseurl"] + "/admin", Rack::Handler::WEBrick, JekyllAdmin::StaticServer
server.mount JekyllAdmin.site.config["baseurl"] + "/_api", Rack::Handler::WEBrick, JekyllAdmin::Server
Jekyll.logger.info "JekyllAdmin mode:", ENV["RACK_ENV"] || "production"
end
end
Expand Down
2 changes: 1 addition & 1 deletion script/test-server
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
script/branding

cd ./spec/fixtures/site || exit
RACK_ENV=development bundle exec jekyll serve --verbose --watch
RACK_ENV=development bundle exec jekyll serve --verbose --watch -H 192.168.122.1 --port 3000
2 changes: 2 additions & 0 deletions spec/fixtures/site/_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
title: Your awesome title

# baseurl: /example

# Load the admin interface.
plugins:
- jekyll-admin
Expand Down
4 changes: 2 additions & 2 deletions src/constants/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const API =
process.env.NODE_ENV === 'production'
? '/_api'
: 'http://localhost:4000/_api';
? `${window.location.pathname.split('/admin')[0]}/_api`
: `http://localhost:4000${window.location.pathname.split('/admin')[0]}/_api`;

export const getConfigurationUrl = () => `${API}/configuration`;
export const putConfigurationUrl = () => `${API}/configuration`;
Expand Down
9 changes: 8 additions & 1 deletion src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export const VERSION = 'v0.8.1';
export const ADMIN_PREFIX = '/admin';
export const ADMIN_PREFIX = getPrefix();

function getPrefix() {
// TODO:
// * 1 line does not compile (export const ADMIN_PREFIX = ...)
// * window is not defined during tests, see why and test with baseurl
return typeof window != 'undefined' ? `${window.location.pathname.split('/admin')[0]}/admin` : '/admin';
}
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Jekyll Admin</title>
<link rel="shortcut icon" href="/admin/favicon.ico">
<link rel="shortcut icon" href="%baseurl%/admin/favicon.ico">
</head>
<body>
<div id="root"></div>
<script src="/admin/bundle.js"></script>
<script src="%baseurl%/admin/bundle.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion tools/buildHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fs.readFile('src/index.html', 'utf8', (readError, markup) => {
const $ = cheerio.load(markup);

// since a separate spreadsheet is only utilized for the production build, need to dynamically add this here.
$('head').append('<link rel="stylesheet" href="/admin/styles.css">');
$('head').append('<link rel="stylesheet" href="%baseurl%/admin/styles.css">');

fs.writeFile('lib/jekyll-admin/public/index.html', $.html(), 'utf8', (writeError) => {
if (writeError) {
Expand Down

0 comments on commit 366eb76

Please sign in to comment.