Skip to content

Commit

Permalink
Fixing list issue (#23)
Browse files Browse the repository at this point in the history
* list merge issues fix

* adding the util file

---------

Co-authored-by: Fateh Ullah <fateh@stakater.com>
  • Loading branch information
ufateh and Fateh Ullah authored May 21, 2024
1 parent 5a6b128 commit a9ad4b2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
styles

venv/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ Versioning is provided by `theme_override` and can be added to the `mkdocs.yml`
```
It is compiled under the `dist/_theme`

> Tip: Copy `prepare_theme.sh` file to your project and run it to avoid the above scripts in step 4.
7 changes: 7 additions & 0 deletions prepare_theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chmod +x theme_common/scripts/create-virtual-env.sh
./theme_common/scripts/create-virtual-env.sh
source venv/bin/activate
pip3 install -r theme_common/requirements.txt
python3 theme_common/scripts/combine_theme_resources.py theme_common/resources theme_override/resources dist/_theme
python3 theme_common/scripts/combine_mkdocs_config_yaml.py theme_common/mkdocs.yml theme_override/mkdocs.yml mkdocs.yml
deactivate
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mkdocs-material>=9.5.2,<10.0.0
mkdocs-glightbox>=0.3.5,<1.0.0
mkdocs-glightbox>=0.3.5,<1.0.0
pyyaml>=6.0.1,<7.0.0
24 changes: 17 additions & 7 deletions scripts/combine_mkdocs_config_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
def merge_yaml_files(file1, file2, output_file):

with open(file1, 'r') as f1, open(file2, 'r') as f2:
# data1 = yaml.safe_load(f1)
# data2 = yaml.safe_load(f2)
data1 = yaml.load(f1, Loader=yaml.Loader)
data2 = yaml.load(f2, Loader=yaml.Loader)
merged_data = merge_dicts(data1, data2)
Expand All @@ -14,13 +12,25 @@ def merge_yaml_files(file1, file2, output_file):
yaml.dump(merged_data, out_file, default_flow_style=False)

def merge_dicts(dict1, dict2):
for key, value in dict2.items():
if key in dict1 and isinstance(dict1[key], dict) and isinstance(value, dict):
dict1[key] = merge_dicts(dict1[key], value)
for key in dict2:
if key in dict1:
if isinstance(dict1[key], dict) and isinstance(dict2[key], dict):
merge_dicts(dict1[key], dict2[key])
elif isinstance(dict1[key], list) and isinstance(dict2[key], list):
dict1[key] = merge_lists(dict1[key], dict2[key])
else:
dict1[key] = dict2[key]
else:
dict1[key] = value
dict1[key] = dict2[key]
return dict1


def merge_lists(list1, list2):
merged_list = list1[:]
for item in list2:
if item not in merged_list:
merged_list.append(item)
return merged_list

if __name__ == "__main__":

if len(sys.argv) != 4:
Expand Down
13 changes: 13 additions & 0 deletions scripts/create-virtual-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Define the name of the virtual environment
VENV_DIR="venv"

# Check if the virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
# Create the virtual environment
python3 -m venv $VENV_DIR
echo "Virtual environment created in $VENV_DIR."
else
echo "Virtual environment already exists in $VENV_DIR."
fi

0 comments on commit a9ad4b2

Please sign in to comment.