Add a banner on the old documentation docs.
PATCH v12 1/1 Add a banner on the old documentation docs.
--- scripts/docs_fix_all_html_css.py | 111 +++++++++++++++++++++++++++++++ scripts/run-docs-build | 2 + 2 files changed, 113 insertions(+) create mode 100644 scripts/docs_fix_all_html_css.py
scripts/docs_fix_all_html_css.py new file +110 -0
@@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0-only +# +#Signed-off-by: Abongwa Bonalais Amahnui <[email protected]> +# +# +# function to append to the content of a html file below the body tag +# +# + +import os + + + +html_content_dunfell = ''' +<div id="outdated-warning">This document is outdated, you should select the <a href="https://docs.yoctoproject.org/">latest release version</a> in this series.</div> +<div xml:lang="en" class="body" lang="en"> +''' +html_content = ''' +<div id="outdated-warning">This version of the project is now considered obsolete, please select and use a <a href="https://docs.yoctoproject.org">more recent version</a>.</div> +<div xml:lang="en" class="body" lang="en"> +''' + +# <div xml:lang="en" class="body" lang="en"> and </div> are added to the html files to wrap all the content below the body tag in a div tag whose class is known so it can be controlled in the css file +last_div = ''' +</div> + +''' + +css_replacement_content = ''' + + font-family: Verdana, Sans, sans-serif; + + /*min-width: 640px;*/ + width: 100%; + margin: 0; + padding: 0; + color: #333; + overflow-x: hidden; + } + + /*added books too*/ +.body{ +margin: 0 auto; +min-width: 640px; +padding: 0 5em 5em 5em; +} +/* added the id below to make the banner show and be fixed*/ +#outdated-warning{ +text-align: center; +background-color: rgb(255, 186, 186); +color: rgb(106, 14, 14); +padding: 0.5em 0; +width: 100%; +position: fixed; +top: 0; + + +''' + # pattern = '^3.1*' + # exclude = re.search(pattern, dir) +def loop_through_html_directories(dir): + exclude = [] + for root, dirs, filenames in os.walk(dir): + # exclude banner for 3.1.x upward as it is an LTS release and is still supported + exclude = [ name for name in os.listdir(dir) if name.startswith('3.1') ] + for d in dirs: + if d in exclude: + dirs.remove(d) + for filename in filenames: + if filename.endswith('.html'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + current_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(current_content.replace('<body>', '<body>' + html_content)) + f.write(current_content.replace('</body>', last_div + '</body>')) + if filename.endswith('.css'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + css_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content )) + print(exclude) +loop_through_html_directories('.') + + + + +def dunfell_tags(dir): + dunfell_banners = [] + for root, dirs, filenames in os.walk(dir): + dunfell_banners = [ name for name in os.listdir(dir) if not name.startswith('3.1') ] + for d in dirs: + if d in dunfell_banners: + dirs.remove(d) + + for filename in filenames: + if filename.endswith('.html'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + current_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(current_content.replace('<body>', '<body>' + html_content_dunfell)) + f.write(current_content.replace('</body>', last_div + '</body>')) + if filename.endswith('.css'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + css_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content )) + print(dunfell_banners) +dunfell_tags('.')
scripts/run-docs-build +2 -0
@@ -37,6 +37,8 @@ cd $outputdir echo Extracing old content from archive tar -xJf $docbookarchive +$scriptdir/docs_fix_all_html_css.py + cd $bbdocs mkdir $outputdir/bitbake
Signature · 1 line
2.25.1
Hi Amahnui,
On 4/27/22 19:27, Abongwa Amahnui Bonalais wrote:> Signed-off-by: Abongwa Bonalais Amahnui <[email protected]>> ---
Adding a comment in the commit log to explain why this patch is needed and what it does would be great.
Quoted 11 lines
scripts/docs_fix_all_html_css.py | 111 +++++++++++++++++++++++++++++++ scripts/run-docs-build | 2 + 2 files changed, 113 insertions(+)create mode 100644
scripts/docs_fix_all_html_css.pyscripts/docs_fix_all_html_css.py new file +0
-0
scripts/docs_fix_all_html_css.py line 9
Quoted 9 lines
scripts/docs_fix_all_html_css.py new file +9
-0@@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0-only +# +#Signed-off-by: Abongwa Bonalais Amahnui <[email protected]> +# +# +# function to append to the content of a html file below the body tag +#
Please add a comment as to what this script is supposed to to. You're discussing the implementation here more than the finality. We need to know when opening the file and reading the comment what this should/would be used for.
scripts/docs_fix_all_html_css.py line 19
Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10
-0+# + +import os + + + +html_content_dunfell = ''' +<div id="outdated-warning">This document is outdated, you should select the <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__docs.yoctoproject.org_&d=DwMDAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=aRH3jUhIOsO6ovQMKiTHiW-F3Xwnx9HWg6yTF99QSvNBJXbkOkdzSNhwGt6I4zHl&s=QnWAweVmLt12aTlVPVFZsjAeYelStsO_8RsqIskX0Sk&e=">latest release version</a> in this series.</div> +<div xml:lang="en" class="body" lang="en"> +'''
I would nitpick here and say we should probably point to https://docs.yoctoproject.org/dunfell in the href. But that can be fixed/discussed later.
scripts/docs_fix_all_html_css.py line 25
Quoted 6 lines
scripts/docs_fix_all_html_css.py new file +6
-0+html_content = ''' +<div id="outdated-warning">This version of the project is now considered obsolete, please select and use a <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__docs.yoctoproject.org&d=DwMDAg&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=aRH3jUhIOsO6ovQMKiTHiW-F3Xwnx9HWg6yTF99QSvNBJXbkOkdzSNhwGt6I4zHl&s=XxAPqWFTh9XMmtK4eywrsIFkuOGfwEs8acOxvNGck2g&e=">more recent version</a>.</div> +<div xml:lang="en" class="body" lang="en"> +''' + +# <div xml:lang="en" class="body" lang="en"> and </div> are added to the html files to wrap all the content below the body tag in a div tag whose class is known so it can be controlled in the css file
You are explaining what you are doing, which we can usually understand by reading the code, instead of explaining why you're doing it which is something we cannot guess. Why was it not possible to just insert the banner in the body tag as a div before any other element/tag?
scripts/docs_fix_all_html_css.py line 35
Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10
-0+last_div = ''' +</div> + +''' + +css_replacement_content = ''' + + font-family: Verdana, Sans, sans-serif; + + /*min-width: 640px;*/
You can remove this commented part as it does not provide any context or help.
scripts/docs_fix_all_html_css.py line 43
Quoted 8 lines
scripts/docs_fix_all_html_css.py new file +8
-0+ width: 100%; + margin: 0; + padding: 0; + color: #333; + overflow-x: hidden; + } + + /*added books too*/
Not sure what I am supposed to understand with this comment?
Quoted 9 lines
scripts/docs_fix_all_html_css.py new file +9
-0+.body{ +margin: 0 auto; +min-width: 640px; +padding: 0 5em 5em 5em; +} +/* added the id below to make the banner show and be fixed*/ +#outdated-warning{ +text-align: center; +background-color: rgb(255, 186, 186);
scripts/docs_fix_all_html_css.py line 62
Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10
-0+color: rgb(106, 14, 14); +padding: 0.5em 0; +width: 100%; +position: fixed; +top: 0; + + +''' + # pattern = '^3.1*' + # exclude = re.search(pattern, dir)
Useless comments, please remove.
Quoted 13 lines
scripts/docs_fix_all_html_css.py new file +13
-0+def loop_through_html_directories(dir): + exclude = [] + for root, dirs, filenames in os.walk(dir): + # exclude banner for 3.1.x upward as it is an LTS release and is still supported + exclude = [ name for name in os.listdir(dir) if name.startswith('3.1') ] + for d in dirs: + if d in exclude: + dirs.remove(d) + for filename in filenames: + if filename.endswith('.html'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + current_content = f.read() + with open(os.path.join(root, filename), 'w') as f:
scripts/docs_fix_all_html_css.py line 85
Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10
-0+ f.write(current_content.replace('<body>', '<body>' + html_content)) + f.write(current_content.replace('</body>', last_div + '</body>')) + if filename.endswith('.css'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + css_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content )) + print(exclude) +loop_through_html_directories('.') +
The function name is not really helpful, you're explaining the implementation more than the outcome of it. I should call this function if I want to add a banner for olds docs. I could suggest add_banner_old_docs as a function name instead, though other people could probably come up with something more meaningful.
Quoted 14 lines
scripts/docs_fix_all_html_css.py new file +14
-0+ + + +def dunfell_tags(dir): + dunfell_banners = [] + for root, dirs, filenames in os.walk(dir): + dunfell_banners = [ name for name in os.listdir(dir) if not name.startswith('3.1') ] + for d in dirs: + if d in dunfell_banners: + dirs.remove(d) + + for filename in filenames: + if filename.endswith('.html'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f:
scripts/docs_fix_all_html_css.py line 109
Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10
-0+ current_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(current_content.replace('<body>', '<body>' + html_content_dunfell)) + f.write(current_content.replace('</body>', last_div + '</body>')) + if filename.endswith('.css'): + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + css_content = f.read() + with open(os.path.join(root, filename), 'w') as f: + f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content )) + print(dunfell_banners)
This is all extremely complex just for using a different variable depending on the name of the directory.
+def add_banner_old_docs(dir):
+ exclude = []
+ for root, dirs, filenames in os.walk(dir):
+ if root.startswith('./3.1'):
+ html_replacement = html_content_dunfell
+ else:
+ html_replacement = html_content
+
+ for filename in filenames:
+ if filename.endswith('.html'):
+ with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f:
+ current_content = f.read()
+ with open(os.path.join(root, filename), 'w') as f:
+ f.write(current_content.replace('<body>', '<body>' + html_replacement))
+ f.write(current_content.replace('</body>', last_div + '</body>'))
+ if filename.endswith('.css'):
+ with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f:
+ css_content = f.read()
+ with open(os.path.join(root, filename), 'w') as f:
+ f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content ))
+ print(exclude)
+add_banner_old_docs('.')
Cheers,
Quentin
Hi Quentin
Quoted 26 lines · Quentin Schulz
Quoted 26 lines
scripts/docs_fix_all_html_css.py new file +7
-0+ + + +def dunfell_tags(dir): + dunfell_banners = [] + for root, dirs, filenames in os.walk(dir): + dunfell_banners = [ name for name in os.listdir(dir) if not
name.startswith('3.1')]
+ for d in dirs:
+ if d indunfell_banners:
+dirs.remove(d)
+
+ for filename in filenames:
+ iffilename.endswith('.html'):
+ withopen(os.path.join(root, filename), 'r', encoding="ISO-8859-1")as f:
+current_content=f.read()
+ withopen(os.path.join(root, filename), 'w')as f:
+f.write(current_content.replace('<body>', '<body>' + html_content_dunfell))
+f.write(current_content.replace('</body>', last_div + '</body>'))
+ iffilename.endswith('.css'):
+ withopen(os.path.join(root, filename), 'r', encoding="ISO-8859-1")as f:
Quoted 8 lines
Quoted 5 lines
+
css_content=f.read()
+ withopen(os.path.join(root, filename), 'w')as f:
+ f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' +css_replacement_content))
+print(dunfell_banners)This is all extremely complex just for using a different variable depending on the name of the directory.
I wish to ask if your'e referring to the last line of code or this entire function, I have actuallly removed the print(dunfell_banners) line
Thanks a lot for reviewing.