Skip to content

Commit 02e95a4

Browse files
Merge pull request #18 from CoderDojoPotsdam/issue-17-offline-support
Issue 17 offline support
2 parents 7bfe9df + 15a149b commit 02e95a4

File tree

10 files changed

+197
-7
lines changed

10 files changed

+197
-7
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
_site
1+
_site
2+
/offline
3+
/intro

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: ruby
2+
rvm:
3+
- 2.1
4+
env:
5+
global:
6+
- OFFLINE_BUILD_FOLDER=intro
7+
- OFFLINE_FOLDER="$OFFLINE_BUILD_FOLDER/offline"
8+
install:
9+
- gem install github-pages
10+
script:
11+
- echo "Build online version"
12+
- jekyll build
13+
- echo "Build offline version"
14+
- git fetch origin "+offline:offline"
15+
- mkdir -p "$OFFLINE_FOLDER"
16+
- cp -r .git "$OFFLINE_FOLDER"
17+
- ( cd "$OFFLINE_FOLDER" && git checkout offline )
18+
- jekyll build --destination "$OFFLINE_BUILD_FOLDER"
19+
deploy:
20+
provider: script
21+
skip_cleanup: true
22+
script: _scripts/deploy-offline-build-branch.sh
23+
file_glob: true
24+
on:
25+
branch: master

_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
sourcecode:
22
repository: "https://github.com/CoderDojoPotsdam/CoderDojoPotsdam.github.io/intro"
33
root: "https://github.com/CoderDojoPotsdam/intro/blob/master/"
4+
keep_files:
5+
- offline

_data/tutorials.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ lightbot:
1111
links:
1212
- name: Online
1313
url: http://lightbot.com/flash.html
14+
- name: Offline
15+
url: offline/lightbot/index.html
16+
offline: true
17+
- name: Download
18+
url: offline/lightbot/lightbot.zip
19+
offline: true
1420
- name: iOS
1521
url: http://lightbot.com/redirect-ios-codehour.html
1622
- name: Android
1723
url: http://lightbot.com/redirect-android-codehour.html
1824
categories:
1925
- symbols
2026
- hour-of-code
21-
- offline
2227
# todo offline link
2328
spritebox:
2429
title: SpriteBox
@@ -69,8 +74,13 @@ blockly:
6974
en: https://blockly-games.appspot.com/?lang=en
7075
es: https://blockly-games.appspot.com/?lang=es
7176
links:
77+
- name: Offline
78+
url:
79+
de: offline/blockly-games/index-de.html
80+
en: offline/blockly-games/index-de.html
81+
de: offline/blockly-games/index-de.html
7282
- name: Labyrinth
73-
url:
83+
url:
7484
de: https://blockly-games.appspot.com/maze?lang=de
7585
en: https://blockly-games.appspot.com/maze?lang=en
7686
es: https://blockly-games.appspot.com/maze?lang=es

_docs/Branches.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Branches
2+
3+
The repository has these branches and the other brnaches can be deleted as
4+
they might origin from pull requests.
5+
6+
- `master` [→ visit][master-branch]
7+
This is the branch we work on to create custom sites, add tutorials and
8+
style the pages.
9+
The built branch is served via [GitHub Pages][pages].
10+
- `offline` [→ visit][offline-branch]
11+
This is an optional branch which can be used to generate an offline version
12+
of the website.
13+
- `offline-build` [→ visit][offline-build-branch]
14+
To make deployment easy, this branch contains the build website ready to serve.
15+
16+
[pages]: https://coderdojopotsdam.github.io/intro/
17+
[master-branch]: https://github.com/CoderDojoPotsdam/intro/tree/master
18+
[offline-branch]: https://github.com/CoderDojoPotsdam/intro/tree/offline
19+
[offline-build-branch]: https://github.com/CoderDojoPotsdam/intro/tree/offline-build

_docs/README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ lightbot:
5757
5858
If you like to translate a tutorial to different languages,
5959
first, check that your language is in the [list of languages][languages]. If not, add it.
60-
Then, you can translate [tutorials][tutorials] and
60+
Then, you can translate [tutorials][tutorials] and
6161
6262
## How to add a web page
6363
@@ -92,7 +92,7 @@ Each element in the structure can be either
9292
```yaml
9393
- lightbot
9494
```
95-
- a category, in which case the we write
95+
- a category, in which case the we write
9696
```yaml
9797
- category: symbols
9898
```
@@ -104,7 +104,80 @@ Each element in the structure can be either
104104
- lightbot
105105
```
106106

107+
108+
## How to use the offline version
109+
110+
This website also has an offline version.
111+
The offline version is updated by [travis][travis] and can be accessed via the [offline-build branch][offline-build].
112+
113+
You can download the [offline version][offline-build-download].
114+
You can extract it, store it e.g. on a USB device or serve it via a webserver.
115+
116+
To keep your local copy updated, you can install git.
117+
Then, you clone the repository once:
118+
119+
git clone --branch offline-build https://github.com/CoderDojoPotsdam/intro.git
120+
121+
Everytime you want to update the local copy, run
122+
123+
git pull
124+
125+
## How to build the offline version
126+
127+
You can build the offline version.
128+
To clone the offline material, execute this command:
129+
130+
`git clone --branch offline https://github.com/CoderDojoPotsdam/intro.git _site/offline`
131+
132+
Then, you can run the jekyll command to build and serve the offline website:
133+
134+
`jekyll serve --trace`
135+
136+
Now, your webpage should be available at http://localhost:4000/.
137+
Notice that some additional links appear which are only available as offline verison.
138+
139+
## How to add offline content
140+
141+
Offline links are supported in the `links` section of a tutorial.
142+
If your links look like this:
143+
144+
```yaml
145+
links:
146+
- name: Online
147+
url: http://lightbot.com/flash.html
148+
```
149+
150+
You can also add an offline link to a file stored in the
151+
[offline branch][offline-branch].
152+
Offline links are only displayed if the offline version is generated, see above.
153+
154+
Here, you can see that we add an offline link
155+
to the [lightbot/index.html][offline-branch-lightbot] file:
156+
```yaml
157+
links:
158+
- name: Online
159+
url: http://lightbot.com/flash.html
160+
- name: Offline
161+
url: offline/lightbot/index.html
162+
offline: true
163+
```
164+
165+
In the [offline branch][offline-branch], follow this to add an offline content:
166+
167+
- Create a new folder.
168+
- Create a README.md file which describes what you did to create the folder.
169+
This should include download links, context information, scripts, ... .
170+
The goal is to update this after some years when you are not around,
171+
so please add everything you can.
172+
- Add the necessary files.
173+
174+
107175
[new-issue]: https://github.com/CoderDojoPotsdam/intro/issues/new
108176
[edit-tutorials]: https://github.com/CoderDojoPotsdam/intro/edit/master/_data/tutorials.yml
109177
[tutorials]: https://github.com/CoderDojoPotsdam/intro/blob/master/_data/tutorials.yml
110178
[languages]: https://github.com/CoderDojoPotsdam/intro/blob/master/_data/languages.yml
179+
[offline-build]: https://github.com/CoderDojoPotsdam/intro/tree/offline-build
180+
[offline-build-download]: https://github.com/CoderDojoPotsdam/intro/archive/offline-build.zip
181+
[travis]: https://travis-ci.org/CoderDojoPotsdam/intro/
182+
[offline-branch]: https://github.com/CoderDojoPotsdam/intro/tree/offline
183+
[offline-branch-lightbot]: https://github.com/CoderDojoPotsdam/intro/blob/offline/lightbot/index.html

_includes/tutorial.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
</div>
1010
{%- if tutorial.links -%}
1111
{%- for link in tutorial.links -%}
12+
{%- if link.offline -%}
13+
<span class="offline">
14+
{%- endif -%}
1215
{%- include lang-link.html text=link.name href=link.url -%}
1316
{%- if forloop.last -%}{%- else %} | {% endif -%}
17+
{%- if link.offline -%}
18+
</span>
19+
{%- endif -%}
1420
{% endfor -%}
1521
{%- endif -%}
16-
</div>
22+
</div>

_layouts/overview.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<link href="css/overview.css" rel="stylesheet"/>
99
<link href="css/fonts.css" rel="stylesheet"/>
1010
<link href="css/grid.css" rel="stylesheet"/>
11+
<link href="css/deactivate-offline.css" rel="stylesheet"/>
12+
<link href="offline/activate.css" rel="stylesheet"/>
1113
</head>
1214
<body>
1315
<div class="header">
@@ -26,4 +28,4 @@
2628
{%- endfor %}
2729
{% include footer.html %}
2830
</body>
29-
</html>
31+
</html>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
BRANCH="offline-build"
6+
REMOTE="https://$GITHUB_API_KEY@github.com/CoderDojoPotsdam/intro.git"
7+
8+
if ! [ -n "$GITHUB_API_KEY" ]; then
9+
echo "You should set the variable GITHUB_API_KEY to contain an api key with push access to this repository. It should have the form \"USERNAME:API_KEY\" See https://stackoverflow.com/a/33125422/1320237"
10+
exit 1
11+
fi
12+
if ! [ -n "$OFFLINE_BUILD_FOLDER" ]; then
13+
echo "You should set the variable OFFLINE_BUILD_FOLDER to contain the built version of the offline tutorial."
14+
exit 1
15+
fi
16+
17+
echo "Create a temporary folder for checking out $BRANCH."
18+
mkdir -p temp
19+
cp -r .git temp
20+
(
21+
set -e
22+
cd temp
23+
git fetch origin "+$BRANCH:$BRANCH"
24+
git checkout "$BRANCH"
25+
)
26+
mv temp/.git "$OFFLINE_BUILD_FOLDER"
27+
rm -r temp
28+
29+
(
30+
set -e
31+
cd "$OFFLINE_BUILD_FOLDER"
32+
echo "Commit offline version into branch \"$BRANCH\""
33+
git checkout README.md # do not commit the change in the readme as we want to document the branch
34+
git add --all .
35+
if git commit -am"Automated build $TRAVIS_BUILD_NUMBER"; then
36+
git push -f -q "$REMOTE" "$BRANCH:$BRANCH"
37+
else
38+
echo "No changes"
39+
fi
40+
rm -rf .git
41+
)

css/deactivate-offline.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* This css file deactivates all the offline supported links.
3+
*
4+
*/
5+
6+
.offline {
7+
display: none;
8+
}
9+
10+
@import url("../offline/activate.css");

0 commit comments

Comments
 (0)