Skip to content

Commit 8d1f1e2

Browse files
committed
add indent yaml task (helps see what links changed)
1 parent a98cdd2 commit 8d1f1e2

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

__tasks/tasks/stitch_outbound_links.clj

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@
9999
;; "/docs/latest/cloud/start"]
100100
)
101101

102-
(defn- process-yaml [path dry-run?]
102+
(defn- fix-yaml-links [path dry-run?]
103103
(let [parsed (yaml/parse-string (slurp path))
104104
updated (walk/postwalk
105105
update-node
106106
parsed)]
107107
(cond
108108
(and (= parsed updated) dry-run?)
109-
(do
110-
;; reindent the file in-place
111-
(spit path (u/generate-yaml parsed))
112-
(u/log " 📝" (str "Dry run: Would update file: " path)))
109+
(u/log " ℹ️" (str "Dry run: No update to: " path))
110+
111+
dry-run?
112+
(u/log " 📝" (str "Dry run: Would update file: " path))
113113

114114
(= parsed updated)
115115
(u/log " ℹ️" (str "No changes for file: " path))
@@ -118,22 +118,25 @@
118118
(do (spit path (u/generate-yaml updated))
119119
(u/log "" (str "Updated file: " path))))))
120120

121-
(comment
122-
123-
(process-yaml "_data/docs/nav/latest.yml" false)
124-
125-
)
121+
(defn- fix-yaml-indent [path & _]
122+
(try
123+
(->> path slurp yaml/parse-string u/generate-yaml (spit path))
124+
(catch Exception e
125+
(u/log "" (str "Error processing file: " path ": " (.getMessage e))))))
126126

127127
(defn- crawl-data-directory
128-
[dry-run?]
128+
[f dry-run?]
129129
(doseq [file (concat (fs/glob "_data" "**/*.yaml")
130130
(fs/glob "_data" "**/*.yml"))]
131-
(process-yaml (str file) dry-run?)))
131+
(f (str file) dry-run?)))
132132

133133
(defn -main
134134
"Entry point. Args are validated in bb.edn"
135135
[{:keys [dry-run?]}]
136136
(u/log "🚀" (str "Crawling _docs directory: updating markdown links" (when dry-run? " (dry run mode)")))
137137
(crawl-md-directory "_docs" dry-run?)
138138
(u/log "🚀" (str "Crawling _data directory: updating yaml links" (when dry-run? " (dry run mode)")))
139-
(crawl-data-directory dry-run?))
139+
(crawl-data-directory fix-yaml-links dry-run?))
140+
141+
(defn indent-yaml! []
142+
(crawl-data-directory fix-yaml-indent false))

bb.edn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414

1515
stitch-outbound-links
1616
{:requires [[tasks.stitch-outbound-links :refer [-main]]]
17-
:task (-main (parse-args *command-line-args*))}}}
17+
:task (-main (parse-args *command-line-args*))}
18+
19+
indent-yaml
20+
{:requires [[tasks.stitch-outbound-links :refer [indent-yaml!]]]
21+
:task (indent-yaml!)}}}

0 commit comments

Comments
 (0)