Skip to content

Commit

Permalink
docs: fix build of reference files
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Jul 5, 2024
1 parent a2e5870 commit 5320cbd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RESTIC_DIR=$(BUILD)restic-
RESTIC_CMD=$(BUILD)restic-commands.json

JSONSCHEMA_DIR=docs/static/jsonschema
CONFIG_REFERENCE_DIR=docs/content/configuration/reference
CONFIG_REFERENCE_DIR=docs/content/reference

BUILD_DATE=`date`
BUILD_COMMIT=`git rev-parse HEAD`
Expand Down Expand Up @@ -262,7 +262,7 @@ generate-jsonschema: build
generate-config-reference: build
@echo "[*] $@"

META_TITLE="Reference" \
META_TITLE="Resticprofile configuration reference" \
META_WEIGHT="50" \
LAYOUT_NO_HEADLINE="1" \
LAYOUT_HEADINGS_START="#" \
Expand All @@ -271,7 +271,7 @@ generate-config-reference: build
LAYOUT_HINT_START="{{% notice hint %}}" \
LAYOUT_HINT_END="{{% /notice %}}" \
LAYOUT_UPLINK="[go to top](#reference)" \
$(abspath $(BINARY)) generate --config-reference > $(CONFIG_REFERENCE_DIR)/index.md
$(abspath $(BINARY)) generate --config-reference --to $(CONFIG_REFERENCE_DIR)

documentation: generate-jsonschema generate-config-reference
@echo "[*] $@"
Expand Down
19 changes: 13 additions & 6 deletions commands_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ var configReferenceTemplates embed.FS

func generateConfigReference(output io.Writer, args []string) error {
resticVersion := restic.AnyVersion
destination := "docs/content/reference"
if slices.Contains(args, "--version") {
args = args[slices.Index(args, "--version"):]
if len(args) > 1 {
resticVersion = args[1]
args = args[2:]
}
}
if slices.Contains(args, "--to") {
args = args[slices.Index(args, "--to"):]
if len(args) > 1 {
destination = args[1]
args = args[2:]
}
}

data := config.NewTemplateInfoData(resticVersion)
tpl := templates.New("config-reference", data.GetFuncs())
Expand Down Expand Up @@ -97,7 +105,7 @@ func generateConfigReference(output io.Writer, args []string) error {

for _, staticPage := range staticPages {
fmt.Fprintf(output, "generating %s...\n", staticPage.templateName)
err = generatePage(tpl, data, staticPage.fileName, staticPage.templateName)
err = generatePage(tpl, data, filepath.Join(destination, staticPage.fileName), staticPage.templateName)
if err != nil {
return fmt.Errorf("unable to generate page %s: %w", staticPage.fileName, err)
}
Expand All @@ -111,7 +119,7 @@ func generateConfigReference(output io.Writer, args []string) error {
Section: profileSection,
Weight: weight,
}
err = generatePage(tpl, sectionData, filepath.Join("profile", profileSection.Name()+".md"), "profile.sub-section.gomd")
err = generatePage(tpl, sectionData, filepath.Join(destination, "profile", profileSection.Name()+".md"), "profile.sub-section.gomd")
if err != nil {
return fmt.Errorf("unable to generate profile section %s: %w", profileSection.Name(), err)
}
Expand All @@ -126,7 +134,7 @@ func generateConfigReference(output io.Writer, args []string) error {
Section: nestedSection,
Weight: weight,
}
err = generatePage(tpl, sectionData, filepath.Join("nested", nestedSection.Name()+".md"), "profile.nested-section.gomd")
err = generatePage(tpl, sectionData, filepath.Join(destination, "nested", nestedSection.Name()+".md"), "profile.nested-section.gomd")
if err != nil {
return fmt.Errorf("unable to generate nested section %s: %w", nestedSection.Name(), err)
}
Expand All @@ -136,12 +144,11 @@ func generateConfigReference(output io.Writer, args []string) error {
}

func generatePage(tpl *template.Template, data any, fileName, templateName string) error {
fullname := filepath.Join("docs/content/reference", fileName)
err := os.MkdirAll(filepath.Dir(fullname), 0o755)
err := os.MkdirAll(filepath.Dir(fileName), 0o755)
if err != nil {
return fmt.Errorf("cannot create directory: %w", err)
}
file, err := os.Create(fullname)
file, err := os.Create(fileName)
if err != nil {
return fmt.Errorf("cannot open file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/configuration/jsonschema/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ JSON schema URLs for **any** *restic* version:
* Config V2: {{< absolute "jsonschema/config-2.json" >}}

These universal schemas contain all flags and commands of all known *restic* versions and
may allow to set flags that are not supported by a particular *restic* version. Descriptions
may allow setting flags that are not supported by a particular *restic* version. Descriptions
and deprecation markers indicate what is supported and what should no longer be used.

JSON schema URLs for a **specific** *restic* version (list of [available URLs]({{% relref "reference/json-schema" %}})):
Expand Down

0 comments on commit 5320cbd

Please sign in to comment.