ya2 · news · projects · code · about

docs
authorFlavio Calva <f.calva@gmail.com>
Tue, 14 Dec 2021 18:57:04 +0000 (19:57 +0100)
committerFlavio Calva <f.calva@gmail.com>
Tue, 14 Dec 2021 18:57:04 +0000 (19:57 +0100)
lib/build/docs.py

index 83f435164ced3babe3c98faf7c234df62c87abb5..9b5aeeb52dd010f6fa9b3362857671bd20905fdd 100644 (file)
@@ -4,6 +4,7 @@ from os.path import exists
 from shutil import rmtree, make_archive
 from lib.build.build import InsideDir
 from pathlib import Path
+from re import match, findall, sub
 from glob import glob
 
 
@@ -16,6 +17,24 @@ def bld_docs():
     rmtree('docs', ignore_errors=True)
     Path('docs').mkdir(exist_ok=True)
     [rename(fname, 'docs/' + fname) for fname in glob('*.html')]
+    for fname in glob('docs/*.html'):
+        out_lines = []
+        with open(fname) as fhtml:
+            lines = fhtml.readlines()
+        for line in lines:
+            occurs = findall('"#[0-9A-Fa-f]{6}"', line)
+            new_line = line
+            for occur in occurs:
+                red = int(occur[2:4], 16) / 255
+                green = int(occur[4:6], 16) / 255
+                blue = int(occur[6:8], 16) / 255
+                new_col = .2989 * red + .5870 * green + .1140 * blue
+                new_col = hex(int(round(new_col * 255)))[2:]
+                new_col = '"#%s%s%s"' %  (new_col, new_col, new_col)
+                new_line = sub('"#[0-9A-Fa-f]{6}"', new_col, new_line)
+            out_lines += [new_line]
+        with open(fname, 'w') as fhtml:
+            fhtml.write(''.join(out_lines))
     Path('build').mkdir(exist_ok=True)
     rmtree('build/docs', ignore_errors=True)
     rename('docs', 'build/docs')