Skip to content

Commit

Permalink
dir updates to .htmls files
Browse files Browse the repository at this point in the history
  • Loading branch information
burnt-exe committed Jun 16, 2024
1 parent 5988016 commit d9bd110
Show file tree
Hide file tree
Showing 66 changed files with 4,443 additions and 4,553 deletions.
306 changes: 154 additions & 152 deletions AWS.html

Large diffs are not rendered by default.

311 changes: 157 additions & 154 deletions Adobe.html

Large diffs are not rendered by default.

306 changes: 153 additions & 153 deletions Coding.html

Large diffs are not rendered by default.

306 changes: 153 additions & 153 deletions GitHub.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions Google.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions HashiCorp.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions Microsoft.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions Oracle.html

Large diffs are not rendered by default.

343 changes: 171 additions & 172 deletions Outerbox.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions RedHat.html

Large diffs are not rendered by default.

305 changes: 152 additions & 153 deletions SAP.html

Large diffs are not rendered by default.

129 changes: 112 additions & 17 deletions add_header_include.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
import os
import requests
from bs4 import BeautifulSoup
from PIL import Image
from io import BytesIO
import shutil

def download_image(url, path):
try:
response = requests.get(url, stream=True)
if response.status_code == 200:
response.raw.decode_content = True
with open(path, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
return path
else:
print(f"Failed to download image from {url}: Status code {response.status_code}")
except Exception as e:
print(f"Failed to download image from {url}: {e}")
return None

def resize_image(path, sizes):
try:
img = Image.open(path)
for size in sizes:
img.thumbnail(size, Image.ANTIALIAS)
img.save(f"{os.path.splitext(path)[0]}_{size[0]}x{size[1]}.png")
except Exception as e:
print(f"Failed to resize image {path}: {e}")

def process_images(soup, base_directory):
for img_tag in soup.find_all('img'):
img_src = img_tag.get('src')
if img_src:
img_name = os.path.basename(img_src)
img_path = os.path.join(base_directory, 'assets', 'downloaded', img_name)
if not os.path.exists(img_path):
img_path = download_image(img_src, img_path)
if img_path and not img_path.endswith('.svg'): # Only resize if not an SVG
resize_image(img_path, [(16, 16), (32, 32), (128, 128)])
if img_path:
img_tag['src'] = os.path.relpath(img_path, base_directory)
else:
print(f"Image {img_src} could not be processed. Please check the URL or provide a valid image.")

def update_html_files_with_header(header_file, base_directory):
# Read the content of the header file
with open(header_file, 'r', encoding='utf-8') as file:
header_content = file.read()

# Loop through all directories and files in the base directory
for root, dirs, files in os.walk(base_directory):
for filename in files:
if filename.endswith('.html') and filename != 'header.html':
Expand All @@ -14,29 +55,83 @@ def update_html_files_with_header(header_file, base_directory):
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()

# Remove existing header and @@include('partials/header.html')
content = content.replace(header_content, '')
content = content.replace("@@include('partials/header.html')", '')
soup = BeautifulSoup(content, 'html.parser')
process_images(soup, base_directory)

new_header = BeautifulSoup(header_content, 'html.parser')
old_header = soup.find('header')
if old_header:
old_header.replace_with(new_header)
else:
body = soup.find('body')
if body:
body.insert(0, new_header)

with open(filepath, 'w', encoding='utf-8') as file:
file.write(str(soup))

print(f'Updated {filepath}')

# Find the location to insert the new header
header_start = content.find('<header>')
header_end = content.find('</header>') + len('</header>')
def remove_include_directives(base_directory):
for root, dirs, files in os.walk(base_directory):
for filename in files:
if filename.endswith('.html'):
filepath = os.path.join(root, filename)

if header_start != -1 and header_end != -1:
# Remove the existing header
content = content[:header_start] + content[header_end:]
with open(filepath, 'r', encoding='utf-8') as file:
content = file.readlines()

# Insert the new header at the top of the body
body_start = content.find('<body>') + len('<body>')
new_content = content[:body_start] + '\n' + header_content + '\n' + content[body_start:]
new_content = []
for line in content:
if "@@include('partials/header.html')" not in line:
new_content.append(line)

with open(filepath, 'w', encoding='utf-8') as file:
file.write(new_content)
file.writelines(new_content)

print(f'Updated {filepath}')
print(f'Removed include directive from {filepath}')

def add_assets_to_html_files(base_directory, css_files, js_files):
for root, dirs, files in os.walk(base_directory):
for filename in files:
if filename.endswith('.html'):
filepath = os.path.join(root, filename)

with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()

soup = BeautifulSoup(content, 'html.parser')

# Add CSS links
head = soup.find('head')
if head:
for css_file in css_files:
link_tag = soup.new_tag('link', rel='stylesheet', href=css_file)
head.append(link_tag)

# Add JS scripts
body = soup.find('body')
if body:
for js_file in js_files:
script_tag = soup.new_tag('script', src=js_file)
body.append(script_tag)

with open(filepath, 'w', encoding='utf-8') as file:
file.write(str(soup))

print(f'Added assets to {filepath}')

# Update the base_directory with the path to your project's root directory
base_directory = './'
header_file = os.path.join(base_directory, 'partials/header.html')
header_file = os.path.join(base_directory, 'partials', 'header.html')
css_files = ['./css/main.css', './css/header.css', './css/footer.css', './css/sidebar.css', './css/forms.css']
js_files = ['./js/include-header.js', './js/partnerSearchFilter.js', './js/partnerFilter.js', './js/mobileDropdown.js', './js/main.js', './js/formHandler.js', './js/combinedPartnerFilter.js']

# Remove include directives
remove_include_directives(base_directory)

# Update HTML files with the header
update_html_files_with_header(header_file, base_directory)

# Add CSS and JS assets to HTML files
add_assets_to_html_files(base_directory, css_files, js_files)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/ai--transparency.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/analyzes--data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/business--continuity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/cloud--builder--professional--services.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/cloud--data--services.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/code--syntax.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/downloaded/container--microservices.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d9bd110

Please sign in to comment.