1
1
mirror of https://github.com/rsms/inter.git synced 2024-11-23 11:43:47 +03:00

Include version in CSS so that HTTP caches are not pointing to old versions

This commit is contained in:
Rasmus Andersson 2017-08-22 13:11:06 -07:00
parent eda835f2f2
commit c97111a594
3 changed files with 49 additions and 12 deletions

View File

@ -97,6 +97,7 @@ dist:
rm -rf docs/font-files
mkdir docs/font-files
cp -a build/dist/*.woff build/dist/*.woff2 docs/font-files/
misc/versionize-css.py
@echo "——————————————————————————————————————————————————————————————————"
@echo ""
@echo "Next step:"

View File

@ -2,43 +2,43 @@
font-family: 'Interface';
font-style: normal;
font-weight: 400;
src: url("https://rsms.me/interface/font-files/Interface-Regular.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Regular.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-Regular.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Regular.woff?v=1.1") format("woff");
}
@font-face {
font-family: 'Interface';
font-style: italic;
font-weight: 400;
src: url("https://rsms.me/interface/font-files/Interface-RegularItalic.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-RegularItalic.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-RegularItalic.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-RegularItalic.woff?v=1.1") format("woff");
}
@font-face {
font-family: 'Interface';
font-style: normal;
font-weight: 500;
src: url("https://rsms.me/interface/font-files/Interface-Medium.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Medium.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-Medium.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Medium.woff?v=1.1") format("woff");
}
@font-face {
font-family: 'Interface';
font-style: italic;
font-weight: 500;
src: url("https://rsms.me/interface/font-files/Interface-MediumItalic.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-MediumItalic.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-MediumItalic.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-MediumItalic.woff?v=1.1") format("woff");
}
@font-face {
font-family: 'Interface';
font-style: normal;
font-weight: 700;
src: url("https://rsms.me/interface/font-files/Interface-Bold.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Bold.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-Bold.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-Bold.woff?v=1.1") format("woff");
}
@font-face {
font-family: 'Interface';
font-style: italic;
font-weight: 700;
src: url("https://rsms.me/interface/font-files/Interface-BoldItalic.woff2") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-BoldItalic.woff") format("woff");
src: url("https://rsms.me/interface/font-files/Interface-BoldItalic.woff2?v=1.1") format("woff2"),
url("https://rsms.me/interface/font-files/Interface-BoldItalic.woff?v=1.1") format("woff");
}

36
misc/versionize-css.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
# encoding: utf8
#
# Updates the "?v=x" in docs/interface.css
#
from __future__ import print_function
import os, sys, re
from collections import OrderedDict
from ConfigParser import RawConfigParser
def main():
rootDir = os.path.dirname(os.path.dirname(__file__))
config = RawConfigParser(dict_type=OrderedDict)
config.read(os.path.join(rootDir, 'src', 'fontbuild.cfg'))
version = config.get('main', 'version')
regex = re.compile(r'(url\("[^"]+?v=)([^"]+)("\))')
cssFileName = os.path.join(rootDir, 'docs', 'interface.css')
s = ''
with open(cssFileName, 'r') as f:
s = f.read()
s = regex.sub(
lambda m: '%s%s%s' % (m.group(1), version, m.group(3)),
s
)
with open(cssFileName, 'w') as f:
f.write(s)
if __name__ == '__main__':
main()