Skip to contentSkip to conversation

Add a banner on the old documentation docs.

PATCH Superseded Abongwa Bonalais Amahnui 3 participants 4 messages Apr 26, 2022

v10 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 Add a banner on the old documentation docs.

---
 scripts/docs_fix_all_html_css.py | 75 ++++++++++++++++++++++++++++++++
 scripts/run-docs-build           |  2 +
 2 files changed, 77 insertions(+)
 create mode 100755 scripts/docs_fix_all_html_css.py
scripts/docs_fix_all_html_css.py new file +75 -0
new file mode 100755
index 0000000..9ac5a2b
@@ -0,0 +1,75 @@
+#!/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 = '''
+<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">
+'''
+# <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):
+    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 = 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:
+            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 ))
+loop_through_html_directories('.')
\ No newline at end of file
scripts/run-docs-build +2 -0
index ecc5332..307ac19 100755
@@ -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
#1 lore raw

Hi Amahnui,

Quoted 21 lines · Abongwa Amahnui Bonalais
---
  scripts/docs_fix_all_html_css.py | 75 ++++++++++++++++++++++++++++++++
  scripts/run-docs-build           |  2 +
  2 files changed, 77 insertions(+)

create mode 100755 scripts/docs_fix_all_html_css.py

scripts/docs_fix_all_html_css.py new file +8 -0
new file mode 100755
index 0000000..9ac5a2b
@@ -0,0 +1,75 @@
+#!/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

scripts/docs_fix_all_html_css.py line 18

Quoted 10 lines
scripts/docs_fix_all_html_css.py new file +10 -0
+#
+#
+
+import os
+
+
+
+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_&amp;d=DwMDAg&amp;c=_sEr5x9kUWhuk4_nFwjJtA&amp;r=LYjLexDn7rXIzVmkNPvw5ymA1XTSqHGq8yBP6m6qZZ4njZguQhZhkI_-172IIy1t&amp;m=QSXvmsOZCPvnujS5xVQeG1_nbbJlo9MdPDnn8pJWC8JwcBRoB0Y1lQVspWNVn0Qy&amp;s=huYXC94XMMYriEdfcMvylQV9z5JxJ6VUTq_IBdmkY7o&amp;e=">latest release version</a> in this series.</div>
+<div xml:lang="en" class="body" lang="en">

This message is ok for Dunfell (3.1.x) releases. You could also point directly to https://docs.yoctoproject.org/dunfell/

For all other releases, use:

This version of the project is now considered obsolete, please select and use a <a href="https://docs.yoctoproject.org">more recent version</a>.

scripts/docs_fix_all_html_css.py line 20

Quoted 2 lines
scripts/docs_fix_all_html_css.py new file +2 -0
+'''
+# <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

body can be modified directly in the css file without using a div. I seem to recall you told us something related to the content actually overlapping you modifications if body was used without putting it in a div? This is the comment we want in there, you explaining why we cannot keep body tag but need a div with a body class instead.

Quoted 26 lines
scripts/docs_fix_all_html_css.py new file +26 -0
+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);

scripts/docs_fix_all_html_css.py line 57

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.

scripts/docs_fix_all_html_css.py line 60

Quoted 3 lines
scripts/docs_fix_all_html_css.py new file +3 -0
+def loop_through_html_directories(dir):
+    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

It is still supported but the files you're looking through are outdated, so a different message should be printed. But something should still be printed though!

scripts/docs_fix_all_html_css.py line 61

Quoted 1 line
scripts/docs_fix_all_html_css.py new file +1 -0
+        exclude = set(['3.1', '3.1.1', '3.1.2', '3.1.3'])

3.1.4 is still missing. You could just check for any directory whose filename is prefixed by 3.1.

Cheers,
Quentin

#2 lore raw

Hi Quentin,
Thanks for the review.

I tried using regex to look for all the folders prefixed by 3.1. but it is currently not working, But I am still working on a fix for it. I noticed that the banner was already on the dunfell excluding 3.1.15, so should I hardcode from 3.1 to 3.1.14 while looking for way to make the regex method work?

#3 lore raw

Hi Amahnui,

Quoted 4 lines · Abongwa Amahnui Bonalais

Hi Quentin,
Thanks for the review.

I tried using regex to look for all the folders prefixed by 3.1. but it is currently not working, But I am still working on a fix for it.

No need for a regex, just check the root string starts with "./3.1", that's enough.

Quoted 1 line

I noticed that the banner was already on the dunfell excluding 3.1.15, so should I hardcode from 3.1 to 3.1.14 while looking for way to make the regex method work?

Your script will only run on the old docs which stops at 3.1.4. There are no other directories. You can check by yourself in the docbook tarball and/or by exiting the run-docs-build script right after calling your script. Therefore, there's really nothing fancy in handling 3.1 except having a different message than for <3.1 releases.

Cheers,
Quentin