Commit 2d8a89f3 authored by Robert Knight's avatar Robert Knight

Add a script to assist with updating the icon font

To simplify the process of updating the icon font and make
sure that nothing is missed out, add a script which takes
the icon font archive generated by icomoon and updates
the relevant files in the repository.

T-90
parent c87110f5
......@@ -17,9 +17,5 @@ add the relevant icons and then use the app's _Generate Font_ facility.
`h-icon-<name>` class name.
4. Ensure all icons in the 'h' set are selected, then go to the 'Generate Font' tab in icomoon
and click the 'Download' button which appears _within_ the tab.
5. From the downloaded archive:
* Extract `fonts/h.woff` -> `./fonts/h.woff`
* Extract `style.css` -> `./icomoon.css`.
* Edit `icomoon.css` to keep only the _WOFF_ format font as that is [supported](http://caniuse.com/#feat=woff) by our target browsers (IE >= 10).
The WOFF URL needs to be an inlined data URL until #2571 is resolved.
6. Commit the updated `selection.json`, `fonts/h.woff` and `icomoon.css` files to the repository.
5. Run `scripts/update-icon-font.py <icomoon zip archive>` to update the icon font
6. Commit the updated files to the repository.
#!/usr/bin/env python
import argparse
import os
from base64 import b64encode
from zipfile import ZipFile
def main():
parser = argparse.ArgumentParser('Update the icomoon icon font from the provided archive')
parser.add_argument('archive', help='Path to .zip file generated by icomoon')
args = parser.parse_args()
script_dir = os.path.dirname(os.path.abspath(__file__))
vendor_style_dir = script_dir + '/../h/static/styles/vendor'
icon_font_archive = ZipFile(args.archive)
icon_font_archive.extract('selection.json', vendor_style_dir + '/fonts')
icon_font_archive.extract('fonts/h.woff', vendor_style_dir)
css_input_file = icon_font_archive.open('style.css')
css_output_file = open(vendor_style_dir + '/icomoon.css', 'w')
for line in css_input_file:
if "format('woff')" in line:
# inline the WOFF format file
woff_content = icon_font_archive.open('fonts/h.woff').read()
woff_src_line = """
/* WARNING - the URL below is inlined
* because the CSS asset pipeline is not correctly rebasing
* URLs when concatenating files together.
*
* See issue #2571
*/
src:url('data:application/font-woff;base64,%s') format('woff');
"""
css_output_file.write(woff_src_line % b64encode(woff_content))
elif "url(" in line:
# skip non-WOFF format fonts
pass
else:
css_output_file.write(line)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment