-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmetadata-check.py
72 lines (59 loc) · 1.74 KB
/
metadata-check.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# metadata-check.py
# read .md file and make sure there is correct metadata
import pathlib
import markdown
import csv
import os
# check_metadata(file: str) -> None
def check_metadata(file: str) -> None:
# Check if the file is in the authors subfolder or contributor-bios.md
if (
"authors" in pathlib.Path(file).parts
or "contributor-bios.md" in pathlib.Path(file).parts
):
print(
f"Skipping metadata check for {file} in authors subfolder or contributor-bios.md."
)
return
metadata_fields = {
"blog_title",
"thumbnail",
"date",
"author",
"tags",
"category",
"language",
"target_audience",
"key_value_propositions",
}
# read the markdown file
try:
data = pathlib.Path(file).read_text(encoding="utf-8")
md = markdown.Markdown(extensions=["meta"])
md.convert(data)
except:
return 1
# error flag, 0 = no error, 1 = error
# you want it to print out all the errors, so you shouldnt exit on the first one
missing = []
error = 0
for field in metadata_fields:
if field not in md.Meta:
missing.append(field)
if (
"ecosystems-and-partners" in pathlib.Path(file).parts
and missing == "author"
):
print("Author exempt from ecosystems and partners")
pass
else:
error = 1
missing_text = " ".join(missing)
print(
f"{file} is missing a metadata field: {missing_text} with error {error}, please take a look at guide-to-blogs-metadata.md"
)
exit(error)
def main():
file = input()
check_metadata(file)
main()