#!/usr/bin/env python3 import glob import html import json import os import re import shutil import toml def get_features(dirname): features = {} 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 unstable_features = get_features('unstable') os.makedirs('target', exist_ok=True) shutil.copy('style.css', 'target') with open('target/data.json', 'w') as f: json.dump(dict(unstable=unstable_features, versions=versions), f) def write_features(f, feature_data): features = {} 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: url = 'https://github.com/rust-lang/rust/issues/{}'.format( data['tracking_issue_id'] ) elif 'impl_pr_id' in data: url = 'https://github.com/rust-lang/rust/pull/{}'.format(data['impl_pr_id']) data['url'] = url data['filename'] = feat if key in features and features[key]['url'] != url: print( 'different urls for feature {}:\n* {}: {}\n* {}: {}'.format( key, data['filename'], data['url'], features[key]['filename'], features[key]['url'], ) ) data['title'] = data['flag'] features[key] = data f.write('
{}
'.format(m.group(1)), title)
f.write(title)
f.write('