Skip to content

Commit f45d963

Browse files
author
Addisu Z. Taddese
committed
Use base_url in redirection logic
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
1 parent f6cefd4 commit f45d963

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ jobs:
3232
- name: Setup Pages
3333
id: pages
3434
uses: actions/configure-pages@v5
35+
- id: determine_env
36+
run: |
37+
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
38+
echo "ENV_TYPE=production" >> $GITHUB_ENV
39+
else
40+
echo "ENV_TYPE=staging" >> $GITHUB_ENV
41+
fi
3542
- name: Build site with docker
3643
run: |
3744
docker build -t sdf_tutorials .
38-
docker run --rm -v ${{ github.workspace }}:/usr/src/app sdf_tutorials bundle exec nanoc compile
45+
docker run --rm -v ${{ github.workspace }}:/usr/src/app sdf_tutorials bundle exec nanoc compile -e $ENV_TYPE
3946
- name: Upload artifact
4047
uses: actions/upload-pages-artifact@v3
4148
with:

content/assets/javascripts/redirect_old_links.js.erb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@ $(function redirect_old_links() {
99

1010
const spec_re = /.*\?=spec.*/
1111
const tutorials_re = /.*\?tut=.*/
12-
if (spec_re.test(window.location)) {
1312

13+
new_loc = null
14+
15+
if (spec_re.test(window.location)) {
1416
var ver = params.get('ver');
1517
var elem = params.get('elem');
1618
if (ver && elem) {
17-
window.location.href = '/spec/' + ver + '/' + elem;
19+
new_loc = '/spec/' + ver + '/' + elem;
20+
}
21+
else {
22+
new_loc = "/404/"
1823
}
1924
} else if (tutorials_re.test(window.location)) {
20-
console.log("Redir: tut")
2125
var tut = params.get('tut');
2226
var cat = params.get('cat');
2327
var ver = params.get('ver');
2428

2529
if (tut && cat && ver) {
26-
window.location.href = '/tutorials/' + cat + '/' + tut + '/' + ver;
30+
new_loc = '/tutorials/' + cat + '/' + tut + '/' + ver;
2731
} else if (tut && cat) {
28-
window.location.href = '/tutorials/' + cat + '/' + tut;
32+
new_loc = '/tutorials/' + cat + '/' + tut;
2933
} else if (cat) {
30-
window.location.href = '/tutorials/' + cat;
31-
}
32-
else if (tut) {
34+
new_loc = '/tutorials/' + cat;
35+
} else if (tut) {
3336
<% tutorial_map = @items.find_all("/tutorials/**/*.md").filter_map { |item|
3437
[File.basename(item[:ref]), item[:ref]] if item[:ref]
3538
}.to_h %>
@@ -39,9 +42,15 @@ $(function redirect_old_links() {
3942
<% end %>
4043
}
4144
if (tut in tutorials) {
42-
window.location.href = '/tutorials/' + tutorials[tut];
45+
new_loc = '/tutorials/' + tutorials[tut];
46+
} else {
47+
new_loc = "/404/"
4348
}
4449
}
4550
}
4651

52+
if (new_loc) {
53+
window.location.href = '<%= @config[:base_url] %>' + new_loc
54+
}
55+
4756
})

nanoc.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ data_sources:
1818
- type: sdf_documentation
1919
items_root: /tutorials
2020

21-
base_url: https://sdformat.org
21+
base_url: http://localhost:3000
2222
site_name: sdformat.org
23+
24+
environments:
25+
staging:
26+
base_url: https://gazebosim.github.io/sdf_tutorials
27+
28+
production:
29+
base_url: https://sdformat.org

0 commit comments

Comments
 (0)