|
99 | 99 | ;; "/docs/latest/cloud/start"] |
100 | 100 | ) |
101 | 101 |
|
102 | | -(defn- process-yaml [path dry-run?] |
| 102 | +(defn- fix-yaml-links [path dry-run?] |
103 | 103 | (let [parsed (yaml/parse-string (slurp path)) |
104 | 104 | updated (walk/postwalk |
105 | 105 | update-node |
106 | 106 | parsed)] |
107 | 107 | (cond |
108 | 108 | (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)) |
113 | 113 |
|
114 | 114 | (= parsed updated) |
115 | 115 | (u/log " ℹ️" (str "No changes for file: " path)) |
|
118 | 118 | (do (spit path (u/generate-yaml updated)) |
119 | 119 | (u/log " ✅" (str "Updated file: " path)))))) |
120 | 120 |
|
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)))))) |
126 | 126 |
|
127 | 127 | (defn- crawl-data-directory |
128 | | - [dry-run?] |
| 128 | + [f dry-run?] |
129 | 129 | (doseq [file (concat (fs/glob "_data" "**/*.yaml") |
130 | 130 | (fs/glob "_data" "**/*.yml"))] |
131 | | - (process-yaml (str file) dry-run?))) |
| 131 | + (f (str file) dry-run?))) |
132 | 132 |
|
133 | 133 | (defn -main |
134 | 134 | "Entry point. Args are validated in bb.edn" |
135 | 135 | [{:keys [dry-run?]}] |
136 | 136 | (u/log "🚀" (str "Crawling _docs directory: updating markdown links" (when dry-run? " (dry run mode)"))) |
137 | 137 | (crawl-md-directory "_docs" dry-run?) |
138 | 138 | (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)) |
0 commit comments