-
Notifications
You must be signed in to change notification settings - Fork 7
/
lint_tags.bb
40 lines (33 loc) · 1.03 KB
/
lint_tags.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(ns lint-tags
(:require
[clojure.set :as set]
[clj-yaml.core :as y]
[clojure.java.io :as io]))
(def required-tags
#{:author :title :category :layout :publishedDate :heroImage})
(def optional-tags
#{:draft :tags :clojureIn :description})
(def all-tags
(set/union required-tags optional-tags))
(defn validate-tags [f]
(let [parsed (->> f
slurp
(re-find #"(?is)---(.*?)---")
last)
tags (-> parsed
y/parse-string
keys
set)]
(assert (and
(set/subset? required-tags tags)
(set/subset? tags all-tags))
{:required required-tags
:file (.getName f)
:actual-tags tags})))
(defn validate-all []
(doseq [f (file-seq (io/file "src/pages/blog"))
:when (and (.isFile f)
(or (.endsWith (.getName f) "md")
(.endsWith (.getName f) "mdx")))]
(validate-tags f)))
(validate-all)