Skip to content
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

docs: Format auto-generated docs for Hugo #2041

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion hack/.templates/jsonschemaforhumans/base.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{ schema.keywords.get("title").literal | default("Zarf Package Schema") | md_heading(0) }}
---
title: {{ schema.keywords.get("title").literal | default("Zarf Package Schema") }}
weight: 4
type: docs
---

{% set contentBase %}
{% with schema=schema, skip_headers=False %}
{% include "content.md" %}
Expand Down
22 changes: 14 additions & 8 deletions hack/gen-cli-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
printf "Generating CLI docs\n"
ZARF_CONFIG=hack/empty-config.toml go run main.go internal gen-cli-docs

# Create the top menu label for the sidebar menu
printf "Generating sidebar menu label\n"
MENU_LABEL='{"label": "CLI Commands"}\n'
printf "${MENU_LABEL}" > docs/2-the-zarf-cli/100-cli-commands/_category_.json
BUILT_BY="<!-- Auto-generated by hack\/gen-cli-docs.sh -->"
SEPERATOR="---"
TYPE="type: docs"

# The GenMarkdownTree function from cobra/docs starts the headers at H2.
# This breaks the sidebar menu naming for Docusaurus. This command drops
# all headers by 1 level to fix the menu.
printf "Updating section header levels\n"
# This converts the H2 to Hugo frontmatter and reduces all other headers by one level.

printf "Creating frontmatter from auto-generated title\n"
for FILE in $(find docs/2-the-zarf-cli/100-cli-commands -name "*.md")
do
sed -i.bak "1s/^/${SEPERATOR}\n/" ${FILE}
sed -i.bak "s/^## \(.*\)/title: \1\n${TYPE}\n---\n\n${BUILT_BY}\n/" ${FILE}
sed -i.bak 's/^##/#/g' ${FILE}
sed -i.bak '2s/^/<!-- Auto-generated by hack\/gen-cli-docs.sh -->\n/' ${FILE}
truncate -s -1 ${FILE}
rm ${FILE}.bak
done

# Create the top menu label for the sidebar menu
printf "Generating sidebar menu label\n"
MENU_LABEL='title: CLI Commands'
printf "%s\n%s\ntype: docs\n%s\n\n%s\n" "${SEPERATOR}" "${MENU_LABEL}" "${SEPERATOR}" "${BUILT_BY}" > docs/2-the-zarf-cli/100-cli-commands/_index.md

Loading