forked from plotly/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfront-matter-ci.py
50 lines (40 loc) · 1.67 KB
/
front-matter-ci.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
import frontmatter
from pathlib import Path, PosixPath
import sys
allPosts = [];
# should be either '_posts' for this repo or 'build/html' for the py-docs repo
try:
path = str(sys.argv[1])
except:
raise Exception("You need to specify a path that contains the files with front matter.")
#get all posts with frontmatter in html format
for md_path in Path(path).glob("**/*.html"):
post = frontmatter.load(str(md_path))
if len(post.metadata.keys()) > 0:
allPosts.append(post)
#get all posts with frontmatter in md format
for md_path in Path(path).glob("**/*.md"):
post = frontmatter.load(str(md_path))
if len(post.metadata.keys()) > 0:
allPosts.append(post);
#make sure that every post that is not a redirect has a name tag in the front matter
noNamePaths = [];
titlePaths = [];
for post in allPosts:
if len(post.metadata.keys()) > 0:
meta = post.metadata
if "jupyter" in meta:
meta = meta['jupyter']['plotly']
if "name" not in meta:
if "redirect_to" in meta:
continue
else:
noNamePaths.append(post.metadata)
if "title" in meta:
titlePaths.append(post.metadata)
if (len(noNamePaths) > 0):
raise Exception("CI Check #1 Not Passed: post:'{}' is not a redirect but is missing a name frontmatter\n".format('\n'.join([str(item) for item in noNamePaths])))
print("CI Check #1 Passed: All non-redirect posts have names!")
if (len(titlePaths) > 0):
raise Exception("CI Check #2 Not Passed: post:'{}' has a title. Titles no longer needed!\n".format('\n'.join([str(item) for item in titlePaths])))
print("CI Check #2 Passed: No posts have titles!")