Skip to content

Commit

Permalink
Define published files in yaml and only render those files (#243)
Browse files Browse the repository at this point in the history
use workflow yaml as source of nav links
  • Loading branch information
pwright authored Jun 10, 2024
1 parent 3d74e0b commit 6dd4367
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/asciidoc-convert-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
"overview/resources.adoc"
"overview/routing.adoc"
"overview/security.adoc"
"overview/load.adoc"
"kubernetes/deployment-concerns.adoc"
)
for file in "${files[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export PYTHONPATH := python

.PHONY: generate-preview
generate-preview:
bash ./scripts/convert-all.sh
python ./scripts/convert-all.py ./scripts/convert-adoc.sh .github/workflows/asciidoc-convert-check.yml
7 changes: 6 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ If you want to preview changes for more complex contributions, follow this proce
. Start the build:
+
----
$ bash scripts/convert-all.sh
$ python scripts/convert-all.py ./scripts/convert
-adoc.sh .github/workflows/asciidoc-convert-check.yml
----

* `convert-adoc.sh` converts each adoc to HTML
* `.github/workflows/asciidoc-convert-check.yml` is the single source of truth about which adoc files are published, see [GitHub: Source code for the Skupper project website]( https://github.com/skupperproject/skupper-website ).


. See the `build` directory for the HTML output.
Empty file modified scripts/convert-adoc.sh
100644 → 100755
Empty file.
58 changes: 58 additions & 0 deletions scripts/convert-all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import yaml
import subprocess
import os
import argparse

# Function to parse command-line arguments
def parse_args():
parser = argparse.ArgumentParser(description="Process AsciiDoc files using a specified script.")
parser.add_argument('script', help="Path to the script to process AsciiDoc files.")
parser.add_argument('yaml_file', help="Path to the YAML file containing the list of AsciiDoc files.")
return parser.parse_args()

# Function to read the YAML content from a file
def read_yaml(yaml_file):
with open(yaml_file, 'r') as file:
return yaml.safe_load(file)

# Function to retrieve AsciiDoc files list
def get_asciidoc_files(data):
asciidoc_files = []
# Navigate through the nested dictionary to find the 'files' list
for job_name, job_details in data.get('jobs', {}).items():
steps = job_details.get('steps', [])
for step in steps:
if step.get('name') == 'Convert specified AsciiDoc files to HTML':
run_content = step.get('run', '')
if 'files=(' in run_content:
start = run_content.find('files=(') + len('files=(')
end = run_content.find(')', start)
files_list = run_content[start:end].strip().split('\n')
# Clean and add the files to the list
for file in files_list:
clean_file = file.strip().strip('"')
if clean_file:
asciidoc_files.append(clean_file)
return asciidoc_files

# Function to run the specified script against each AsciiDoc file
def process_asciidoc_file(script, file):
# Check if the script exists
if not os.path.exists(script):
print(f"Script not found: {script}")
return
# Execute the script with the file as an argument using bash
result = subprocess.run(['bash', script, file], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
print(result.stdout) # Print or handle the output as needed
if result.stderr:
print(f"Error processing {file}: {result.stderr}")

def main():
args = parse_args()
data = read_yaml(args.yaml_file)
asciidoc_files = get_asciidoc_files(data)
for file in asciidoc_files:
process_asciidoc_file(args.script, file)

if __name__ == "__main__":
main()
17 changes: 0 additions & 17 deletions scripts/convert-all.sh

This file was deleted.

0 comments on commit 6dd4367

Please sign in to comment.