summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-27 10:05:45 +0100
committerMartin Fischer <martin@push-f.com>2021-11-27 12:53:41 +0100
commitb10463a36fd3c9032296ac8017abecf7934e993b (patch)
tree46a62e10673fb1ec4879bfc94c3a91b65866d564
parente48c98c767f83554c75457c54ab7942dcc0d316b (diff)
data: serialize post-processed features
-rwxr-xr-xbuild.py78
1 files changed, 36 insertions, 42 deletions
diff --git a/build.py b/build.py
index 9e541b9..d3dad17 100755
--- a/build.py
+++ b/build.py
@@ -10,53 +10,23 @@ import toml
def get_features(dirname):
- features = {}
+ feature_data = {}
for feature in sorted(os.listdir('caniuse.rs/data/' + dirname)):
with open('caniuse.rs/data/' + dirname + '/' + feature) as f:
name = feature.split('.')[0]
- features[name] = toml.load(f)
- return features
-
-
-with open('caniuse.rs/data/versions.toml') as f:
- versions = toml.load(f)
-
-for version, data in versions.items():
- try:
- data['features'] = get_features(version)
- except FileNotFoundError:
- pass
-
-versions = dict(reversed(list(versions.items())))
-
-unstable_features = get_features('unstable')
-
-
-os.makedirs('target', exist_ok=True)
-shutil.copy('style.css', 'target')
-shutil.copy('script.js', 'target')
-
-with open('target/data.json', 'w') as f:
- json.dump(dict(unstable=unstable_features, versions=versions), f)
-
+ feature_data[name] = toml.load(f)
-def write_features(f, feature_data):
+ # new dict because we want to deduplicate features
features = {}
+
+ # caniuse.rs sometimes has several .toml files for one feature flag e.g.
+ # For the const_io feature flag it has 6 .toml files, all with the same
+ # tracking_issue_id but different titles.
+ #
+ # That makes sense for a search-centric application. Not so much for a
+ # static-site generator since showing the same link 6 times is confusing.
for feat, data in feature_data.items():
key = data['flag'] if 'flag' in data else feat
- # caniuse.rs sometimes has several .toml files for one feature flag e.g.
- # For the const_io feature flag it has 6 .toml files, all with the same
- # tracking_issue_id and the following titles:
- #
- # * `io::Cursor::get_ref` as `const fn`
- # * `io::Cursor::new` as `const fn`
- # * `io::Cursor::position` as `const fn`
- # * `io::empty` as `const fn`
- # * `io::repeat` as `const fn`
- # * `io::sink` as `const fn`
- #
- # That makes sense for a search-centric application. Not so much for a
- # static-site generator since showing the same link 6 times is confusing.
url = None
if 'tracking_issue_id' in data:
@@ -90,13 +60,37 @@ def write_features(f, feature_data):
features[key] = data
- features = sorted(features.items(), key=lambda t: t[1]['title'].replace('`', '').lower())
+ return dict(sorted(features.items(), key=lambda t: t[1]['title'].replace('`', '').lower()))
+
+
+with open('caniuse.rs/data/versions.toml') as f:
+ versions = toml.load(f)
+
+for version, data in versions.items():
+ try:
+ data['features'] = get_features(version)
+ except FileNotFoundError:
+ pass
+
+versions = dict(reversed(list(versions.items())))
+
+unstable_features = get_features('unstable')
+
+
+os.makedirs('target', exist_ok=True)
+shutil.copy('style.css', 'target')
+shutil.copy('script.js', 'target')
+
+with open('target/data.json', 'w') as f:
+ json.dump(dict(unstable=unstable_features, versions=versions), f)
+
+def write_features(f, features):
f.write('<ul')
if len(features) > 5:
f.write(' class=columns')
f.write('>')
- for feat, data in features:
+ for feat, data in features.items():
f.write('<li><a')
url = data['url']
if url: