8000 Update hugo to 0.115.4 by jarrodmillman · Pull Request #649 · numpy/numpy.org · GitHub
[go: up one dir, main page]

Skip to content

Update hugo to 0.115.4 #649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update gen_config to work with new Hugo config structure
  • Loading branch information
stefanv committed Jul 28, 2023
commit 90c2061e460906bf8e31e1bce3eeae75b380ea28
15 changes: 9 additions & 6 deletions config.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ languages:
title: NumPy
weight: 1
contentDir: content/en
< content/en/config.yaml >
< content/en/tabcontents.yaml >
include-files:
- content/en/config.yaml
- content/en/tabcontents.yaml

# Portuguese
pt:
title: NumPy
weight: 2
contentDir: content/pt
< content/pt/config.yaml >
< content/pt/tabcontents.yaml >
include-files:
- content/pt/config.yaml
- content/pt/tabcontents.yaml

# Japanese
ja:
title: NumPy
weight: 3
contentDir: content/ja
< content/ja/config.yaml >
< content/ja/tabcontents.yaml >
include-files:
- content/ja/config.yaml
- content/ja/tabcontents.yaml
54 changes: 38 additions & 16 deletions gen_config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
import os
import re
import yaml


with open('config.yaml.in', 'r', encoding='utf-8') as templ:
lines = templ.readlines()
config = yaml.load(
open("config.yaml.in", "r", encoding="utf-8"), Loader=yaml.SafeLoader
)

pattern = re.compile('< content\/\w\w\/\w*.yaml >')
with open('config.yaml', 'w', encoding='utf-8') as f:
for line in lines:
match = pattern.search(line)
if match:
with open(match.group()[2:-2], 'r', encoding='utf-8') as f2:
for f2_line in f2.readlines():
# indent to get correct yaml formatting
f.write(' ' + f2_line)
elif line.startswith('disableLanguages'):
if os.environ.get('NUMPYORG_WITH_TRANSLATIONS'):
line = "#" + line

f.write(line)
def merge_dicts(d1, d2):
for key, value in d2.items():
if key in d1:
if isinstance(value, list):
d1[key].extend(value)
elif isinstance(value, dict):
merge_dicts(d1[key], value)
else:
f.write(line)
d1[key] = value

return d1


def include_files(d):
external = {}
for key, val in d.items():
if isinstance(val, dict):
d[key] = include_files(val)
elif key == "include-files":
for otherfile in val:
external_data = yaml.load(
open(otherfile, "r", encoding="utf-8"), Loader=yaml.SafeLoader
)
external = merge_dicts(external, external_data)

d.pop("include-files", None)
return {**d, **external}


config = include_files(config)
if os.environ.get("NUMPYORG_WITH_TRANSLATIONS"):
del config["disableLanguages"]


yaml.dump(config, open('config.yaml', 'w', encoding='utf-8'), sort_keys=False)
0