Skip to contentSkip to conversation

Add a banner on the old documentation docs

PATCH Superseded Abongwa Bonalais Amahnui 2 participants 5 messages Apr 22, 2022

v6 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 Add a banner on the old documentation docs

---
 htmlscript.py  | 36 +++++++++++++++++++++++++++++
 stylescript.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 htmlscript.py
 create mode 100644 stylescript.py
htmlscript.py new file +36 -0
new file mode 100644
index 0000000..fdbd109
@@ -0,0 +1,36 @@
+#!/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">
+'''
+last_div = '''
+</div>
+
+'''
+
+def loop_through_html_directories(dir):
+    for dirpath, dirnames, filenames in os.walk(dir):
+    # loop through all files in the directory
+        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(dirpath, 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(dirpath, 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>'))
+loop_through_html_directories('.')
stylescript.py new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

Hi Amahnui,

Quoted 4 lines · Abongwa Amahnui Bonalais

---
htmlscript.py | 36 +++++++++++++++++++++++++++++ stylescript.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++

Please have those files inside scripts/ in yocto-autobuilder-helper git repo and send a patch following the contribution guidelines (yocto-autobuilder-helper in the tag part of the commit title ([PATCH yocto-autobuilder-helper]). You did it correctly for the other mail you just sent, the same needs to be done for this one too.

As a side note, the loops are identical in both scripts, so handling html and css files within the same loop with just a different if condition would have been better and avoided a need for a second file.

Quoted 10 lines
2 files changed, 97 insertions(+)

create mode 100644 htmlscript.py
create mode 100644 stylescript.py

htmlscript.py new file +0 -0
new file mode 100644
index 0000000..fdbd109

htmlscript.py line 8

Quoted 8 lines
htmlscript.py new file +8 -0
@@ -0,0 +1,36 @@
+#!/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

It would help to explain why this is needed. (Display the obsolete banner on the old docs website)

Quoted 8 lines
htmlscript.py new file +8 -0
+#
+#
+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">
+'''
+last_div = '''

htmlscript.py line 26

Quoted 10 lines
htmlscript.py new file +10 -0
+</div>
+
+'''
+
+def loop_through_html_directories(dir):
+    for dirpath, dirnames, filenames in os.walk(dir):
+    # loop through all files in the directory
+        for filename in filenames:
+            # check if the file is an html file
+            if filename.endswith('.html'):

i.e. have here another if filename.endswith('style.css'): and have the code of the other file in there.

Quoted 57 lines
htmlscript.py new file +10 -0
+                # open the html file in read mode
+                with open(os.path.join(dirpath, 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(dirpath, 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>'))
+loop_through_html_directories('.')
stylescript.py new file +41 -0
new file mode 100644
index 0000000..2777730
@@ -0,0 +1,61 @@
+#!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 css file below the body class
+#
+#
+import os
+
+
+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;
+

stylescript.py line 51

Quoted 10 lines
stylescript.py new file +10 -0
+
+'''
+
+
+
+def loop_through_html_directories(dir):
+    for dirpath, dirnames, filenames in os.walk(dir):
+    # loop through all files in the directory
+        for filename in filenames:
+            # check if the file is an html file

Incorrect comment, we're looking for style.css.

stylescript.py line 53

Quoted 2 lines
stylescript.py new file +2 -0
+            if filename.endswith('style.css'):
+                # open the html file in read mode

Incorrect comments we're opening style.css

stylescript.py line 55

Quoted 2 lines
stylescript.py new file +2 -0
+                with open(os.path.join(dirpath, filename), 'r', encoding="ISO-8859-1") as f:
+                    # read the content of the html file

Same here.

stylescript.py line 57

Quoted 2 lines
stylescript.py new file +2 -0
+                   css_content = f.read()
+                # open the html file in write mode

Same here.

stylescript.py line 60

Quoted 3 lines
stylescript.py new file +3 -0
+                with open(os.path.join(dirpath, filename), 'w') as f:
+                    # write the content of the html file
+                   

Same here.
f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + content ))

stylescript.py line 61

Quoted 1 line
stylescript.py new file +1 -0
+loop_through_html_directories('.')

A better name would be fix_all_style_css('.')
Or something like that. Because, yes, you're looping through directories but that's not what this function is used for, it's used for fixing files.

Same for the function in the other file.

The script filename would benefit from a rename too, likely docs_fix_all_style_css.py or something similar. So that we know what this script is used for without reading it.

The filenames are just suggestions, if you come up with something better, please use whatever think is best.

Cheers,
Quentin

#2 lore raw

Hi Quentin,
Thank you very much for the review, I will apply all the changes based on your review and send another patch.

#3 lore raw
In reply to Quentin Schulz
Quoted 9 lines

A better name would be fix_all_style_css('.') Or something like that. Because, yes, you're looping through directories but that's not what this function is used for, it's used for fixing files. Same for the function in the other file. The script filename would benefit from a rename too, likely docs_fix_all_style_css.py or something similar. So that we know what this script is used for without reading it. The filenames are just suggestions, if you come up with something better, please use whatever think is best.

Since I am to send everything to a single script, I will just give it a generic name to cover both the html and css changes.