Skip to content

Commit 901c2a0

Browse files
committed
process _data/docs/nav/latest + bump script
1 parent 1f07807 commit 901c2a0

File tree

3 files changed

+72
-23
lines changed

3 files changed

+72
-23
lines changed

__tasks/tasks/stitch_outbound_links.clj

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,73 @@
5858
(doseq [file (fs/glob dir "**/*.md")]
5959
(process-md (str file) dry-run?)))
6060

61-
(do
62-
(defn process-yaml [path dry-run?]
63-
(let [parsed (yaml/parse-string (slurp path))
64-
updated (walk/postwalk
65-
(fn [node]
66-
(if (and (map? node)
67-
(contains? node :url)
68-
(some #(str/starts-with? (:url node) %) (map #(str "/" % "/") outbound-link-roots)))
69-
(update-in node [:url] #(str "https://metabase.com" %))
70-
node))
71-
parsed)]
72-
(if dry-run?
73-
(do (u/log " 📝" (str "Dry run: Would update file: " path))
74-
updated)
75-
(do
76-
(spit path (yaml/generate-string updated :dumper-options {:flow-style :block}))
61+
;; YAML processing for _data dir (which stores nav info):
62+
63+
(defn- add-metabase-prefix? [node]
64+
(and (map? node)
65+
(contains? node :url)
66+
(not (str/starts-with? (:url node) "/docs/"))
67+
(not (str/starts-with? (:url node) "https://metabase.com"))
68+
(not (str/starts-with? (:url node) "https://www.metabase.com"))
69+
(not (str/starts-with? (:url node) "http://metabase.com"))
70+
(not (str/starts-with? (:url node) "http://www.metabase.com"))))
71+
72+
(defn- remove-metabase-prefix? [node]
73+
(and (map? node)
74+
(contains? node :url)
75+
(or (str/starts-with? (:url node) "https://metabase.com/docs")
76+
(str/starts-with? (:url node) "https://www.metabase.com/docs")
77+
(str/starts-with? (:url node) "http://metabase.com/docs")
78+
(str/starts-with? (:url node) "http://www.metabase.com/docs"))))
79+
80+
(defn- update-node [node]
81+
(let [add? (add-metabase-prefix? node)
82+
remove? (remove-metabase-prefix? node)]
83+
(when add? (u/log " 📝" (str "Adding prefix to: " (:url node))))
84+
(when remove? (u/log " 📝" (str "Removing prefix from: " (:url node))))
85+
(cond-> node
86+
add? (update-in [:url] #(str "https://metabase.com" %))
87+
remove? (update-in [:url]
88+
(comp
89+
#(str/replace % #"^http://www.metabase.com" "")
90+
#(str/replace % #"^http://metabase.com" "")
91+
#(str/replace % #"^https://www.metabase.com" "")
92+
#(str/replace % #"^https://metabase.com" ""))))))
93+
94+
(comment
95+
(mapv (comp :url update-node)
96+
[{:url "/learn/latest/cloud/start"}
97+
{:url "http://www.metabase.com/docs/latest/cloud/start"}])
98+
;; => ["https://metabase.com/learn/latest/cloud/start"
99+
;; "/docs/latest/cloud/start"]
100+
)
101+
102+
(defn- process-yaml [path dry-run?]
103+
(let [parsed (yaml/parse-string (slurp path))
104+
updated (walk/postwalk
105+
update-node
106+
parsed)]
107+
(cond
108+
dry-run?
109+
(u/log " 📝" (str "Dry run: Would update file: " path))
110+
111+
(= parsed updated)
112+
(u/log " ℹ️" (str "No changes for file: " path))
113+
114+
:else
115+
(do (spit path (u/generate-yaml updated))
77116
(u/log "" (str "Updated file: " path))))))
78-
(process-yaml "_data/docs/nav/latest.yml" true))
79117

118+
(comment
119+
120+
(process-yaml "_data/docs/nav/latest.yml" false)
121+
122+
)
80123

81124
(defn- crawl-data-directory
82125
[dry-run?]
83-
(doseq [file (concat (fs/glob "_data" "**/*.yaml") (fs/glob "_data" "**/*.yml"))]
126+
(doseq [file (concat (fs/glob "_data" "**/*.yaml")
127+
(fs/glob "_data" "**/*.yml"))]
84128
(process-yaml (str file) dry-run?)))
85129

86130
(defn -main

__tasks/tasks/util.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
(ns tasks.util
22
(:require [clj-yaml.core :as yaml]))
33

4-
(defn log [level message] (println (str level " " message)))
4+
(defn log [level message]
5+
(when-not (System/getenv "QUIET")
6+
(println (str level " " message))))
7+
8+
(defn generate-yaml [data]
9+
(yaml/generate-string data :dumper-options {:flow-style :block}))
510

611
(defn update-frontmatter!
712
"Reads a file, updates its YAML frontmatter by applying f to the value of the
@@ -24,6 +29,6 @@
2429
updated (apply f data args)]
2530
(when (not= data updated)
2631
(println "Writing changes to frontmatter in: " file)
27-
(let [new-front (yaml/generate-string updated :dumper-options {:flow-style :block})
32+
(let [new-front (generate-yaml updated)
2833
new-content (str "---\n" new-front "---\n" rest)]
2934
(spit file new-content)))))

_data/docs/nav/latest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ categories:
22
- name: Analytics
33
pages:
44
- name: Getting started
5-
url: /learn/metabase-basics/getting-started/index
5+
url: https://metabase.com/learn/metabase-basics/getting-started/index
66
- name: Metabase concepts
7-
url: /learn/metabase-basics/overview/concepts
7+
url: https://metabase.com/learn/metabase-basics/overview/concepts
88
- name: Questions
99
url: /docs/latest/questions/start
1010
pages:
@@ -192,7 +192,7 @@ categories:
192192
- name: Installation overview
193193
url: /docs/latest/installation-and-operation/installing-metabase
194194
- name: Metabase Cloud
195-
url: https://www.metabase.com/docs/latest/cloud/start
195+
url: /docs/latest/cloud/start
196196
- name: Running the JAR file
197197
url: /docs/latest/installation-and-operation/running-the-metabase-jar-file
198198
- name: Running in Docker

0 commit comments

Comments
 (0)