Skip to content

Commit c31058d

Browse files
committed
added config file support, closes #87
1 parent 224bacd commit c31058d

4 files changed

Lines changed: 54 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
## 0.7.0 [2016-07-31]
66
- Added markdown support.
77
- Added upgrade command.
8-
- Added support for localtime.
8+
- Added support for localtime.
9+
- Added support for a config file.
910

1011
## 0.6.0 [2016-07-26]
1112
- Added an option to automate the update process.

docs/customizing.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ or, on the website, select the `gh-pages` branch before editing things.
99

1010
### Template
1111

12-
The template is fully customizable, edit `template.html`.
12+
Don't edit the `template.html` file directly, as it will change with each upgrade.
1313

14-
### Logo
14+
Instead, create a file called `config.json` in the root of your repository and change the defaults. Don't forget to run `statuspage update` afterwards.
1515

16-
Add a `logo.png` to your repo's root and change `template.html` to point to that file.
16+
```javascript
17+
{
18+
"footer": "Status page hosted by GitHub, generated with <a href='https://github.com/jayfk/statuspage'>jayfk/statuspage</a>",
19+
"logo": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/logo.png",
20+
"title": "Status",
21+
"favicon": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/favicon.png"
22+
}
23+
```
1724

18-
### CSS
19-
20-
CSS is located at `style.css` in the root directory. Just edit it and commit the file.
25+
Please note: `config.json` has to be valid JSON. The best way to validate it online is at [jsonlint.com](http://jsonlint.com/).
2126

2227
### Use a subdomain
2328

statuspage/statuspage.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from tqdm import tqdm
1414
from collections import OrderedDict
1515
import markdown2
16+
import json
1617

1718
__version__ = "0.6.0"
1819

@@ -39,6 +40,13 @@
3940
"statuspage.js",
4041
]
4142

43+
DEFAULT_CONFIG = {
44+
"footer": "Status page hosted by GitHub, generated with <a href='https://github.com/jayfk/statuspage'>jayfk/statuspage</a>",
45+
"logo": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/logo.png",
46+
"title": "Status",
47+
"favicon": "https://raw.githubusercontent.com/jayfk/statuspage/master/template/favicon.png"
48+
}
49+
4250

4351
@click.group()
4452
@click.version_option(__version__, '-v', '--version')
@@ -85,7 +93,7 @@ def run_upgrade(name, token, org):
8593
click.echo("Upgrading...")
8694

8795
repo = get_repo(token=token, name=name, org=org)
88-
files = [file.path for file in repo.get_dir_contents("/", ref="gh-pages")]
96+
files = get_files(repo=repo)
8997
head_sha = repo.get_git_ref("heads/gh-pages").object.sha
9098

9199
# add all the template files to the gh-pages branch
@@ -132,9 +140,10 @@ def run_update(name, token, org):
132140
panels = get_panels(systems)
133141

134142
# render the template
143+
config = get_config(repo)
135144
template = Template(template_file.decoded_content.decode("utf-8"))
136145
content = template.render({
137-
"systems": systems, "incidents": incidents, "panels": panels
146+
"systems": systems, "incidents": incidents, "panels": panels, "config": config
138147
})
139148

140149
# create/update the index.html with the template
@@ -283,6 +292,31 @@ def iter_systems(labels):
283292
yield label.name
284293

285294

295+
def get_files(repo):
296+
"""
297+
Get a list of all files.
298+
"""
299+
return [file.path for file in repo.get_dir_contents("/", ref="gh-pages")]
300+
301+
302+
def get_config(repo):
303+
"""
304+
Get the config for the repo, merged with the default config. Returns the default config if
305+
no config file is found.
306+
"""
307+
files = get_files(repo)
308+
config = DEFAULT_CONFIG
309+
if "config.json" in files:
310+
# get the config file, parse JSON and merge it with the default config
311+
config_file = repo.get_file_contents('/config.json', ref="gh-pages")
312+
try:
313+
repo_config = json.loads(config_file.decoded_content.decode("utf-8"))
314+
config.update(repo_config)
315+
except ValueError:
316+
click.secho("WARNING: Unable to parse config file. Using defaults.", fg="yellow")
317+
return config
318+
319+
286320
def get_severity(labels):
287321
label_map = dict(COLORED_LABELS)
288322
for label in labels:

statuspage/template/template.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="robots" content="index, follow">
6-
<title>Status</title>
6+
<title>{{ config.title }}</title>
77
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
88
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.css">
99
<link rel="stylesheet" href="style.css">
10-
{# upload your own favicon.png to the root of your repo and replace with href="favicon.png" #}
11-
<link rel="icon" href="https://raw.githubusercontent.com/pyupio/statuspage/master/template/favicon.png">
10+
<link rel="icon" href="{{ config.favicon }}">
1211
</head>
1312
<body>
1413

@@ -18,9 +17,8 @@
1817
<section class="container">
1918

2019
<a class="navigation-title" href="">
21-
{# upload your own logo.png to the root of your repo and replace with src="logo.png" #}
22-
<img class="img" src="https://raw.githubusercontent.com/pyupio/statuspage/master/template/logo.png" height="30">
23-
<h1 class="title">Status</h1>
20+
<img class="img" src="{{ config.logo }}" height="30">
21+
<h1 class="title">{{ config.title }}</h1>
2422
</a>
2523

2624

@@ -83,8 +81,7 @@ <h4>Incidents</h4>
8381
<footer class="footer">
8482
<section class="container">
8583
<hr/>
86-
{# you might want to replace this with a link to your website or something #}
87-
<p>Status page hosted by GitHub, generated with <a href="https://github.com/jayfk/statuspage">jayfk/statuspage</a></p>
84+
<p>{{ config.footer }}</p>
8885
</section>
8986
</footer>
9087

0 commit comments

Comments
 (0)