Add a banner on the old documentation docs.
PATCH v8 1/1 Add a banner on the old documentation docs.
--- scripts/docs_fix_all_html_css.py | 85 ++++++++++++++++++++++++++++++++ scripts/run-docs-build | 1 + 2 files changed, 86 insertions(+) create mode 100755 scripts/docs_fix_all_html_css.py
scripts/docs_fix_all_html_css.py new file +85 -0
@@ -0,0 +1,85 @@ +#!/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 +# +# +from logging import root +import os +import re + + +html_content = ''' +<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"> +''' +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): + for root, dirs, filenames in os.walk(dir, topdown=True): + # loop through all files in the directory + exclude = set(['3.1', '3.1.1', '3.1.2', '3.1.3']) + dirs[:] = list(filter(lambda x: not x in exclude, dirs)) + for filename in filenames: + # check if the file is an html file + if filename.endswith('.html'): + # open the html file in read mode + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + # read the content of the html file + current_content = f.read() + # open the html file in write mode + with open(os.path.join(root, filename), 'w') as f: + # write the content of the html file + f.write(current_content.replace('<body>', '<body>' + html_content)) + f.write(current_content.replace('</body>', last_div + '</body>')) + if filename.endswith('.css'): + # open the css file in read mode + with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f: + # read the content of the css file + css_content = f.read() + # open the css file in write mode + with open(os.path.join(root, filename), 'w') as f: + # write the content of the css file + f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content )) +loop_through_html_directories('.') + +
scripts/run-docs-build +1 -0
@@ -37,6 +37,7 @@ 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
scripts/docs_fix_all_html_css.py line 13
Quoted 3 lines
scripts/docs_fix_all_html_css.py new file +3
-0+from logging import root +import os +import re
The logging and re imports are unused, remove these.
scripts/docs_fix_all_html_css.py line 21
Quoted 8 lines
scripts/docs_fix_all_html_css.py new file +8
-0+ + +html_content = ''' +<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"> +''' +last_div = ''' +</div>
Add a comment explaining why you need to add a <div> wrapping the main content.
scripts/docs_fix_all_html_css.py line 60
Quoted 6 lines
scripts/docs_fix_all_html_css.py new file +6
-0+ # pattern = '^3.1*' + # exclude = re.search(pattern, dir) +def loop_through_html_directories(dir): + for root, dirs, filenames in os.walk(dir, topdown=True): + # loop through all files in the directory + exclude = set(['3.1', '3.1.1', '3.1.2', '3.1.3'])
Hardcoding numbers like this isn’t a great idea. If the intention is to add the warning on all versions earlier than 3.2, then the regex approach that is commented out would be better. It most likely didn’t work as regex matching isn’t like shell/windows matching:
pattern = r”^3\.1.*"
A good solution would be to use packaging.version.parse, but that’s not a built-in module so would need to be added to the build. That can wait, the regex solution should be good.
A comment here explaining what the exclusion is for, and why 3.1, would be good.
scripts/docs_fix_all_html_css.py line 63
Quoted 3 lines
scripts/docs_fix_all_html_css.py new file +3
-0+ dirs[:] = list(filter(lambda x: not x in exclude, dirs)) + for filename in filenames: + # check if the file is an html file
No need for obvious comments
scripts/docs_fix_all_html_css.py line 65
Quoted 2 lines
scripts/docs_fix_all_html_css.py new file +2
-0+ if filename.endswith('.html'): + # open the html file in read mode
Obvious comment, again, and several times below.
Ross
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Hi Ross,
Quoted 24 lines · Ross Burton
scripts/docs_fix_all_html_css.py line 13
Quoted 3 lines
scripts/docs_fix_all_html_css.py new file +3
-0+from logging import root +import os +import reThe logging and re imports are unused, remove these.
scripts/docs_fix_all_html_css.py line 21
Quoted 8 lines
scripts/docs_fix_all_html_css.py new file +8
-0+ + +html_content = ''' +<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=DwMGaQ&c=_sEr5x9kUWhuk4_nFwjJtA&r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&m=3Ugg7DXNtg5Jzu8oqGU6VwYTbn01QrCiaWSKjVlkEVKyVfiZZnaOgnCbTgFNdaTg&s=NpHhdUuDWyKDzpnNui16Z9MijVOTPcXWU2zzwvY-aWw&e=">latest release version</a> in this series.</div> +<div xml:lang="en" class="body" lang="en"> +''' +last_div = ''' +</div>Add a comment explaining why you need to add a <div> wrapping the main content.
scripts/docs_fix_all_html_css.py line 60
Quoted 6 lines
scripts/docs_fix_all_html_css.py new file +6
-0+ # pattern = '^3.1*' + # exclude = re.search(pattern, dir) +def loop_through_html_directories(dir): + for root, dirs, filenames in os.walk(dir, topdown=True): + # loop through all files in the directory + exclude = set(['3.1', '3.1.1', '3.1.2', '3.1.3'])
Quoted 6 lines
Hardcoding numbers like this isn’t a great idea. If the intention is to add the warning on all versions earlier than 3.2, then the regex approach that is commented out would be better. It most likely didn’t work as regex matching isn’t like shell/windows matching:
pattern = r”^3\.1.*"
A good solution would be to use packaging.version.parse, but that’s not a built-in module so would need to be added to the build. That can wait, the regex solution should be good.
To be fair, the list of impacted versions for dunfell is finite, since we're talking about old docs that aren't regenerated anymore. Dunfell was migrated to Sphinx (and is thus regenerated by run-docs-build script) in 3.1.5. (So I think we're missing 3.1.4 in there.)
For Dunfell, this message will ultimately be replaced with the obsolete message common to all other old docs, in 2 years from now, when it's obsolete.
Just to give more context, I'm not particularly pushing for anything here.
Cheers,
Quentin
Quoted 9 lines
Hardcoding numbers like this isn’t a great idea. If the intention is to add the warning on all versions earlier than 3.2, then the regex approach that is commented out would be better. It most likely didn’t work as regex matching isn’t like shell/windows matching: pattern = r”^3\.1.*" A good solution would be to use packaging.version.parse, but that’s not a built-in module so would need to be added to the build. That can wait, the regex solution should be good.
Hi Ross, I tried out the regex solution but I did not work and I also noticed that the 3.1.x doc versions on the documentation website already contains the banner I thought from 3.1.2 above were not outdate to, I am a little bit confused about which version is the latest.